Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Reading contents of a file from end in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
lucky.rohith
Currently Banned

New User


Joined: 06 Aug 2006
Posts: 10

PostPosted: Thu Aug 24, 2006 12:54 am    Post subject: Reading contents of a file from end in COBOL
Reply with quote

Hi,

IN C-language v can read contents of a file from the end using pointers.
Is ther any possibility of reading contents of a file from end in COBOL?
If its ther how v hav to do it?
Back to top
View user's profile Send private message

DavidatK

Active Member


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

PostPosted: Thu Aug 24, 2006 2:34 am    Post subject: Re: reading a file.
Reply with quote

I'm going to say No,

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

I believe it should be technically possible, but far outside acceptability. You would have 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 pointer to the last record and read it. This is NOT something to do using COBOL.

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

Dave
Back to top
View user's profile Send private message
cobolunni

Active User


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

PostPosted: Thu Aug 24, 2006 9:26 pm    Post subject:
Reply with quote

hello rohit

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

from the replays i found that there is no function in the vs cobol 2 to read file from bottom but there are options in some cobol compilers .

you can sort the file using some index field in the file using sort verb to the desending order and make the new file and then read the new file icon_smile.gif
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Fri Aug 25, 2006 11:29 am    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

Hi

You can read backwards.
for eg. If organization is Indexed, you can use the following method.

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

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

go to p1.


Regards

Aji Cherian
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Fri Aug 25, 2006 1:58 pm    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

Hi,
There is a mistake in my previous post. Please see the modified code below.


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

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

go to p1.


Regards

Aji Cherian
Back to top
View user's profile Send private message
cheetz007

New User


Joined: 10 Aug 2006
Posts: 23

PostPosted: Fri Aug 25, 2006 3:19 pm    Post subject:
Reply with quote

Or, put another way, unless the file is indexed, no you can't do it. The best way to do it if the file is not indexed is to use a sort to add a key to the file and then sort it in reverse order and then just read it normally.

Of course, if it's a small file, you can just read the lot into some kind of table and then process it that way, but this way leads to madness! First answer seems to be the most common practice.
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Fri Aug 25, 2006 10:11 pm    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

Aji,

Would you be so kind as to enlighten us as to where in the COBOL manual I can read about READ PREVIOUS?

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

Dave
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Aug 27, 2006 2:29 am    Post subject:
Reply with quote

Hi Aji,

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

I don't know this as a fact but I'm sure CICS uses assembler language to satisfy the request.
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

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

hi

There is a connection, for reading the previous record the correct syntax is

Read <file-name> previous record.


regards

Aji Cherian
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Mon Aug 28, 2006 1:34 pm    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

Hi

There is a mistake in my code once again. Sorry. Please go through the code below.

intialize key-1.
move high-values to key-1
start file1 key > key-1.

p1.
read <file1> previous record.
if file-status = 46
perform close-files
stop run.

go to p1.


Regards

Aji Cherian
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Tue Aug 29, 2006 3:55 am    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

Aji Cherian, you are one hard person to convince that there is no ?READ PREVIOUS? in COBOL. Even the COBOL manual was given to you as a link, but you persist. As Jack said, CICS does have some syntax to support ?READ PREVIOUS? that looks like COBOL, but It?s not, it?s a CICS command. Or maybe you are using a NON-IBM compiler that does support it, but this is an IBM VS COBOL II forum, and IBM VS COBOL II, or any other IBM COBOL does NOT support ?READ PREVIOUS?. Please read the manual.

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

Quote:

There is a mistake in my code once again


Dave
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Tue Aug 29, 2006 3:15 pm    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

Please check the following page,
http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/IGY3LR00/INDEX?SHELF=igy3sh01&DT=20011206182158

Check the following link,

PREVIOUS RECORD phrase, READ statement, 6.2.28

here also it is not described about previous record, but that phase exists.

regards

Aji Cherian
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Wed Aug 30, 2006 2:00 am    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

Well Aji,

I gave you the benifit of the doubt and thought that there might be undocumented options, so I compiled a small program.

Code:

PP 5655-G53 IBM ENTERPRISE COBOL FOR Z/OS AND OS/390 3.1.0     TEST01    DATE 08
  LINEID  PL SL  ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6---
  000001         000100 IDENTIFICATION DIVISION.                               
  000002         000200 PROGRAM-ID.    TEST01.                                 
  000003         000300 AUTHOR.        DAVIDATK.                               
  000004         000400 INSTALLATION.                                           
  000005         000500 DATE-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 SECTION.                                   
  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          ACCESS 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  TEST-FLAT-REC              PIC X(80).             
  000030         002310                                                       
  000031         002311 FD  TEST-INDX                                         
  000032         002312     LABEL RECORDS ARE STANDARD.                       
  000033         002313 01  TEXT-INDX-REC.                                   
  000034         002314     05  KEY-1                  PIC X(10).             
  000035         002315     05  FILLER                 PIC X(70).             
  000036         002316 
  000037         002320                                                         
  000038         005800 WORKING-STORAGE SECTION.                               
  000039**       002940                                                         
  000040**       002405                                                         
  000041**       002402 LINKAGE SECTION.                                       
  000042         002430                                                         
  000043         004020 PROCEDURE DIVISION.                                     
  000044**       002600                                                         
  000045         004111 PROGRAM-START.                                         
  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-S "PREVIOUS" WAS INVALID.  SKIPPED TO THE NEXT VERB, PERIOD OR
                        PROCEDURE-NAME DEFINITION.                             
PP 5655-G53 IBM ENTERPRISE COBOL FOR Z/OS AND OS/390 3.1.0     TEST01    DATE 08
  LINEID  PL SL  ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6---
                                                                               
  000055**       004120                                                         
  000056         004122     CLOSE TEST-FLAT.                                   
  000057**       004120                                                         
  000058         004131     INITIALIZE KEY-1.                                   
  000059         004132     MOVE HIGH-VALUES TO KEY-1.                         
  000060         004133     START TEST-INDX KEY > KEY-1.                       
  000061         004134                                                         
  000062         004135     READ TEST-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
                        PROCEDURE-NAME DEFINITION.                             
                                                                               
  000065         004138                                                         
  000066         004140     GOBACK.                                             
  000067         004300


Dave
Back to top
View user's profile Send private message
raghunathns

Active User


Joined: 08 Dec 2005
Posts: 127
Location: rochester

PostPosted: Wed Aug 30, 2006 2:33 am    Post subject: Possibility of reading contents of a file from end in
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 top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Wed Aug 30, 2006 2:57 am    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

raghunathns,

If you look at the example given above, you will find that there is a 'Flat' file and an 'INDEXED' file given.

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

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

Not by the proof that Aji gave for 'READ <file> PREVIOUS' being valid by showing my where it is not in the manual.

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

Dave icon_smile.gif
Back to top
View user's profile Send private message
raghunathns

Active User


Joined: 08 Dec 2005
Posts: 127
Location: rochester

PostPosted: Wed Aug 30, 2006 8:45 pm    Post subject: ibm manual
Reply with quote

http://publibfp.boulder.ibm.com/epubs/pdf/igyvr002.pdf

check this.

procedure division, read statement.
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Thu Aug 31, 2006 4:57 am    Post subject: Re: Possibility of reading contents of a file from end in CO
Reply with quote

raghunathns,

I'll give you partial credit for your post as I over-generalized when I spoke of IBM COBOL. You showed me where ?READ PREVIOUS RECORD? is a valid IBM Extension in the COBOL/VSE manual. icon_surprised.gif But, it is not valid in VS COBOL II, Enterprise COBOL, and this is not a COBOL/VSE forum.

You did a good job in pointing this out, I?ll reply to this type of post more accurately next time. icon_smile.gif

Dave
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Export flat file data into excel sheet murali.andaluri DFSORT/ICETOOL 2 Mon Mar 20, 2017 5:39 pm
No new posts Formatting VB File Learncoholic DFSORT/ICETOOL 3 Mon Mar 20, 2017 12:29 pm
No new posts Problem reading GTF trace output danik56 ABENDS & Debugging 7 Thu Mar 16, 2017 1:02 pm
No new posts Updating a VSAM file with DISP=OLD sheersh JCL & VSAM 8 Tue Mar 14, 2017 6:14 pm
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us