Here’s a sample COBOL program that reads VSAM file randomly. The logic given here is helpful to use in your projects.
Storage of VSAM Files
- Entries will store in Master or User catalog
- Plainly, the Master and User-catalog both can have entries of VSAM and non-VSAM datasets.
- Only KSDS datasets have Indexed. The ESDS and RRDS have only the data components. That means they do not have an index.
- |Data component|Index component|
- While working with ESDS and RRDS you need not index.
- KSDS index is a combination of Key and Value. Also, KSDS supports an alternate index.
- Index key|Sequence value
- In KSDS, firstly, it locates the index, then finds corresponding sequence value. From this it gets data from control interval and area.
- The catalog that stores information of VSAM and non-VSAM datasets is called the ICF integrated catalog facility.
How to READ VSAM Files Randomly
SELECT TEST1 ASSIGN TO TEST1
ORGANIZATION IS INDEXED
ACCESS IS RANDOM
RECORD-KEY IS TS-EMPLOYEE-NUMBER
ALTERNATE RECORD KEY IS TS-SOCIAL-SECURITY-NO
ALTERNATE RECORD KEY IS TS-DEPT-NO