VSAMintermediate

VSAM File Status Codes and Error Handling

Recognize the most common VSAM FILE STATUS codes returned to COBOL programs and understand the disciplined error-handling patterns built around them.

Every VSAM operation returns a two-character status. Most production incident investigations start with which one came back.

A VSAM file status code is the receipt printed after every ATM transaction — most of the time it just confirms success, but a specific code for 'insufficient funds' versus 'card not recognized' versus 'network error' tells you precisely what actually happened and what to do next, and a careful person reads that receipt every single time rather than assuming the transaction always went through.

Key Concepts

1
    SELECT CUST-FILE ASSIGN TO CUSTFILE
        ORGANIZATION IS INDEXED
        ACCESS MODE IS DYNAMIC
        RECORD KEY IS CUST-ID
        FILE STATUS IS WS-FILE-STATUS.
2
The codes that come up constantly.
    00   success
    10   end of file -- normal, and how a read loop ends
    22   duplicate key on WRITE where the key must be unique
    23   record not found on a keyed read
    35   file not found at OPEN -- usually a missing DD in the JCL
    37   OPEN mode conflict, e.g. opening a KSDS as sequential output
    92   logic error -- an operation the current OPEN mode does not allow
    93   resource unavailable -- often the file is held by another job
3
Two of these are normal, not errors. 10 is how you know a sequential read has finished. 23 is the correct answer to "does this customer exist" when they do not.
1023
4
Treating either as a failure produces a program that abends on the ordinary case.
5
The rest need handling. 35 at OPEN almost always means the DD statement is missing or the dataset name is wrong — a JCL problem, not a program one. 93 means somebody else holds the file, which in a batch window usually means two jobs were scheduled against it at once.
3593
6
Check the status after every operation.
    EXEC-READ.
        READ CUST-FILE
        EVALUATE WS-FILE-STATUS
            WHEN '00'  PERFORM PROCESS-RECORD
            WHEN '10'  SET END-OF-FILE TO TRUE
            WHEN '23'  PERFORM RECORD-NOT-FOUND
            WHEN OTHER PERFORM FATAL-IO-ERROR
        END-EVALUATE.
7
WHEN OTHER is what stops silent corruption. A program that tests only for 00 and 10, and does nothing else, continues after a failed read with whatever the record area held before — usually the previous record.
WHEN OTHER0010
8
So it processes the same record twice and nobody notices. That pattern is one of the most common causes of quietly wrong output in legacy VSAM applications, and it produces no error anywhere.
9
It is the same discipline as SQLCODE in DB2, and the parallel is worth drawing: check the outcome of every I/O operation, distinguish the expected non-zero results from the genuine failures, and never let an unexpected one fall through to nothing.
SQLCODE
10
What the interviewer is probing.1. "What does status 22 mean?" Probing: practical reading. Stalls: "An error." Moves up: a duplicate key on a write — a business condition to be handled, not an abend.
11
2. "What does status 23 mean?" Probing: the common one. Stalls: "A failure." Moves up: record not found, which on a lookup is a normal outcome your logic must expect.
12
3. "Why check FILE STATUS rather than letting it abend?" Probing: the discipline. Stalls: "Habit." Moves up: an abend in a batch window costs a rerun and an operator call; a handled condition writes a reject record and the job completes.
13
4. "What does a status 9x code indicate?" Probing: the detail. Stalls: "Unknown." *Moves up:* an implementation-defined error with a VSAM return code behind it, which means consulting the detailed feedback rather than guessing.