Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
📄 VSAM

VSAM KSDS Operations

Intermediate 🕑 18 min read 👁 0 views

18

Code Example


## VSAM KSDS Operations

Key-Sequenced Data Sets support both sequential and random access.

### Characteristics
- Records stored in key sequence
- Primary key must be unique
- Supports alternate indexes
- Both sequential and direct access

### Access Modes
- **Sequential:** Read in key order
- **Random:** Direct key access
- **Dynamic:** Both in same program

### COBOL File Control
\`\`\`cobol
SELECT KSDS-FILE ASSIGN TO KSDSDD
    ORGANIZATION IS INDEXED
    ACCESS MODE IS DYNAMIC
    RECORD KEY IS KS-KEY
    FILE STATUS IS WS-STATUS.
\`\`\`

### File Operations
- OPEN (INPUT/OUTPUT/I-O/EXTEND)
- READ (sequential or by key)
- WRITE (add record)
- REWRITE (update record)
- DELETE (remove record)
- START (position for sequential)
- CLOSE

### Invalid Key Conditions
File status indicates success/failure.