Step-by-step: load and read a VSAM file

Defining a cluster proves you can talk to the catalog; loading proves you can move bits in the right order; reading proves the application world agrees with both. This page stitches those worlds together for a KSDS-shaped beginner path: verify with LISTCAT, load with sorted REPRO, open the dataset through JCL, and read from COBOL with explicit FILE STATUS handling. ESDS and RRDS variants are noted where they differ, but the spine matches what most training labs teach first because keyed files surface the richest lessons about ordering, positioning, and mistakes that look like “VSAM is broken” when the program never opened the right DSN.

Roadmap table

Seven-step load-and-read checklist
StepWhat to verify
1. Prove catalog healthLISTCAT the cluster; confirm SHAREOPTIONS, KEYS, and volumes match expectations.
2. Load or refresh dataSort keyed input ascending; REPRO into cluster; reconcile counts from SYSPRINT.
3. Author JCL DDDSN=cluster, DISP=SHR or OLD per concurrency; AMP only when tuning owners approve.
4. Compile program with matching FDRECORD CONTAINS / BLOCK CONTAINS align with VSAM RECORDSIZE; SELECT matches DD name.
5. OPEN and check FILE STATUSTreat non-00 statuses as hard stops until understood.
6. Position then READRandom: READ KEY; sequential: START optional then READ NEXT as pattern requires.
7. CLOSE and reportLog record counts and abnormal statuses for operations.

JCL that lets a program see the cluster

The DD name is the bridge between JCL and program. In COBOL, ASSIGN links the SELECT internal name to the DD name the binder expects. DISP=SHR allows shared read when policy permits; DISP=OLD signals exclusive use appropriate for some maintenance jobs. VSAM does not care about your program language—it honors allocation and sharing rules from the catalog and DD. Typos in DSN or DD omission produce FILE STATUS 35 at OPEN, not mysterious VSAM internals.

text
1
2
3
4
5
//READJOB EXEC PGM=COBTEST //STEPLIB DD DISP=SHR,DSN=DEPT.TRAIN.LOAD //CUSTMAS DD DISP=SHR,DSN=DEPT.TRAIN.CUST.KSDS //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=*

Minimal COBOL OPEN / READ skeleton

The sample uses fixed-area spacing so columns resemble traditional COBOL reference format: sequence area (1–6 blank), indicator (7 blank), Area A (8–11), Area B from column 12. Adjust names for your shop standards; compile with the same VSAM dataset definition you validated in LISTCAT.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
IDENTIFICATION DIVISION. PROGRAM-ID. COBTEST. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUST-FILE ASSIGN TO CUSTMAS ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-VSAM-STATUS. DATA DIVISION. FILE SECTION. FD CUST-FILE RECORD CONTAINS 80 CHARACTERS. 01 CUST-RECORD PIC X(80). WORKING-STORAGE SECTION. 01 WS-VSAM-STATUS PIC XX. PROCEDURE DIVISION. OPEN INPUT CUST-FILE IF WS-VSAM-STATUS NOT = '00' DISPLAY 'OPEN FAILED: ' WS-VSAM-STATUS STOP RUN END-IF READ CUST-FILE AT END DISPLAY 'NO FIRST RECORD' NOT AT END DISPLAY 'FIRST RECORD OK' END-READ CLOSE CUST-FILE STOP RUN.

ACCESS MODE changes the story

SEQUENTIAL

Walk records in key order after optional positioning. Good for reports that sweep the file. For large files, design commit or checkpoint logic so restarts do not reread from scratch unintentionally.

RANDOM

Supply a key before each READ KEY. Useful for transaction lookups. Requires that the key buffer layout matches KEYS offset/length from DEFINE or you will read the wrong record or get NOT FOUND statuses.

DYNAMIC

Mix sequential and random operations in one session per language rules. Beginners should master SEQUENTIAL and RANDOM separately before relying on DYNAMIC nuances.

ESDS and RRDS quick differences

  • ESDS: No primary key; sequential or RBA-style addressing. LOAD order is chronological; reads respect RBA arguments when used.
  • RRDS: Relative record slots; READ uses RRN. Loads must respect slot semantics documented for your application.

Verification discipline

After the read job, compare program-record counts to control totals when available. If counts diverge, suspect duplicate keys absorbed during REPLACE loads, wrong KEY positions in the FD, or filters in START/READ pairs. Keep SYSPRINT from REPRO and the language listing together in the ticket so reviewers can correlate times and names.

Practice exercises

  1. Run LISTCAT before and after a sandbox REPRO; diff high-used statistics if your site exposes them.
  2. Modify the sample to use ACCESS RANDOM and one READ KEY with a literal key; document FILE STATUS for success and not-found.
  3. Intentionally remove the // DD once in test to memorize the 35 pattern in your environment.
  4. Pair-read the COBOL READ page and annotate which verbs pair with START for browse loops.

Explain like I'm five

Loading is pouring cereal into the box. Reading is opening the flap and taking one spoon at a time. If you yell into the pantry but never open the right box, you cannot taste cereal—that is forgetting the DD name bridge. If you pour before the box exists, cereal hits the floor—that is skipping DEFINE. The grown-up step is checking the label on the box twice: LISTCAT is the label photo.

Test your knowledge

Test Your Knowledge

1. A KSDS load completed with RC=0 but the file is empty at OPEN. Which check comes first?

  • Reformat the LPAR
  • Verify REPRO actually targeted the same DSN you OPEN (LISTCAT names versus JCL DSN)
  • Increase CI size blindly
  • Delete SYS1.PARMLIB

2. FILE STATUS immediately after OPEN is 35. What class of problem is most likely?

  • Sort work space
  • Open-time failure such as missing DD, bad DSN, or authorization
  • End of file
  • Successful read

3. For sequential KSDS reads, which statement often precedes the first READ NEXT in keyed browse-style loops?

  • DELETE ADSPACE
  • START not always required depending on program pattern; many loops use START with KEY IS = low key or first READ KEY
  • CLEAR SCREEN
  • DISPLAY ST
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: IBM VSAM COBOL integration patterns (introductory)Sources: IBM Enterprise COBOL Programming Guide; VSAM Demystified (SG24-6105)Applies to: z/OS VSAM with Enterprise COBOL