COBOL file status 35, 39, 22, 23, 92 — VSAM I/O errors
The two-character FILE STATUS tells you why an OPEN, READ or WRITE on a VSAM file failed. Learn the handful that cover most incidents.
What happened
A COBOL program working with a VSAM file got a non-zero file status on an OPEN, READ, WRITE, REWRITE or DELETE. Depending on how the program is written it either displays the status and ends with a return code or user abend, or it carries on and fails later.
MPACCT01 OPEN FAILED FILE=ACCTMAST STATUS=39 MPACCT01 VSAM RC=0008 FUNC=0000 FDBK=0000 MPACCT01 ENDING WITH RETURN CODE 16
What it means
The first digit gives the class (0 success, 1 at end, 2 invalid key, 3 permanent error, 4 logic error, 9 implementor-defined). The codes you meet most with VSAM:
| Status | Meaning |
|---|---|
| 00 / 02 / 97 | Success. 02 = duplicate alternate key that is allowed. 97 = OPEN succeeded after VSAM verified the file's integrity. |
| 10 | End of file on a sequential READ. |
| 21 | Sequence error — key changed between READ and REWRITE, or keys written out of ascending order. |
| 22 | Duplicate key on WRITE or REWRITE where duplicates are not allowed. |
| 23 | Record not found on a random READ, START or DELETE. |
| 35 | OPEN INPUT, I-O or EXTEND of a required file that is not available (often no DD or no dataset). |
| 37 | OPEN mode not allowed for this file. |
| 39 | OPEN found a conflict between the file's fixed attributes and the program's (organization, key, record size). |
| 41 / 42 / 47 / 48 / 49 | Logic errors: already open, not open, or wrong open mode for READ, WRITE, DELETE/REWRITE. |
| 92 | Logic error (general). |
| 93 | Resource not available — another job or region holds the dataset. |
| 96 | No DD statement for a file that needs one. |
For VSAM files, the FILE STATUS clause can name a second, 6-byte data item. It holds the VSAM return code (0, 8 or 12), function code (0–5) and feedback code (0–255) as three 2-byte binary fields. They are set only when VSAM returns a non-zero return code, and are meaningful only then.
Typical causes
- 35 — the DD statement is missing or misspelled, or the dataset was not defined yet.
- 39 — the cluster was defined with a different key position/length or record size than the program's FD and RECORD KEY; or a KSDS is opened as if it were an ESDS.
- 22 — the same key arrives twice in the input, or a rerun inserts records already loaded.
- 23 — the key is not on file; often a key-building or data issue rather than a VSAM problem.
- 93 — the resource is not available, typically because another job or region holds the dataset.
- 4x / 92 — the program logic is wrong: OPEN of a file already open (41), CLOSE of a file not open (42), REWRITE or DELETE without a successful READ (43), READ in the wrong open mode (47).
Symptoms
- A clean step end with a high return code and the program's own display — not an abend.
- If the program never checks status, a later S0C4 or a wrong report can be the first visible symptom.
- 39 and 35 appear on the very first OPEN; 22/23 appear part way through the data.
Where to look
- The program's display in SYSOUT or the job log for the status and the VSAM return/function/feedback codes.
- The JCL DD for the file name and DISP.
- A LISTCAT of the cluster for KEYS, RECORDSIZE and organization.
- The program's FD, SELECT and RECORD KEY clauses or copybook.
How to diagnose
- Note the status and the operation (OPEN, READ, WRITE…) and, for VSAM, the extended codes.
- For 35/96 check the DD name in JCL against the ASSIGN name in the program.
- For 39 compare LISTCAT KEYS and RECORDSIZE with the record layout and key definition in the program.
- For 22/23 capture the key value and check the input data or the key-building logic.
- For 93 find who else holds the dataset at that time.
How to fix
Fix the cause, not the symptom: add or correct the DD, redefine the cluster to the agreed attributes with IDCAMS, correct the FD to match the cluster, or clean the duplicate keys in the input. Then restart from the agreed point — for loads that already wrote records, check whether a rerun will cause 22s and agree a recovery plan first.
How to prevent
- Check FILE STATUS after every I/O statement, and declare the 6-byte VSAM status area for VSAM files.
- Keep the cluster definition and copybook under the same change control.
- Design loads to be restartable without inserting duplicates.
Production considerations
Interview question
A batch program gets file status 39 on OPEN of a KSDS. What do you check?
Stuck on something else?
Ask the community or search the full course.