COBOL REWRITE on indexed files: required lock state before execution
0 reputation · 17 Mar 2021, 16:22 UTC
COBOL REWRITE on indexed files: required lock state before execution
Goal: Clarify whether a record must be locked for update before executing REWRITE on an indexed file opened in I-O mode, and how this requirement varies between IBM Enterprise COBOL and GnuCOBOL.
Constraints: The ANSI COBOL 85 standard states that REWRITE updates the current record and requires the record to be locked for update, but it does not mandate explicit locking, leaving the detail to the compiler. IBM Enterprise COBOL documentation specifies that the file must be opened in I-O mode and the last I/O operation must be a successful READ (or START) that positioned the record; otherwise REWRITE fails with file status 90. GnuCOBOL treats REWRITE as permissible after any successful READ that positioned the record, returning file status 92 if the record is not locked for update. The behavior when another process holds a shared lock differs: IBM COBOL rejects REWRITE with file status 92, while GnuCOBOL may allow the rewrite if the underlying OS permits it, risking data corruption.
Uncertainty: It remains unclear which lock state (exclusive, shared, or none) is sufficient to guarantee a successful REWRITE across both compilers without invoking undefined behavior or file corruption.
Does REWRITE require the record to be locked for update prior to execution?
Does the required lock differ between IBM Enterprise COBOL and GnuCOBOL?
Is a successful READ alone sufficient to satisfy the lock prerequisite, or must an explicit lock be obtained?