File status and transactions

Common STATUS codes

Every I/O verb fills the FILE STATUS field: 00 success, 10 end of file, 21 duplicate key, 22 write on existing key, 23 read of missing key, 30 permanent error, 35 file not found. Test it after every verb in production code:

READ EMPLOYEE-FILE AT END MOVE "Y" TO WS-EOF END-READ. IF WS-STATUS NOT = "00" PERFORM HANDLE-FILE-ERROR END-IF.

Commit points

For update files, decide where a unit of work ends and commit there. On a CICS system that is EXEC CICS SYNCPOINT; on batch files it means closing and reopening at a known-good record boundary.

Recovery

Keep a restart position: the last committed key in a small file, so a failed job resumes instead of reprocessing the whole input. Log the key at each commit, and check it before the first READ.

The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev