VSAM · 2026-10-11

VSAM KSDS Explained: Keys, Records, and IDCAMS Basics

Learn what a VSAM KSDS is, why it is used, and how mainframe programs access keyed records.

VSAM is a mainframe access method used to store and retrieve records. One of the most common VSAM file types is KSDS, or Key-Sequenced Data Set. A KSDS stores records in key sequence and allows direct access by key.

What is a KSDS?

A KSDS has two main parts:

The key is part of the record. For example, a customer file may use customer number as the key.

Why KSDS is useful

KSDS supports both sequential and random access. A program can read records in key order or directly read a specific record using a key.

Use cases:

IDCAMS define example

//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
  DEFINE CLUSTER(NAME(DBALA.CUSTOMER.KSDS) -
    INDEXED -
    KEYS(10 0) -
    RECORDSIZE(100 100) -
    TRACKS(5 5)) -
  DATA(NAME(DBALA.CUSTOMER.KSDS.DATA)) -
  INDEX(NAME(DBALA.CUSTOMER.KSDS.INDEX))
/*

KEYS(10 0) means the key length is 10 and starts at position 0.

COBOL access

A COBOL program may define the file as indexed:

SELECT CUSTOMER-FILE ASSIGN TO CUSTFILE
    ORGANIZATION IS INDEXED
    ACCESS MODE IS DYNAMIC
    RECORD KEY IS CUSTOMER-ID
    FILE STATUS IS WS-CUST-STATUS.

ACCESS MODE IS DYNAMIC allows both sequential and random access.

Common file status values

Conclusion

VSAM KSDS is a powerful structure for keyed access on the mainframe. Developers should understand keys, file status, and access modes to write reliable COBOL programs that use VSAM files.

← Back to all articles