View previous topic :: View next topic |
Author |
Message |
sivarao Beginner
Joined: 21 Aug 2008 Posts: 6 Topics: 1
|
Posted: Mon Aug 25, 2008 7:14 am Post subject: how to read the records from bottom to top |
|
|
Hi ,
I would like to read the records from bottom to top through COBOL logic.
Assu that the file KSDS.
Regards,
Siva |
|
Back to top |
|
 |
superk Advanced

Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
Posted: Mon Aug 25, 2008 1:39 pm Post subject: |
|
|
Can't be done with COBOL.
Take a look at using Assembler or File-Aid instead. |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Mon Aug 25, 2008 4:15 pm Post subject: |
|
|
I'm wondering why you would want to do this.
If you're processing every record, or most records, you could REPRO the KSDS to a flat file, sort it by the key in descending order, and code a COBOL pgm to process the resulting sorted file.
In theory, you could use a START KEY IS LESS THAN followed by a single READ. The key from each READ would then be used as the key in the next START KEY IS LESS THAN. I suspect the performance would be horrible. I would not recommend this option, but just mention it as a possibility. |
|
Back to top |
|
 |
sivarao Beginner
Joined: 21 Aug 2008 Posts: 6 Topics: 1
|
Posted: Mon Aug 25, 2008 11:51 pm Post subject: |
|
|
thanks for your suggestyions. |
|
Back to top |
|
 |
superk Advanced

Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
Posted: Tue Aug 26, 2008 6:23 am Post subject: |
|
|
jsharon1248 wrote: | I'm wondering why you would want to do this. |
I second this comment. sivarao, why would you want to do this? |
|
Back to top |
|
 |
tcurrier Intermediate
Joined: 10 Feb 2006 Posts: 188 Topics: 68
|
Posted: Tue Aug 26, 2008 8:04 pm Post subject: |
|
|
If you really need to do this, this should work :
In your SELECT statement, use 'ACCESS IS SEQUENTIAL' :
Code: | FILE-CONTROL.
SELECT VSAM-FILE ASSIGN TO VSAMFILE
ORGANIZATION IS INDEXED
RECORD KEY IS VSAM-KEY
ACCESS IS SEQUENTIAL
FILE STATUS IS VSAM-STATUS. |
In the PROCEDURE-DIVISION, code:
Code: | OPEN INPUT VSAM-FILE.
PERFORM UNTIL VSAM-STATUS > '00'
READ VSAM-FILE NEXT RECORD
DISPLAY 'NEXT RECORD: ' VSAM-RECORD
END-PERFORM.
CLOSE VSAM-FILE. |
|
|
Back to top |
|
 |
sivarao Beginner
Joined: 21 Aug 2008 Posts: 6 Topics: 1
|
Posted: Wed Aug 27, 2008 1:37 am Post subject: |
|
|
I just wanted to check whether we can do this logic in COBOL.
any way thanks for your suggestions and code. |
|
Back to top |
|
 |
|
|