VSAM organization

There are three types of VSAM data sets. Each type roughly corresponds to a PL/I data set organization. All three types of VSAM data sets are ordered, and they can all have keys associated with their records. Both sequential and keyed access are possible with all three types.

Table 1. Types of VSAM data sets and corresponding PL/I data set organization
VSAM data set type Corresponding PL/I data set organization
Key-sequenced data sets (KSDS) Indexed data set
Entry-sequenced data sets (ESDS) Consecutive data set
Relative record data sets (RRDS) Regional data set

Although only key-sequenced data sets have keys as part of their logical records, keyed access is also possible for entry-sequenced data sets (using relative-byte addresses) and relative record data sets (using relative record numbers).

All VSAM data sets are held on direct access storage devices, and a virtual storage operating system is required to use them.

The physical organization of VSAM data sets differs from those used by other access methods. VSAM does not use the concept of blocking, and, except for relative record data sets, records need not be of a fixed length. In data sets with VSAM organization, the data items are arranged in control intervals, which are in turn arranged in control areas. For processing purposes, the data items within a control interval are arranged in logical records. A control interval can contain one or more logical records, and a logical record can span two or more control intervals. Concern about blocking factors and record length is largely removed by VSAM, although records cannot exceed the maximum specified size. VSAM allows access to the control intervals, but this type of access is not supported by PL/I.

VSAM data sets can have two types of indexes—prime and alternate. A prime index is the index to a KSDS that is established when you define a data set; it always exists and can be the only index for a KSDS. You can have one or more alternate indexes on a KSDS or an ESDS. Defining an alternate index for an ESDS enables you to treat the ESDS, in general, as a KSDS. An alternate index on a KSDS enables a field in the logical record different from that in the prime index to be used as the key field. Alternate indexes can be either nonunique, in which duplicate keys are allowed, or unique, in which they are not. The prime index can never have duplicate keys.

Any change in a data set that has alternate indexes must be reflected in all the indexes if they are to remain useful. This activity is known as index upgrade, and is done by VSAM for any index in the index upgrade set of the data set. (For a KSDS, the prime index is always a member of the index upgrade set.) However, you must avoid making changes in the data set that would cause duplicate keys in the prime index or in a unique alternate index.

Before using a VSAM data set for the first time, you need to define it to the system with the DEFINE command of Access Method Services, which you can use to completely define the type, structure, and required space of the data set. This command also defines the data set's indexes (together with their key lengths and locations) and the index upgrade set if the data set is a KSDS or has one or more alternate indexes. A VSAM data set is thus created by Access Method Services.

The operation of writing the initial data into a newly created VSAM data set is referred to as loading in this publication.

Use the three different types of data sets according to the following purposes:
  • Use entry-sequenced data sets for data that you primarily access in the order in which it was created (or the reverse order).
  • Use key-sequenced data sets when you normally access records through keys within the records (for example, a stock-control file where the part number is used to access a record).
  • Use relative record data sets for data in which each item has a particular number, and you normally access the relevant record by that number (for example, a telephone system with a record associated with each number).

You can access records in all types of VSAM data sets either directly by a key, or sequentially (backward or forward). You can also use a combination of the two ways: Select a starting point with a key and then read forward or backward from that point.

You can create alternate indexes for key-sequenced and entry-sequenced data sets. You can then access your data in many sequences or by one of many keys. For example, you could take a data set held or indexed in order of employee number and index it by name in an alternate index. Then you could access it in alphabetic order, in reverse alphabetic order, or directly by using the name as a key. You could also access it in the same kind of combinations by employee number.

Table 2 shows how the same data could be held in the three different types of VSAM data sets and illustrates their respective advantages and disadvantages.

Table 2. Types and advantages of VSAM data sets
Data set type Method of loading Method of reading Method of updating Pros and cons
Key-Sequenced Sequentially in order or prime index which must be unique KEYED by specifying key of record in prime index

SEQUENTIAL backward or forward in order of any index

Positioning by key followed by sequential reading either backward or forward

KEYED specifying a unique key in any index

SEQUENTIAL following positioning by unique key

Record deletion allowed

Record insertion allowed

Advantages: Complete access and updating

Disadvantages: Records must be in order of prime index before loading

Uses: For uses where access will be related to key

Entry-Sequenced Sequentially (forward only)

The RBA of each record can be obtained and used as a key

SEQUENTIAL backward or forward

KEYED using RBA

Positioning by key followed by sequential either backward or forward

New records at end only

Existing records cannot have length changed

Record deletion not allowed

Advantages: Simple fast creation

No requirement for a unique index

Disadvantages: Limited updating facilities

Uses: For uses where data will primarily be accessed sequentially

Relative Record Sequentially starting from slot 1

KEYED specifying number of slot

Positioning by key followed by sequential writes

KEYED specifying numbers as key

Sequential forward or backward omitting empty records

Sequentially starting at a specified slot and continuing with next slot

Keyed specifying numbers as key

Record deletion allowed

Record insertion into empty slots allowed

Advantages: Speedy access to record by number

Disadvantages: Structure tied to numbering sequences

Fixed length records

Uses: For use where records will be accessed by number