KSDS
A VSAM file where every record has its own key, so a program can find one record directly.
Also written key-sequenced dataset
Why it matters. The account master is a KSDS. A program asks for account A0000002 and gets that record, with no search through the rest.
Syntax
DEFINE CLUSTER (NAME(entry) INDEXED KEYS(length offset) RECORDSIZE(avg max) ...) PRINT INDATASET(entry) CHARACTER COUNT(n)
- KEYS(len off)
- Length of the key and where it starts. Offset 0 is the first byte.
- Primary key
- Unique. Two records cannot share one.
- Alternate index
- A second way in, which can allow repeated values.
- CI and CA
- VSAM keeps records in control intervals inside control areas.
- Spare space
- Room left in each block so later inserts do not move records.
Try it PRINT
- 1
Ask the catalog about the account master, ZBANK.DATA.ACCTMAST.
LISTCAT ENTRIES('ZBANK.DATA.ACCTMAST') - 2
List the first 2 records of the file, as text.
PRINT INDATASET('ZBANK.DATA.ACCTMAST') CHARACTER COUNT(2)
Remember
- KSDS is key-sequenced: every record has a unique key.
- The index finds a record by its key.
- Records are held in key order.
The usual mistake
Adding a second record with the key A0000002
Every key in a KSDS must be unique. A duplicate is refused.
Give each record its own key, or change the record that already has that key.
On real z/OS
MF/OS models keyed reads, inserts and deletes for training, not VSAM storage. There are no control interval or control area splits, no spare space and no alternate indexes. Do not take performance or space ideas from it.
Where can I practise KSDS?
Right here, at ZedBank. You take a junior job at a simulated bank and use KSDS in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- VSAMA family of dataset types built for fast record access by key, used where applications need to look records up rather than read them in order.
- IDCAMSThe utility used to create, list, copy and delete datasets, and the standard tool for anything involving VSAM.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.
- File descriptionThe FD entry in a COBOL program that describes a file's records, connecting the program to data supplied by the JCL.
- Primary keyThe column or columns that uniquely identify each row in a table, so no two rows share the same value.