File status 38: OPEN of a file closed WITH LOCK
File status 38 means the program tried to OPEN a file that it had earlier closed with CLOSE ... WITH LOCK. A file closed with lock can't be opened again while the run unit is active.
Other names for this code
Also written as FS 38, file status code 38, COBOL status 38, status key 38, CLOSE WITH LOCK, SK38.
What it means
CLOSE has an optional WITH LOCK phrase. It closes the file and marks it so the same run unit can't open it again. Any later OPEN of that file fails with 38, a permanent error.
This rule belongs to COBOL, not to the data set. It isn't a lock in the z/OS sense. Other jobs and other run units can still open the data set. Sharing between jobs is controlled by DISP and, for VSAM, by SHAREOPTIONS. The rule works the same way for QSAM and VSAM files.
Under the older CMPR2 behavior this case was reported as 92, a general logic error. Enterprise COBOL gives it its own code, which makes the cause easy to spot once you know it.
Common causes
- A routine closes a file WITH LOCK at the end of one pass, and a later pass or a restart routine opens it again.
- A called subprogram closes its file WITH LOCK, and the caller calls it again later in the same job step.
- WITH LOCK was added to stop a file being processed twice, and a later change brought in a legitimate second OPEN.
How to find the problem
- Search the program and its subprograms for CLOSE statements with WITH LOCK for that file.
- Trace the order of OPEN and CLOSE statements. Put a DISPLAY before each one, or use a debugger, to see which CLOSE ran before the failing OPEN.
- If a subprogram owns the file, check how many times it's called during the run.
How to fix it
- Remove WITH LOCK if the file needs to be opened again. A plain CLOSE allows a later OPEN.
- If the lock is deliberate, keep it and change the logic so the second OPEN doesn't happen, for example by setting a flag when the file is finished.
- Check the status after every OPEN so a 38 is reported with the file name.
IBM documentation
IBM Enterprise COBOL documentation. Use the documentation for your installed release.
This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.
Related codes
Questions
Does CLOSE WITH LOCK stop other jobs from using the file?
No. It only stops the same run unit from opening the file again. Use DISP, and SHAREOPTIONS for VSAM, to control other jobs.
Is status 38 the same as a file being in use?
No. A VSAM file held by another job gives 93, and a data set name held with DISP=OLD makes the job wait at allocation.
Why did older programs report this as 92?
Under CMPR2, 92 was a catch-all logic error. Enterprise COBOL splits it into specific codes such as 38, 41 and 42.