VSAM files

The physical organization of VSAM data sets differs considerably from the organizations used by other access methods.

VSAM data sets are held in control intervals (CI) and control areas (CA). The size of the CI and CA is normally determined by the access method; and the way in which they are used is not visible to you.

You can use three types of file organization with VSAM:

VSAM sequential file organization
(Also referred to as VSAM ESDS (entry-sequenced data set) organization.) In VSAM sequential file organization, the records are stored in the order in which they were entered.

VSAM entry-sequenced data sets are equivalent to QSAM sequential files. The order of the records is fixed.

VSAM indexed file organization
(Also referred to as VSAM KSDS (key-sequenced data set) organization.) In a VSAM indexed file (KSDS), the records are ordered according to the collating sequence of an embedded prime key field, which you define. The prime key consists of one or more consecutive characters in the records. The prime key uniquely identifies the record and determines the sequence in which it is accessed with respect to other records. A prime key for a record might be, for example, an employee number or an invoice number.
VSAM relative file organization
(Also referred to as VSAM fixed-length or variable-length RRDS (relative-record data set) organization.) A VSAM relative-record data set (RRDS) contains records ordered by their relative key. The relative key is the relative record number, which represents the location of the record relative to where the file begins. The relative record number identifies the fixed- or variable-length record.

In a VSAM fixed-length RRDS, records are placed in a series of fixed-length slots in storage. Each slot is associated with a relative record number. For example, in a fixed-length RRDS that contains 10 slots, the first slot has a relative record number of 1, and the tenth slot has a relative record number of 10.

In a VSAM variable-length RRDS, the records are ordered according to their relative record number. Records are stored and retrieved according to the relative record number that you set.

Throughout this information, the term VSAM relative-record data set (or RRDS) is used to mean both relative-record data sets with fixed-length records and with variable-length records, unless they need to be differentiated.

The following table compares the characteristics of the different types of VSAM data sets.

Table 1. Comparison of VSAM data-set types
Characteristic Entry-sequenced data set (ESDS) Key-sequenced data set (KSDS) Relative-record data set (RRDS)
Order of records Order in which they are written Collating sequence by key field Order of relative record number
Access Sequential By key through an index By relative record number, which is handled like a key
Alternate indexes Can have one or more alternate indexes, although not supported in COBOL Can have one or more alternate indexes Cannot have alternate indexes
Relative byte address (RBA) and relative record number (RRN) of a record RBA cannot change. RBA can change. RRN cannot change.
Space for adding records Uses space at the end of the data set Uses distributed free space for inserting records and changing their lengths in place For fixed-length RRDS, uses empty slots in the data set

For variable-length RRDS, uses distributed free space and changes the lengths of added records in place

Space from deleting records You cannot delete a record, but you can reuse its space for a record of the same length. Space from a deleted or shortened record is automatically reclaimed in a control interval. Space from a deleted record can be reused.
Spanned records Can have spanned records Can have spanned records Cannot have spanned records
Reuse as work file Can be reused unless it has an alternate index, is associated with key ranges, or exceeds 123 extents per volume Can be reused unless it has an alternate index, is associated with key ranges, or exceeds 123 extents per volume Can be reused