Mainframe Path Start learning free
Core7 min readLesson 1 of 3

The four VSAM types

VSAM is a family of file organisations for data you need to reach quickly by key or position, rather than by reading from the start. Most of what you meet in practice is one of the four types below, and usually the first one.

The four organisations
KSDS
Key-sequencedReached by a unique keyHas an indexThe one you will meet
ESDS
Entry-sequencedReached by relative byte addressRecords only appendedLog-style data
RRDS
Relative recordReached by record numberFixed slotsRare in new work
LDS
LinearNo record structure at allA byte streamUsed by DB2 internally

Vocabulary you need before anything else

TermMeaning
ClusterThe whole VSAM object — what you name and refer to
Data componentWhere the records live
Index componentFor a KSDS: the structure that maps a key to a location
Control interval (CI)The unit VSAM reads and writes — like a block
Control area (CA)A group of control intervals
Free spaceRoom deliberately left empty inside CIs and CAs so inserts do not force a split
Alternate index (AIX)A second way to reach records, by a non-primary key
PathThe object a program opens to read through an alternate index

How a KSDS finds a record

Key lookup in a KSDS
Your keyACCT_ID = 0012345678
Index setNarrows to a control area
Sequence setNarrows to a control interval
Control intervalRecords scanned within it
RecordReturned

The index is a tree. The top levels — the index set — narrow the search to a control area; the bottom level — the sequence set — points at the exact control interval. This is why lookup cost barely grows as the file gets bigger, and why the key must be unique and fixed in position and length.

Choosing between VSAM and DB2

Use VSAM whenUse DB2 when
Access is always by one known keyYou need flexible queries and joins
The record layout is stable and owned by one applicationMany applications and tools need access
You need the lowest possible access costYou need SQL, reporting, and referential integrity
The application already uses itYou are designing something new

Common mistakes

Assuming VSAM is a database

It is a file organisation. There is no SQL, no query optimiser and no cross-file referential integrity.

Expecting to change the key

The primary key's position and length are fixed at define time. Changing it means defining a new cluster and reloading.

Reading a VSAM file sequentially in a hot online path

That is what browse commands are for, and they should be bounded. Unbounded browses online are a classic performance defect.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
IDCAMS: define, load, inspect →