VSAM
A family of file types built to find one record fast, by key, without reading all the others.
Also written Virtual Storage Access Method
Why it matters. The bank looks up one account among millions all day. A VSAM file does that, where a plain file would have to be read from the start.
Syntax
DEFINE CLUSTER (NAME(entry) INDEXED|NONINDEXED|NUMBERED|LINEAR ...)
- KSDS
- Key-sequenced: each record has a key.
- ESDS
- Entry-sequenced: records in the order they arrive.
- RRDS
- Relative record: records are found by slot number.
- LDS
- Linear: a plain string of bytes, used by Db2.
- Catalog
- Every VSAM file must be in a catalog.
Try it LISTCAT
- 1
List the bank's data files, the ones whose name starts with ZBANK.DATA.
LISTCAT LEVEL(ZBANK.DATA) - 2
Now make a keyed file. You're in the SYSIN lines of job MKKEYED, under EXEC PGM=IDCAMS. Write the command that creates ZB0001.DEV.KEYED as a keyed VSAM file: a key of 8 characters from the start, records of 80, and 1 track to begin with. Type it on one line.
SYSIN DEFINE CLUSTER (NAME(ZB0001.DEV.KEYED) INDEXED KEYS(8 0) RECORDSIZE(80 80) TRACKS(1 1)) - 3
Submit the job MKKEYED from your DEV JCL library.
SUBMIT 'ZB0001.DEV.JCL(MKKEYED)' - 4
Read what IDCAMS printed, STEP1.SYSPRINT.
OUTPUT MKKEYED STEP1.SYSPRINT
Remember
- VSAM files are found by key or by position, not read from the start.
- The common kinds: KSDS (key), ESDS (arrival order), RRDS (slot number).
- IDCAMS makes and looks after them.
The usual mistake
Opening a VSAM file with BROWSE
BROWSE is for plain files and members. A VSAM file is a different kind of file.
PRINT INDATASET('ZBANK.DATA.ACCTMAST') CHARACTER COUNT(5)
On real z/OS
The cluster is defined with IDCAMS DEFINE CLUSTER, as on z/OS. ALLOCATE cannot make a keyed VSAM file with keys and sizes; on a storage-managed system, JCL or ALLOCATE can create one only through a data class or RECORG. MF/OS keeps the key length and record size, but not control interval or spare space details, and does not model linear files.
Where can I practise VSAM?
Right here, at ZedBank. You take a junior job at a simulated bank and use VSAM in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- KSDSThe most common VSAM dataset type, where every record has a unique key used to find it directly.
- IDCAMSThe utility used to create, list, copy and delete datasets, and the standard tool for anything involving VSAM.
- DatasetWhat a mainframe calls a file: a named collection of records with a defined structure, rather than a loose stream of bytes.
- DB2 for z/OSIBM's relational database on the mainframe, where a great deal of the world's banking and insurance data is stored.
- Sequential datasetThe simplest kind of dataset: records stored one after another and normally read from start to finish.