COBOL START for VSAM

START positions an indexed or relative VSAM file so subsequent sequential reads can walk forward or backward from a chosen point. In KSDS batch, teams use START plus READ NEXT to print every customer whose ID is greater than or equal to a report threshold, to walk all duplicates sharing a non-unique key, or to restart a long sequential pass after checkpointing the last processed key. START does not fetch a row by itself; pairing it with the wrong READ form is a frequent defect where programmers expect random READ semantics and instead receive sequencing surprises. This page explains KEY IS relational operators at a beginner level, INVALID KEY handling, the interaction with ACCESS IS DYNAMIC, and operational cautions about holding position while other jobs insert keys nearby under duplicate-allowed definitions.

Relational operators on KEY IS

What each operator tries to do for KSDS browse (verify with your manual)
OperatorIntent
=Position at the first record whose key equals the value you moved into RECORD KEY before START.
>Position after the key value for strictly greater browse starting points.
>=Position at or after the key value; useful for range reports that include the boundary key.
< / <= (where supported)Backward or low-bound positioning patterns depend on compiler and ACCESS options—verify before use.

Exact support for less-than comparisons and READ PREV pairing depends on compiler options, VSAM capabilities, and ACCESS MODE. Rather than memorizing edge cases from a blog, build a matrix in your team wiki after running controlled tests on the LPAR version you ship to production. That matrix becomes the authoritative answer when two senior developers disagree during code review.

Keyed browse skeleton

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
MOVE REPORT-START-KEY TO CUST-KEY START CUSTFILE KEY IS NOT LESS THAN CUST-KEY INVALID KEY MOVE 'Y' TO DONE-FLAG END-START PERFORM UNTIL DONE-FLAG = 'Y' READ CUSTFILE NEXT AT END MOVE 'Y' TO DONE-FLAG END-READ IF DONE-FLAG NOT = 'Y' PERFORM PROCESS-CUST-RECORD END-IF END-PERFORM

Phrases like KEY IS NOT LESS THAN map to the >= style intent in English; COBOL uses reserved words instead of symbols in many formats. Replace with the exact START phrase your compiler accepts—some shops generate these lines from macros to avoid hand typos. The sample mixes START INVALID KEY with AT END on READ NEXT; unify FILE STATUS style if your standards forbid mixed paradigms.

Duplicates and START

NONUNIQUEKEY clusters allow multiple rows with the same primary key value. START with equality positions you at the first duplicate in VSAM order; subsequent READ NEXT walks the duplicate chain until the key changes. Programs must decide when to stop: after business columns differ, after a count limit, or after crossing a high boundary key you store in working storage. Failure to document that behavior causes report totals that disagree with SQL extracts built on distinct-key assumptions.

Checkpoint restart

  • Persist last successfully committed key in a checkpoint file.
  • On restart, START at or after that key instead of rewinding the entire cluster.
  • Coordinate with commit points if the program also updates rows it revisits.

Performance notes

Wide scans that START low and READ NEXT for millions of rows stress sequential prefetch paths; tune CI size, BUFND, and job priority with measurement. Narrow scans that START near the high end of the file still pay index descent cost once per START; avoid placing START inside an inner loop when the key does not change—that pattern multiplies positioning overhead unnecessarily.

ACCESS IS DYNAMIC and START

DYNAMIC access allows the runtime to switch between sequential and random styles. START establishes a sequential cursor context from a key boundary, while later random reads may still be legal depending on usage. Mixing styles without a state diagram invites defects. Draw your intended state machine on paper: after START, which reads are NEXT, which are random by key, and where you reset with another START. Reviewers thank you for the diagram during audits more than they thank you for clever paragraph names.

Equality START on missing key

START KEY IS EQUAL when no record matches typically triggers INVALID KEY or a not-found status. Some programs mistakenly treat that as fatal for the whole job when the business meaning is simply “no rows in this optional sub-section.” Encode business rules explicitly: optional sections should branch to empty-report printing rather than ABEND when START fails cleanly with documented codes.

READ PREV considerations

Backward browse using READ PREV appears in maintenance utilities that walk duplicates backward or reverse daily batches. Availability depends on compiler, VSAM, and ACCESS declarations. If your mentor says “we do not use READ PREV here,” believe them and avoid cargo-culting examples from other companies. When it is supported, you still anchor with START and then walk backward with disciplined AT END or status handling symmetrical to forward scans.

Hands-on exercises

  1. Build a report that STARTs at a boundary key and stops when the key prefix changes.
  2. Experiment with duplicate keys: START equal, then READ NEXT until key changes; log each row.
  3. Compare elapsed time between full sequential read and START plus partial scan on a large sandbox KSDS.

Explain Like I'm Five

START is placing your bookmark at the first dictionary page that matches “start at words beginning with M.” READ NEXT is turning pages forward one at a time from that bookmark. If no words begin with M, the librarian shakes their head—INVALID KEY. If you forget to turn pages after placing the bookmark, you never actually read any words.

Test Your Knowledge

Test Your Knowledge

1. START establishes position; which verb usually retrieves the first data row afterward?

  • WRITE
  • READ NEXT
  • DELETE without READ
  • STOP RUN

2. START with KEY IS = and no matching key typically triggers:

  • Automatic WRITE
  • INVALID KEY path or not-found status
  • Compiler warning only
  • SYSOUT redirect

3. START is most associated in class labs with:

  • Tape mount messages
  • KSDS keyed browse
  • GDG scratch
  • PROC compilation
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