Reading a VSAM file with a condition.

Virtual Storage Access method - ESDS, KSDS, RRDS & LDS. Basic direct access method, Basic sequential -, Queued sequential -, Basic partitioned -, Indexed sequential -, Object - access method.
Previous topicNext topic

Topic Author
Abhishek Awasthi
Registered Member
Posts: 14
Joined: Tue Aug 20, 2013 10:43 am

Reading a VSAM file with a condition.

Post by Abhishek Awasthi » Fri Feb 10, 2017 1:54 pm

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.




nicc
Global Moderator
Global Moderator
Posts: 597
Joined: Wed Apr 23, 2014 8:45 pm

Re: Reading a VSAM file with a condition.

Post by nicc » Fri Feb 10, 2017 4:05 pm

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.


Regards
Nic

User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1379
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

Re: Reading a VSAM file with a condition.

Post by Robert Sample » Fri Feb 10, 2017 6:24 pm

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'.



Previous topicNext topic

Return to “SMS & VSAM and BDAM, BSAM, QSAM, BPAM, ISAM, OAM.”