Problem reading a KSDS file from begining



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Problem reading a KSDS file from begining

Postby ashwin1990 » Mon Jun 18, 2012 2:41 pm

Hi All.

I am reading a KSDS file. Suppose i reach the 11th record while reading. Now if i am required to read the 1st record again, how do i do it. Because the nect read will read the 12th record.

I am reading the KSDS file in a loop.
ashwin1990
 
Posts: 32
Joined: Mon Feb 27, 2012 4:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem reading a KSDS file from begining

Postby Monitor » Mon Jun 18, 2012 2:53 pm

What did you find in the COBOL Language Reference manual?
I found
The START statement provides a means of positioning within an indexed or relative file for subsequent sequential record retrieval.
Monitor
 
Posts: 98
Joined: Wed Jan 18, 2012 8:59 pm
Has thanked: 0 time
Been thanked: 7 times

Re: Problem reading a KSDS file from begining

Postby Robert Sample » Mon Jun 18, 2012 4:48 pm

In your SELECT statement, what does the ACCESS clause say? In order to use the START command, the ACCESS must be DYNAMIC or RANDOM, not SEQUENTIAL. If your ACCESS is SEQUENTIAL, you must close the file, open the file again, then issue a READ command to retrieve the first reccord. And it is NEVER a good idea to write your code in such a way that you have to close and re-open files.

And after you've read the first record again, are you going to want to go back and read the 12th record next? In other words, your description of your processing need is woefully inadequate for a full solution.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Problem reading a KSDS file from begining

Postby ashwin1990 » Mon Jun 18, 2012 5:12 pm

Yes the access mode is sequential.................. i cant use random or dynamic mode, as i dont know the values of the key record........... so i have to use sequential access mode........ but at the same time, i am required to read records such that, i may be required to come back to previously read record...........
ashwin1990
 
Posts: 32
Joined: Mon Feb 27, 2012 4:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem reading a KSDS file from begining

Postby Robert Sample » Mon Jun 18, 2012 5:36 pm

Are you using CICS or batch? CICS supports the READPREV option for the READ statement, but you cannot read a sequential file backwards in batch COBOL -- PERIOD. Create a table and save the records as you read them, then you can refer to the appropriate record as needed.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Problem reading a KSDS file from begining

Postby Anuj Dhawan » Mon Jun 18, 2012 6:38 pm

I strongly feel that you should be telling us - -what you want to do instead of what you choose as a "solution". Why do you want to come back at firdt-record?
Anuj
Anuj Dhawan
 
Posts: 273
Joined: Mon Feb 25, 2008 3:53 am
Location: Mumbai, India
Has thanked: 6 times
Been thanked: 4 times

Re: Problem reading a KSDS file from begining

Postby dick scherrer » Mon Jun 18, 2012 8:04 pm

Hello,

A requirement to go back and read from the "front of the file" again is almost always a bad design.

If you explain the "requirement" someone may have alternative suggestions.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post