VSAMbeginner
VSAM KSDS: Key-Sequenced Data Sets
Understand the structure and use of KSDS, the most common VSAM organization, and how its index and data components work together.
A KSDS stores records in key order and can find any one of them directly by key. It is what sits under almost every online file on a mainframe.
A KSDS is a library that keeps books shelved in call-number order (the data component) alongside a card catalog (the index component) mapping each call number straight to its shelf location — you can browse the shelves start to finish, or walk directly to exactly the book you want without touching any other shelf.
Key Concepts
1
Two components, and both exist on disk.
index component maps a key to a location in the data component
data component the records themselves, in key order2
The index is a tree. Finding customer C0004521 in a file of ten million reads a handful of pages, not ten
million records.
C0004521
3
It supports both access patterns, from one open file.
direct jump straight to a key
sequential read in ascending key order
dynamic both, in the same program4
That combination is what makes it the default choice. A batch job reads the whole file in key order; an
online transaction fetches one record; they use the same file.
5
Free space is the parameter people get wrong. A KSDS keeps records in key order, so inserting a record
means putting it in its correct place — not at the end.
6
FREESPACE(20 10)
| |
| percent of each control area left free
percent of each control interval left free7
With free space available, an insert fits into the gap in the right control interval and costs almost
nothing.
8
Without it, you get a split. The control interval is full, so VSAM allocates a new one, moves half the
records into it, and updates the index.
9
before: [ A B C D E ] full
insert F
after: [ A B C ] [ D E F ] two CIs, index updated10
One split is cheap. A file loaded with no free space and then heavily inserted into splits constantly,
the records end up physically scattered despite being logically in key order, and sequential reading —
the thing key order was supposed to make fast — turns into random I/O.
11
A control area split is the same thing one level up, and is considerably more expensive.
12
Which is why a heavily inserted KSDS is periodically reorganised: unload it, redefine it, reload it in
key order with free space restored. That is the VSAM equivalent of a DB2 REORG, and it exists for the same
reason.
REORG
13
The trade against a flat file. The index costs storage, and every insert, update and delete must
maintain it. What it buys is finding one record among millions without reading them all — which a
sequential file cannot do at any size.
14
What the interviewer is probing.1. "What makes a KSDS different from the other VSAM types?" Probing: the fundamentals.
Stalls: "It has keys." Moves up: records are stored and retrievable by a unique key in sequence,
through an index component separate from the data component.
15
2. "What is a control interval split?" Probing: the mechanism. Stalls: "A problem." *Moves
up:* when an insert does not fit, VSAM splits the control interval, which costs time and leaves the
file physically disordered.
16
3. "How do you reduce splits?" Probing: the tuning. Stalls: "You cannot." Moves up: define
free space with the FREESPACE parameter so inserts fit, and REPRO or reorganise periodically.
17
4. "Can the key be changed on an existing record?" Probing: the detail. Stalls: "Yes."
Moves up: no — a key change is a delete and an insert, because the key determines placement.