Simple Mainframe Universe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

VSAM Troubleshooting


VSAM file status 22 duplicate key

VSAM file status 22: Duplicate key — WRITE tried to add a record whose key already exists.

What it means

  • Duplicate key — WRITE tried to add a record whose key already exists.
  • Sequence error on a sequential WRITE.

Common causes

  • Restart reprocessing inserting the same records.
  • Key not unique in input data.
  • ESDS written with keys out of order.

How to diagnose

  • Find the duplicate key value.
  • Check restart logic for repeated inserts.

How to fix it

  • Skip duplicates, or delete-then-insert where appropriate.

Example: Always check FILE STATUS after I/O

READ CUSTFILE NEXT RECORD AT END MOVE 'Y' TO WS-EOF NOT INVALID KEY CONTINUE END-READ. IF WS-FS NOT = '00' DISPLAY 'File status: ' WS-FS END-IF.

FILE STATUS after every I/O turns mystery failures into clear codes.

Interview tip

  • Q: How would you troubleshoot a VSAM file status 22 duplicate key in production?
  • A: I would confirm the exact file status code, check the JCL DD and catalog, then apply the specific fix.

Prevention checklist

  • Check FILE STATUS after every OPEN/READ/WRITE.
  • Keep FD layouts in sync with cluster definitions.




© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant