Page 1 of 1

Problem reading a KSDS file from begining

PostPosted: Mon Jun 18, 2012 2:41 pm
by ashwin1990
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.

Re: Problem reading a KSDS file from begining

PostPosted: Mon Jun 18, 2012 2:53 pm
by Monitor
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.

Re: Problem reading a KSDS file from begining

PostPosted: Mon Jun 18, 2012 4:48 pm
by Robert Sample
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.

Re: Problem reading a KSDS file from begining

PostPosted: Mon Jun 18, 2012 5:12 pm
by ashwin1990
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...........

Re: Problem reading a KSDS file from begining

PostPosted: Mon Jun 18, 2012 5:36 pm
by Robert Sample
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.

Re: Problem reading a KSDS file from begining

PostPosted: Mon Jun 18, 2012 6:38 pm
by Anuj Dhawan
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?

Re: Problem reading a KSDS file from begining

PostPosted: Mon Jun 18, 2012 8:04 pm
by dick scherrer
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.