SELECT and ASSIGN for VSAM

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.

Fixed-form SELECT example with column discipline

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).

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
000100 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.

ASSIGN styles you will see in real code

External name patterns (verify with your compiler guide)
PatternBeginner reading
ASSIGN TO ORDRCBExternal name ORDRCB maps to JCL //ORDRCB DD under IBM default rules for VSAM; verify with PGM compiler option documentation.
ASSIGN TO VSAMFILEGeneric external name used in training examples; still requires matching DD in the job or proc step.
ASSIGN TO literal with hyphenHyphenated 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.

Multiple SELECT clauses for multiple VSAM files

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.

Alternate RECORD KEY considerations

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.

SELECT OPTIONAL semantics

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.

Checklist before you compile

  • ASSIGN token exists as a DD in the proc with correct spelling.
  • RECORD KEY field length matches DEFINE KEYS length.
  • FD record max size fits inside DEFINE RECORDSIZE maximum.
  • Alternate keys, if any, match DEFINE AIX key positions.

Hands-on exercises

  1. Copy a production SELECT into your notes and underline ASSIGN, RECORD KEY, and any ALTERNATE RECORD KEY.
  2. Write the exact // line you would add to JCL for that ASSIGN token.
  3. Find one program using OPTIONAL and interview the author about whether the file can truly be absent.

Explain Like I'm Five

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.

Test Your Knowledge

Test Your Knowledge

1. The JCL line //CUSTIN DD DSN=... requires which COBOL pattern when ASSIGN TO CUSTIN is coded?

  • No relationship
  • The DD name matches the ASSIGN external name CUSTIN
  • DD must be SYSOUT
  • ASSIGN must be ALL CAPS in PROC only

2. RECORD KEY IS must reference:

  • A working-storage counter only
  • A field in the record description associated with the FD for that file
  • A paragraph name
  • The JOBNAME

3. ALTERNATE RECORD KEY appears when:

  • You only read tape
  • You access a KSDS through an alternate index path or alternate key defined for the program
  • You compile with NODYNAM
  • You omit FD
Published
Read time11 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: IBM Enterprise COBOL Language ReferenceSources: IBM Enterprise COBOL for z/OS Language ReferenceApplies to: z/OS 2.5 / 3.x