How to Read Records in Reverse Order in Cobol

View previous topic :: View next topic Author Message lucky.rohith
Currently Banned

New User

Joined: 06 Aug 2006
Posts: 10


Post Posted: Thu Aug 24, 2006 12:54 am
Reply with quote

Hello,

IN C-language five tin can read contents of a file from the end using pointers.
Is ther any possibility of reading contents of a file from cease in COBOL?
If its ther how v hav to do it?

Dorsum to top DavidatK

Agile Fellow member

Joined: 22 November 2005
Posts: 700
Location: Troy, Michigan USA


Post Posted: Thu Aug 24, 2006 ii:34 am
Reply with quote

I'm going to say No,

Reading a file from the back to the front end in COBOL cannot be done within the normal confines of the COBOL language.

I believe it should be technically possible, but far exterior acceptability. You would accept to have an in-depth knowledge of the Operating System Control Blocks, and run these using pointers. Then you should be able to set the current record arrow to the last tape and read it. This is NOT something to practice using COBOL.

Another way would be to call an assembler subroutine to do the read for you. But, then information technology?s not COBOL, is it.

Dave

Back to top cobolunni

Active User

Joined: 07 Aug 2006
Posts: 127
Location: kerala,india


Post Posted: Thu Aug 24, 2006 ix:26 pm
Reply with quote

hello rohit

This question is asked by me early in the forum merely not much erstwhile entry check out for the replay's

from the replays i institute that there is no office in the vs cobol 2 to read file from bottom merely there are options in some cobol compilers .

yous can sort the file using some alphabetize field in the file using sort verb to the desending order and make the new file and so read the new file icon_smile.gif

Dorsum to top Aji

New User

Joined: 03 Feb 2006
Posts: 53
Location: Mumbai


Post Posted: Fri Aug 25, 2006 11:29 am
Reply with quote

Hello

You lot can read backwards.
for eg. If system is Indexed, you can apply the post-obit method.

intialize central-one.
get-go file1 key > key-1.

p1.
read previous record.
if file-status = x
perform close-files
stop run.

go to p1.

Regards

Aji Cherian

Back to height Aji

New User

Joined: 03 Feb 2006
Posts: 53
Location: Mumbai


Post Posted: Friday Aug 25, 2006 i:58 pm
Reply with quote

How-do-you-do,
There is a fault in my previous post. Please encounter the modified lawmaking below.

intialize key-1.
start file1 cardinal > fundamental-1.

p1.
read previous record.
if file-status = 46
perform close-files
cease run.

go to p1.

Regards

Aji Cherian

Dorsum to acme cheetz007

New User

Joined: ten Aug 2006
Posts: 23


Post Posted: Fri Aug 25, 2006 3:xix pm
Reply with quote

Or, put another manner, unless the file is indexed, no you can't exercise information technology. The all-time way to do information technology if the file is not indexed is to use a sort to add a key to the file and then sort it in reverse gild and then merely read it normally.

Of form, if it's a small file, you can just read the lot into some kind of table then process information technology that fashion, just this way leads to madness! Showtime reply seems to exist the most common practice.

Back to top DavidatK

Agile Member

Joined: 22 November 2005
Posts: 700
Location: Troy, Michigan Us


Post Posted: Fri Aug 25, 2006 10:11 pm
Reply with quote

Aji,

Would you lot be so kind as to enlighten u.s.a. as to where in the COBOL transmission I can read about READ PREVIOUS?

I take included a link to the COBOL MANUAL for y'all convenience.

Dave

Dorsum to acme mmwife

Super Moderator

Joined: 30 May 2003
Posts: 1592


Post Posted: Dominicus Aug 27, 2006 ii:29 am
Reply with quote

Hi Aji,

The READ PREV is a function of IBM's CICS. While information technology appears that information technology'southward a COBOL office in that it uses COBOL-like syntax the function is only supported when using CICS.

I don't know this as a fact just I'm sure CICS uses assembler language to satisfy the asking.

Back to top Aji

New User

Joined: 03 February 2006
Posts: 53
Location: Mumbai


Post Posted: Mon Aug 28, 2006 10:36 am
Reply with quote

hi

In that location is a connection, for reading the previous record the correct syntax is

Read <file-name> previous tape.

regards

Aji Cherian

Back to top Aji

New User

Joined: 03 February 2006
Posts: 53
Location: Bombay


Post Posted: Mon Aug 28, 2006 1:34 pm
Reply with quote

Hi

There is a mistake in my lawmaking one time once again. Sorry. Delight go through the code beneath.

intialize central-1.
move high-values to key-one
start file1 primal > fundamental-one.

p1.
read <file1> previous tape.
if file-condition = 46
perform shut-files
terminate run.

become to p1.

Regards

Aji Cherian

Back to top DavidatK

Active Member

Joined: 22 November 2005
Posts: 700
Location: Troy, Michigan USA


Post Posted: Tue Aug 29, 2006 iii:55 am
Reply with quote

Aji Cherian, yous are 1 hard person to convince that there is no ?READ PREVIOUS? in COBOL. Even the COBOL transmission was given to you as a link, merely you persist. Equally Jack said, CICS does have some syntax to support ?READ PREVIOUS? that looks like COBOL, but It?due south not, it?south a CICS command. Or perhaps you are using a NON-IBM compiler that does support it, only this is an IBM VS COBOL II forum, and IBM VS COBOL 2, or whatsoever other IBM COBOL does Non support ?READ PREVIOUS?. Delight read the manual.

However, there is one statement you made in your last post that I fully back up.

Quote:

At that place is a mistake in my code one time again

Dave

Back to top Aji

New User

Joined: 03 February 2006
Posts: 53
Location: Mumbai


Back to height DavidatK

Agile Member

Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan United states of america


Post Posted: Wed Aug 30, 2006 2:00 am
Reply with quote

Well Aji,

I gave you lot the benifit of the doubt and idea that at that place might be undocumented options, so I compiled a pocket-size program.

Code:

PP 5655-G53 IBM ENTERPRISE COBOL FOR Z/OS AND Bone/390 3.one.0     TEST01    Engagement 08
LINEID  PL SL  ----+-*A-one-B--+----2----+----3----+----4----+----5----+----6---
000001         000100 IDENTIFICATION Partitioning.
000002         000200 Programme-ID.    TEST01.
000003         000300 Author.        DAVIDATK.
000004         000400 INSTALLATION.
000005         000500 Engagement-WRITTEN.  MAY 2006.
000006**       000500 DATE-COMPILED. 08/29/06.
000007         000700
000008         001200*********************************************************
000009         003100 ENVIRONMENT DIVISION.
000010**       001400 CONFIGURATION Section.
000011         001500 SOURCE-COMPUTER.   IBM-3090.
000012         001600 OBJECT-COMPUTER.   IBM-3090.
000013         003200 INPUT-OUTPUT Department.
000014         003300 FILE-CONTROL.
000015**       002000
000016         002001      SELECT TEST-FLAT  ASSIGN TO TESTFLAT.
000017         002010
000018         002011      SELECT TEST-INDX  ASSIGN TO TESTINDX
000019         002013          ORGANIZATION IS INDEXED
000020         002014          Admission IS DYNAMIC
000021         002016          RECORD Key IS KEY-1.
000022**       002010
000023         004300 Data DIVISION.
000024         004400 FILE SECTION.
000025**       002300
000026         002301 FD  TEST-Flat
000027         002302     LABEL RECORDS ARE STANDARD
000028         002303     BLOCK CONTAINS 0 RECORDS.
000029         002304 01  Examination-Apartment-REC              Picture show X(80).
000030         002310
000031         002311 FD  TEST-INDX
000032         002312     LABEL RECORDS ARE STANDARD.
000033         002313 01  TEXT-INDX-REC.
000034         002314     05  Primal-1                  PIC X(10).
000035         002315     05  FILLER                 Flick X(seventy).
000036         002316
000037         002320
000038         005800 WORKING-STORAGE SECTION.
000039**       002940
000040**       002405
000041**       002402 LINKAGE SECTION.
000042         002430
000043         004020 Process Sectionalization.
000044**       002600
000045         004111 Programme-Outset.
000046         004124
000047**       004113     Open INPUT TEST-Flat
000048         004114                TEST-INDX.
000049         004178
000050**       004116     READ TEST-Flat.
000051         004134
000052**       004118     READ Test-Flat Next.
000053**       004118
000054         004120     READ TEST-FLAT PREVIOUS.

==000054==> IGYPS2072-South "PREVIOUS" WAS INVALID.  SKIPPED TO THE NEXT VERB, Catamenia OR
PROCEDURE-NAME DEFINITION.
PP 5655-G53 IBM ENTERPRISE COBOL FOR Z/Os AND Bone/390 3.1.0     TEST01    DATE 08
LINEID  PL SL  ----+-*A-1-B--+----two----+----three----+----4----+----5----+----6---

  000055**       004120
000056         004122     Shut TEST-Apartment.
000057**       004120
000058         004131     INITIALIZE KEY-1.
000059         004132     Motility High-VALUES TO KEY-ane.
000060         004133     START TEST-INDX KEY > Fundamental-1.
000061         004134
000062         004135     READ Exam-INDX NEXT RECORD.
000063         004136
000064         004137     READ TEST-INDX PREVIOUS RECORD.

==000064==> IGYPS2072-S "PREVIOUS" WAS INVALID.  SKIPPED TO THE NEXT VERB, PERIOD OR
Process-Name DEFINITION.

  000065         004138
000066         004140     GOBACK.
000067         004300

Dave

Dorsum to top raghunathns

Active User

Joined: 08 Dec 2005
Posts: 127
Location: rochester


Post Posted: Wed Aug 30, 2006 ii:33 am
Reply with quote

in cobol we can read previous

the file should be an indexed file (i.e ksds-vsam)

normal sequential file we cant.

Back to elevation DavidatK

Active Fellow member

Joined: 22 November 2005
Posts: 700
Location: Troy, Michigan USA


Post Posted: Wed Aug 30, 2006 2:57 am
Reply with quote

raghunathns,

If you await at the example given above, you volition detect that there is a 'Apartment' file and an 'INDEXED' file given.

The compiler seems to not similar the READ <file> PREVIOUS for either of them.

I submit the same request to yous as to Aji, show me in the IBM COBOL Manual where the 'READ <file> PREVIOUS RECORD' can be plant.

Not by the proof that Aji gave for 'READ <file> PREVIOUS' existence valid by showing my where information technology is non in the manual.

I have included a link to the COBOL MANUAL for you convenience also..

Dave icon_smile.gif

Back to top raghunathns

Active User

Joined: 08 Dec 2005
Posts: 127
Location: rochester


Back to acme DavidatK

Agile Member

Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan United states


Post Posted: Thu Aug 31, 2006 4:57 am
Reply with quote

raghunathns,

I'll requite you fractional credit for your post as I over-generalized when I spoke of IBM COBOL. You showed me where ?READ PREVIOUS Tape? is a valid IBM Extension in the COBOL/VSE manual. icon_surprised.gif Just, information technology is not valid in VS COBOL 2, Enterprise COBOL, and this is not a COBOL/VSE forum.

You did a good chore in pointing this out, I?ll respond to this type of post more accurately next fourth dimension. icon_smile.gif

Dave

Dorsum to superlative

simpsonstiong75.blogspot.com

Source: https://ibmmainframes.com/about13283.html

0 Response to "How to Read Records in Reverse Order in Cobol"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel