How to read VSAM backward



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

How to read VSAM backward

Postby PauloCaze » Wed Jul 23, 2008 1:22 am

Hi list,

I want to read a VSAM KSDS file backward from some key. Is it possible?

Thanks in advance.
PauloCaze
 
Posts: 2
Joined: Wed Jul 23, 2008 1:16 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to read VSAM backward

Postby dick scherrer » Wed Jul 23, 2008 2:54 am

Hello,

There may not be a simple COBOL answer for your requirement.

This was found in another forum:
I need to read a VSAM/KSDS file backwards. We do this all the time with Assembler I/O modules, but we can't find a READ PREVIOUS verb in the Cobol language that the compiler will accept.

Is is possible to read a VSAM/KSDS file backwards in Cobol?

and the response was:
The READ file-name PREVIOUS is NOT in the current version of COBOL unless you are using a 2002 compatible COBOL, like Microfocus NET EXPRESS 4.0 or later. Even IBM's newest Enterprise COBOL 3.4 does not do this yet. (I have the manual.)
It is supported in CICS via a browse with GET PREVIOUS.

If you don't have to read a lot of data, such as just 1 or 2 records prior to some other record you can write an almost there routine: (You really need to understand your data and key relationships)

READ file-name
Decrement some right most key value by some value
and then:
Start FILE-NAME key is record-key
read next file-name
(you need to keep track of the results and check for when you have the record you started with, etc.)
Kluggy at best.
Otherwise, if you need a lot of this, create an alternate key value in binary-inverted sequence and do a read next on the binary-inverted key value.


If you or someone in your group knows assembler, that may be a way to go. Adding an inverted key would work, but may not be desirable - you will need to determine a "good" solution for your environment.

Good luck and let us know how you meet the requirement :)
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

Re: How to read VSAM backward

Postby MrSpock » Wed Jul 23, 2008 2:55 am

PauloCaze wrote:Is it possible?


No, it is not. And it's not for QSAM datasets either. You can use the File-Aid product (from Compuware) to do this, and an Assembler program can handle this. It's not possible in COBOL or most other languages.
User avatar
MrSpock
Global moderator
 
Posts: 807
Joined: Wed Jun 06, 2007 9:37 pm
Location: Raleigh NC USA
Has thanked: 0 time
Been thanked: 4 times

Re: How to read VSAM backward

Postby PauloCaze » Wed Jul 23, 2008 10:30 pm

Thanks to all replies!
Now I'm convinced that I must do an Assembler routine in order to archieve this issue.
PauloCaze
 
Posts: 2
Joined: Wed Jul 23, 2008 1:16 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to read VSAM backward

Postby dick scherrer » Thu Jul 24, 2008 4:06 am

You're welcome :)

Now I'm convinced that I must do an Assembler routine in order to archieve this issue.
You will probably want to get official permission to write assembler code that will ever be used for production. Many organizations no longer permit assembler code because they are not staffed to support assembler.

Given that cobol cannot do this and also given that there are a few million bits of cobol code that process vsam data, there is probably some other way to meet your requirement. . .
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