Page 1 of 1

Read vsam using the alternate index

PostPosted: Fri Mar 01, 2013 5:18 am
by macnano
I need to read a vsam file with alternate index. Both the base file and alternate index file have DDs in the JCL.
1. do I need a select statement for the alternate aix file or just the base file and indicate the alternate key?
2. If I need to have a select statement for the alternate aix file, should the START statement on the alternate aix > alternate key?
3. If #1 is no, should the START statement on the base file where key > alternate key which is defined in the select statement?
4. Should the READ NEXT be the base file or the alternate aix file?

Thank you.

Re: Read vsam using the alternate index

PostPosted: Fri Mar 01, 2013 6:31 am
by Robert Sample
You have the base VSAM file for one DD statement, and the PATH (not the alternate index) specified for the second DD statement, right?

SELECT VSAM-FILE ASSIGN TO DDA
    ORGANIZATION INDEXED
    ACCESS RANDOM
    RECORD KEY IS VF-KEY
    ALTERNATE RECORD KEY IS VF-ALT-KEY
    FILE STATUS IS VF-STAT
followed by
READ VSAM-FILE
    KEY IS VF-ALT-KEY
or
READ VSAM-FILE
    KEY IS VF-KEY
and
READ VSAM-FILE NEXT
VF-KEY and VF-ALT-KEY must be defined in an 01 under the FD; there are some other restrictions which you can read in the COBOL Language Reference manual (link at the top of the page).