VSAM file status code indicates the status of the operation. VSAM files require at least one data record to be initially loaded into the file before the file could be opened for input or update processing. This is because VSAM issues a VERIFY command upon opening a file to reset the end-of-file pointer. If the file has never been loaded, the VERIFY fails because the high used RBA (Relative Byte Address) (HI-USEDRBA) is still zero. Therefore, VSAM files must be initially “loaded” to set the HI-USED-RBA to a value other than zero. This is done by writing a record to the VSAM file in “load” mode and optionally deleting the record to empty the file while leaving the HI-USED-RBA at a non-zero value.
A VSAM file that has never contained a record is treated as unavailable. Attempting to open for input will fail. An empty file can be opened for output only. When you open for output, COBOL will write a dummy record to the file & then delete it out.
VSAM distinguishes between an empty data set (that is, one that has never had a record in it) and a data set with no records (for example, adding a record to a KSDS and then deleting it). The difference is that for each write to a VSAM data set, a pointer is updated to reflect the highest used RBA. If you have never written any data to the data set, this pointer has no value and hence causes VSAM problems when attempting to use it to locate the end of the used data. Any program attempting to open a VSAM data set for input before anything has been written to the data set will have a problem & amend will happen with return code 35 as VSAM is unavailable.
Initializing VSAM File Status (Program)
- To initialize the VSAM, you can open it once in output mode and close it in the program during initialization, it could solve your problem. After that again open it in I/o mode.
- Write a step in JCL that delete defines VSAM and REPRO some records from a flat-file Say GDG version this step should be executed before the program uses VSAM.
Initializing VSAM File Status (Manually)
- Open the VSAM file in EDIT mode in File Manager.
- Insert any record in the VSAM file and save.
- Delete that record & save it will initialize the VSAM file.
Example
//STEP010 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSIN DD * DELETE XXXXX.TEST.VSAM PURGE CLUSTER DEFINE CLUSTER(NAME(XXXXX.TEST.VSAM) - VOLUME(* *) - UNIQUE - SHAREOPTIONS(3 3) - CYLINDERS(7 7)) - DATA (NAME(XXXXX.TEST.VSAM.DATA) - KEYS (29 0) - RECORDSIZE(35 35) - CISZ(4096)) - INDEX (NAME(XXXXX.TEST.VSAM.INDEX) - NOIMBED NOREPLICATE) /* //STEP020 EXEC PGM=IDCAMS //IN DD DSN=XXXXX.TEST.PS,DISP=SHR //OUT DD DSN=XXXXX.TEST.VSAM,DISP=SHR //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * REPRO INFILE(INF) OUTFILE(OUTF) COUNT(1) /*
VSAM File Status Resolution
| Code | Typical meaning | Common causes | Recommended action |
|---|---|---|---|
| 00 | Successful completion | Normal I/O | Continue processing |
| 02 | Non-unique alternate key condition | AIX non-unique read condition | Validate access path and logic |
| 04 | Length mismatch / boundary-related record issue | LRECL mismatch, variable-length inconsistency | Check layout, copybook, and record format |
| 10 | End of file / no more records | Sequential browse complete | End loop cleanly |
| 14 | RRDS relative record out of range | Invalid RRN or slot | Validate record number and file size |
| 20 | Invalid key / sequence issue | Bad key value, wrong sequence | Check key definition and access mode |
| 21 | Duplicate or sequence error | Insert to existing key, bad REWRITE key change | Handle as business duplicate or fix key logic |
| 22 | Duplicate primary key | KSDS duplicate insert | Route to duplicate handling process |
| 23 | Record not found / permanent read issue | Search miss, incorrect key, deleted data | Recheck key, indexing, and data load integrity |
| 24 | Key outside boundary | High/low key violation | Validate key range and start position |
| 28 | Space issue | CI/CA exhaustion, file full | Reorganize or extend cluster |
| 30 | Permanent I/O error | Device, dataset, or media issues | Escalate to storage/operations; inspect logs |
| 34 | Boundary violation | Relative or sequential boundary issue | Verify access mode and record position |
| 35 | Open failure / file not present / definition issue | Missing DD, wrong DISP, missing catalog entry | Check JCL and file definition |
| 37 | Wrong open mode | INPUT vs I-O vs OUTPUT mismatch | Correct COBOL OPEN mode |
| 38 | File locked | Share or enqueue conflict | Review sharing, batch overlap, and CICS serialization |
| 39 | Conflicting file attributes | DD/COPYBOOK mismatch, wrong organization | Align program and data set definition |
| 41 | File already open | Logic error | Prevent double open in run unit |
| 42 | Close on non-open file | Logic error | Guard CLOSE with state checks |
| 43 | REWRITE without prior READ for update | Program sequence error | Ensure successful READ before REWRITE |
| 44 | Length mismatch on REWRITE | Record length changed unexpectedly | Preserve original record format |
| 46 | Read beyond EOF / no current record | Bad sequential flow | Check 10 and EOF condition logic |
| 47 | READ on file not open for input/I-O | Wrong mode or control flow | Open correctly before READ |
| 48 | WRITE on file not open for output/I-O | Wrong mode | Correct OPEN mode |
| 49 | DELETE/REWRITE on file not open I-O | Wrong mode | Ensure I-O access before update verbs |
| 90 | Unsuccessful I/O operation | Generic failure | Use VSAM detail and job logs |
| 91 | Authorization failure | Security / access control | Verify authority |
| 92 | Logic error | Program sequencing | Add state validation and unit tests |
| 93 | Resources unavailable | Buffer, latch, or sharing issue | Review resource contention and environment |
| 94 | Sequential record unavailable / concurrent open error | Sharing conflict | Check serialization and access rules |
| 95 | Invalid or incomplete file info | Bad attributes or missing definitions | Verify DD and file definition |
| 96 | No DD statement | JCL allocation missing | Add or fix DD statement |
| 97 | Open successful and integrity verified | Successful open with verification | Continue processing |
| 98 | File locked | Dataset lock / allocation issue | Clear contention or wait/retry |
| 99 | Record locked | Locked record access failed | Retry under proper lock strategy |
VSAM return code 00 – SUCCESSFUL COMPLETION
Root Cause:
- The Length of the record does not match the properties or attributes defined for the length of the file.
- The file is a Variable Length block file but you defined a fixed-length block in your FD clause. Most of the time, this error occurs while reading from a file or writing to a file.
Fix:
- Assign the proper record length of your file in the DCB Parameter and match it with the length provided in the FD clause of your COBOL Program.
VSAM return code 04 – READ, WRONG LENGTH RECORD
Root Cause: The logical error in the program
Fix: The Logic of the COBOL Program itself is wrong so you need to correct the logic of the program.
VSAM return code 13 – File Not Found
Root Cause: File Not Found
Fix: Provide the correct details of the file name. Check if the path of your VSAM file is correct.
VSAM return code 16 – Accessing VSAM file Error
Root Cause: It depends on the type of file, the program used to access the VSAM file and is mostly related to accessing
Fix: Fix will be based on the way you are accessing the file from a program. Are you trying to update a file for which you do not have permission?
VSAM return code 19 – Accessing VSAM file Error
Root Cause: In case you are accessing the VSAM file in CICS and you did not provide a proper entry of the file
Fix: Check if the PCT entry of the file is proper.
VSAM return code 20 – INVALID KEY VSAM KSDS OR RRDS
Root Cause: In the case of KSDS or RRDS, the key is an INVALID KEY
Fix: Correct the KEY. Check the position, definition, etc and correct it.
VSAM return code 22 – DUPLICATE KEY
Root Cause: Duplicate key defined for Indexed or relative Files. Duplicate alternate key but the alternate key is defined as unique.
Fix: Remove the duplicate entry of the key.
VSAM return code 23 – RECORD NOT FOUND or FILE NOT FOUND
Root Cause: The record is not found when you are trying to access using a key. File not found.
Fix: Check if the record is correct or the path to access the file is given correctly.
VSAM return code 24 – Invalid Key – key outside the boundary of file.
Root Cause: Trying to write beyond the boundary in case of Relative and indexed files using the key. The size of the Relative Record number is larger.
Fix: Do not write beyond the boundary or change the boundary.
VSAM return code 28 – Unable to extend the dataset
Root Cause:
- The primary space is already exhausted and the space in Secondary space cannot be extended further due to the limitation in space.
- The Index CI is not large enough
Fix: Check with your storage group or try to give less value to your secondary allocation.
VSAM return code 35 – OPEN, FILE NOT PRESENT
Root Cause: You are trying to open a file that is not present.
Fix:
- Check why the file is not present? Are you providing the correct filename with the correct path?
- Initialize the file using any of the above method.
VSAM return code 37 – Open file error due to opening mode
Root Cause: You are trying to open a file in a particular mode that is not allowed for that file.
Fix: Check the file opening modes available for the file and fix it.
VSAM return code 39 – LOGIC ERROR
Root Cause:
- The Unsuccessful opening of a file due to the conflicting attributes of the file.
- Wrong value in DCB which is not matching the file attributes in the Program.
Fix: Check the file attribute in the actual file, the file attributes defined in the FD section of the program, the record length in your DCB Parameter and the record mode, etc.
VSAM return code 41 – OPENING A FILE THAT IS ALREADY OPENED
Root Cause: You are trying to open a file in a particular mode that is not allowed for that file.
Fix: Check the file opening modes available for the file and fix it.
VSAM return code 42 – CLOSING A FILE WITHOUT OPEN.
Root Cause: When the file is already closed and you try to do a CLOSE operation once again on the file which is already closed.
Fix: Change the program to make sure that you do not give a CLOSE file on the file which is already closed.
VSAM return code 46 – SEQUENTIAL READ WITHOUT POSITIONING
Root Cause: If you try to sequentially read a file even when the end of the record is reached.
Fix: Once the End of the File is reached, do not read the file.
VSAM return code 47 – READING FILE NOT OPEN AS INPUT/IO/EXTEND
Root Cause: File not opened in INPUT or I-O mode.
Fix: Open the file in INPUT or I-O mode.
VSAM return code 90 – Unsuccessful OPEN, READ, WRITE or CLOSE operation
Root Cause:
- Unsuccessful OPEN, READ, WRITE or CLOSE operation.
- You defined ‘LINE SEQUENTIAL’ for file
- You missed to initialize the file before OPEN, READ or WRITE statement.
- If you are trying to open an empty file or a file which does not exist and you have not tried to capture the return code of the OPEN or READ or WRITE, then you can get this generic error.
- There can be other reason for status code 90 as well as this error is not a specific rather a generic error.
Fix:
- If you have coded ‘LINE SEQUENTIAL’ then remove it.
- Code the file status for OPEN, READ, WRITE or CLOSE operation and see where you are getting the error so that you can easily fix that.
VSAM return code 91 – Password or authorization failed
Root Cause: Password Failure. Authorization failure.
Fix: Check the password which is given for VSAM file or whether you are authorized to access the file or not?
VSAM return code 92 – LOGIC ERROR / OPENING A OPEN FILE / READING OUTPUT FILE / WRITING INTO A INPUT FILE / DEL or REW BUT NO PRIOR READ
Root Cause:
- Logic error.
- Common logic errors are like a wrong way of Opening the file, improper way of reading the file or Writing the file.
Fix:
- Check the logic of the program mentioned above and fix it.
- The most common status code 92 is ‘VSAM file status 92 while writing’ and you need to fix the logical error related to write or rewrite. Check if the file is opened correctly for writing
VSAM return code 93 – OPENING A FILE THAT IS ALREADY OPENED
Root Cause:
- Resource not available.
- Storage is insufficient for
- Extents used up and extra extents not available
Fix: Check with your storage group.
VSAM return code 96 – MISSING DD STATEMENT IN JCL
Root Cause: Missing DD statement for the VSAM or QSAM file.
Fix: Code the missing DD statement in the JCL
VSAM return code 97 – OPEN OK, FILE INTEGRITY VERIFIED
Root Cause: OPEN file successful and the file integrity verified. This might happen when a previous Job did not close the file so VSAM has to verify the integrity of the file.
Fix: Check the file opening modes available for the file and fix it.
VSAM return code 100 – Improper loading
Root Cause:
- Improper loading of file.
- Loading of a cluster using REPRO failed.
Fix: Before building the alternate index(AIX) and path, you need to load the cluster.
VSAM return code 160 – input file might be empty
Root Cause: The input file might be empty when you try to open it.
Fix: Check with your storage group.
VSAM return code 168 – The device type is not supported
Root Cause: The device type is not supported.
Fix: Check with your admin.
| Symptom | Likely cause | First check | Next step |
|---|---|---|---|
| OPEN returns 35 | Missing DD, wrong DISP, catalog issue | JCL and LISTCAT | Fix allocation or catalog entry |
| READ returns 10 | EOF reached | Sequential loop logic | Exit loop cleanly |
| WRITE returns 22 | Duplicate key | Business rule or source data | Quarantine duplicate and continue or reject |
| REWRITE returns 43 | No prior READ for update | Program flow | Ensure positioned record exists |
| DELETE returns 49 | Not opened I-O | OPEN mode | Switch to I-O |
| 90/93/95 class code | Environmental or resource issue | VSAM detail + job log | Resolve security, resource, or definition issue |
Decision tree
Use this decision path for rapid triage:
-
Did the failure occur at OPEN? If yes, inspect JCL, DD allocation, catalog entry, and data set attributes.
-
Did it occur on READ/WRITE/REWRITE/DELETE? If yes, confirm OPEN mode, file organization, and verb sequencing.
-
Is the status in the
20s? If yes, inspect key logic, duplicate handling, and file positioning. -
Is the status in the
30sor90s? If yes, inspect the environment, security, locks, resources, and definition integrity. -
Is the file interrupted after an abend? If yes, run
VERIFY ... RECOVERand thenEXAMINE.
Case studies
Case 1: Duplicate insert in KSDS. A nightly load received status 22 because the upstream system resent a customer number already present in the cluster. The team changed the load to separate new inserts from correction updates and routed duplicates to a reject file.
Case 2: Open failure after deployment. A new COBOL package returned status 35 because the DD statement was missing in the promoted JCL stream. The fix was to align the deployment checklist with catalog validation and automated LISTCAT verification.
Case 3: Interrupted update after abend. A KSDS was left in an uncertain state after a CANCEL. Operations ran VERIFY DATASET(... ) RECOVER, then EXAMINE to confirm health before resuming REPRO processing.
Top 10 mistakes
-
Not checking
FILE STATUSafter every verb. -
Using the wrong OPEN mode for the intended operation.
-
Ignoring duplicate-key handling in KSDS loads.
-
Assuming
35is always a data problem instead of a JCL or catalog issue. -
Rewriting without confirming prior READ for update.
-
Missing or stale PATH/AIX definitions after base-cluster changes.
-
Reloading data without structural validation.
-
Overbuffering without measuring paging impact.
-
Mixing batch and CICS assumptions about locking and sharing.
-
Treating
VSAM Initializationas a one-time task instead of a lifecycle process.
Interview questions
Q1. What is the difference between COBOL file status and VSAM status?
COBOL file status is the high-level two-byte result code, while the VSAM status area provides more detailed return information for VSAM files.
Q2. When should you use EXAMINE and VERIFY?
Use them after interrupted VSAM processing or when structural integrity is in doubt; VERIFY ... RECOVER followed by EXAMINE is a common recovery pattern.
Q3. What is the main difference among KSDS, ESDS, and RRDS?
KSDS is key-based, ESDS is creation-order/RBA-based, and RRDS is relative-record-number based.
Q4. Why is status 35 so common in production?
Because it often signals environment or definition issues such as missing DDs, wrong dataset attributes, or catalog problems.
Q5. How do you handle duplicate keys in a KSDS load?
Treat them as expected business exceptions where appropriate, or reject them with an audit trail and a remediation path.
Q6. During the processing of a VSAM file, some system error occurs and it is subsequently unusable how to fix this issue?
Run VERIFY
Q7. How do you fix the problem associated with VSAM file status out of space condition?
- Define new VSAM dataset allocated with more space.
- Use IDCAMS to REPRO the old VSAM file to the new VSAM dataset.
- Use IDCAMS to ALTER/rename the old VSAM dataset or use IDCAMS to DELETE the old VSAM dataset.
- Use IDCAMS to ALTER/rename the new VSAM dataset to the name of the original VSAM dataset.
Q8. What are VSAM file status codes?
They are COBOL status values that report the result of VSAM file operations such as OPEN, READ, WRITE, REWRITE, DELETE, and CLOSE.
Q9. What is VSAM initialization?
It is the process of defining, deleting, verifying, and loading a VSAM cluster so it is structurally ready for application use.
Q10. How do you initialize a VSAM file in IDCAMS?
A common pattern is DELETE, DEFINE CLUSTER, and then REPRO to load data.
Q11. What does COBOL status 35 mean for VSAM?
It usually indicates an open failure or related definition problem, often involving JCL, catalog, or file attributes.
Q12. Why use a second FILE STATUS item for VSAM?
Because it provides more detailed return information than the two-byte COBOL status alone.
Q13. What is the best first step in VSAM troubleshooting?
Check the verb, the status code, the OPEN mode, and the DD/catalog definition.
Conclusion
VSAM mastery comes from combining correct definitions, disciplined COBOL error handling, and repeatable initialization and recovery procedures. If you standardize FILE STATUS checks, automate IDCAMS validation, and document your recovery paths, you will reduce outages and shorten triage time.
For deeper learning, explore related mainframe topics such as COBOL file handling, IDCAMS utility patterns, JCL utilities, CICS file control, and DB2 integration to build a complete enterprise data-processing toolkit.
