Page 1 of 1

Reading a VSAM file with a condition.

Posted: Fri Feb 10, 2017 1:54 pm
by Abhishek Awasthi
Hi,

I have a VSAM with following key structure with key length of 110:

Code: Select all

01 VSAM-KEY-REC. 
05 VSAM-KEY-DATA PIC X(109). 
05 VSAM-KEY-FLAG PIC X(01). 
For my requirement, I need to read only those records which has VSAM-KEY-FLAG set to 'N'.

This is in my program:

Code: Select all

MOVE LOW-VALUES TO VSAM-KEY-DATA. 
MOVE 'N' TO VSAM-KEY-FLAG. 
*
READ VSAM-FILE 
KEY IS VSAM-KEY-REC 
END-READ. 
But it ends 23 VSAM status. I don't know the remaining keys of vsam i know only the last byte that is 'N'. Please help to resolve this one.

Thanks.

Re: Reading a VSAM file with a condition.

Posted: Fri Feb 10, 2017 4:05 pm
by nicc
You cannot! Generic keys must be at the start of the key. You probably can do what you want by using your sort product. Produce a sequential data set as the output and feed that into your program - assuming your program is going to do more than extract those records.

Re: Reading a VSAM file with a condition.

Posted: Fri Feb 10, 2017 6:24 pm
by Robert Sample
Depending upon the exact task you're trying to do (and other factors, as always), you've got about 3 options:
1. As Nic suggested, use your sort product and put the records with 'N' into a sequential data set
2. Create an alternate index (with duplicates) on the last byte of the key, then use the alternate index in your program. This will work as long as you have no more than 32,767 records with an 'N' as the last byte of the key -- if there are more, this is NOT an option.
3. Sequentially read every record from first to last in your program, and work with the records that have the 'N'.