The SELECT clause introduces a logical file name your PROCEDURE DIVISION uses in OPEN, READ, and CLOSE. The ASSIGN portion tells the compiler which external name participates in dataset allocation at run time. For VSAM batch on z/OS, that external name almost always matches a DD statement in the executing job or procedure step, while the DSN on that DD points at the cataloged cluster or path. This page explains how to read legacy SELECT lines without fear, how alternate RECORD KEY clauses extend the pattern for alternate index processing, and where OPTIONAL belongs in the story. It also warns about the most common classroom bug: a perfect program with a misspelled DD name never reaches OPEN successfully.
The listing below uses reference-format spacing so Area A starts in column 8 for division headers and Area B starts at column 12 for statements, matching classic mainframe coding rules where column 7 holds only the optional indicator and columns 1 through 6 hold sequence numbers (left blank here).
1234567891011121314151617181920000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. ORDREAD. 000300 ENVIRONMENT DIVISION. 000400 INPUT-OUTPUT SECTION. 000500 FILE-CONTROL. 000600 SELECT ORDERS-FILE 000700 ASSIGN TO ORDRCB 000800 ORGANIZATION IS INDEXED 000900 ACCESS MODE IS DYNAMIC 001000 RECORD KEY IS ORD-PRIMARY-KEY 001100 FILE STATUS IS ORD-STATUS. 001200 DATA DIVISION. 001300 FILE SECTION. 001400 FD ORDERS-FILE 001500 RECORD IS VARYING IN SIZE 001600 FROM 20 TO 200 CHARACTERS 001700 DEPENDING ON ORD-LRECL. 001800 01 ORDERS-RECORD. 001900 05 ORD-PRIMARY-KEY PIC X(12). 002000 05 ORD-BODY PIC X(188).
Sequence numbers 000100 style are illustrative. ORDRCB is the external token that must appear as //ORDRCB DD in JCL for typical Enterprise COBOL VSAM linkage unless your installation maps names differently through JCL or binder options. ORD-PRIMARY-KEY must align with DEFINE KEYS offset and length; a one-byte shift produces intermittent file status errors that look like data corruption when the real issue is key placement.
| Pattern | Beginner reading |
|---|---|
| ASSIGN TO ORDRCB | External name ORDRCB maps to JCL //ORDRCB DD under IBM default rules for VSAM; verify with PGM compiler option documentation. |
| ASSIGN TO VSAMFILE | Generic external name used in training examples; still requires matching DD in the job or proc step. |
| ASSIGN TO literal with hyphen | Hyphenated external names appear in older code; confirm whether your compiler treats them as user-defined words or literals. |
Some programs use ASSIGN TO DISK or other esoteric legacy tokens carried forward from older OS generations. Treat those as archaeology: photograph the line, ask a mentor, and map the active DD in the proc you actually run rather than guessing from a 1980s manual PDF that might not match your LPAR linkage editor configuration.
Each VSAM cluster your program opens needs its own SELECT, FD, and usually its own FILE STATUS variable or distinct subfields of a status table. Sharing one status field across unrelated files makes debugging painful because a failed READ leaves you guessing which file produced the code. Naming conventions that echo the business object (ORDERS-FILE, CUSTOMER-FILE) reduce cognitive load when reading thousands of lines written by someone else in a hurry.
When LISTCAT shows an alternate index and your program opens a path DD, the SELECT may still describe ORGANIZATION IS INDEXED with RECORD KEY equal to the primary key while alternate keys appear for programs that use alternate access paths. Some designs open the path and treat the alternate key as RECORD KEY; others keep primary RECORD KEY and rely on ADVANCING statements or vendor extensions. The only safe path is to mirror the working example from your application suite. Do not mix textbook snippets with production path names without a design review because path OPEN validates the entire AIX chain.
OPTIONAL signals that OPEN should tolerate a missing file in certain situations. VSAM masters that must exist for accounting month-end should never be marked OPTIONAL unless the business truly supports “no file means no processing.” Misused OPTIONAL hides configuration drift until downstream totals disagree with expected counts.
SELECT is the friendly nickname you call your friend in the playground. ASSIGN is the locker number written on their real backpack tag. JCL is the hall pass that connects the nickname to the real tag. If you call “Sam” but the tag says “Sara,” nobody’s lunch gets opened even if you know the combination lock math perfectly.
1. The JCL line //CUSTIN DD DSN=... requires which COBOL pattern when ASSIGN TO CUSTIN is coded?
2. RECORD KEY IS must reference:
3. ALTERNATE RECORD KEY appears when: