File status 05: OPTIONAL file not present at OPEN
File status 05 means an OPEN worked, but the file is declared OPTIONAL and wasn't present. After OPEN INPUT the first READ hits end of file. After OPEN I-O or EXTEND the runtime creates the file.
Other names for this code
Also written as FS 05, file status code 05, COBOL status 05, status key 05, SELECT OPTIONAL file status, SK05.
What it means
A file is declared optional with SELECT OPTIONAL. That tells COBOL the program can run whether or not the file exists. When OPEN finds such a file missing, it doesn't fail. It completes and sets 05 so the program can tell the file wasn't there.
What happens next depends on the open mode. After OPEN INPUT the file behaves as if it were empty. The first sequential READ gives the at-end condition (status 10), and a random READ or START gives invalid key (status 23). After OPEN I-O or OPEN EXTEND the file is created and is ready for use. OPEN OUTPUT never returns 05, because output mode creates the file anyway.
"Not present" means different things for each access method. A QSAM file is available when it has a DD allocation and the data set physically exists. A VSAM file is available only if it has a DD allocation, was defined with IDCAMS, and holds records or has held them at some point. So a VSAM cluster that was defined and never loaded counts as missing. If it's OPTIONAL, OPEN INPUT gives 05. Without OPTIONAL, the same OPEN fails with status 35. IBM's status table adds one exception. Status 05 doesn't apply to VSAM sequential files, which means an ESDS.
Common causes
- The DD statement for an OPTIONAL file was left out of the step, either on purpose for a run with no input or by mistake.
- The ddname in the JCL doesn't match the name in the ASSIGN clause, so the runtime finds no allocation and treats the file as absent.
- A VSAM KSDS or RRDS was defined but never loaded, and the program opens it INPUT or I-O.
- A first run, where a history or control file doesn't exist yet and the program creates it with OPEN EXTEND or OPEN I-O.
How to find the problem
- DISPLAY the file status after OPEN. Only OPEN sets 05.
- Look at the allocation messages for the step in the job log (JESYSMSG). Every DD that was allocated is listed by ddname, so a missing one stands out.
- Compare the ASSIGN name in the SELECT clause with the DD names in the JCL, character by character.
- For VSAM, run IDCAMS LISTCAT ALL. A HI-U-RBA of 0 means the cluster has never held a record.
How to fix it
- If the file really is optional, code for it. Check for 05 after OPEN and skip or adjust the processing that depends on the file.
- If the file must be there, remove OPTIONAL from the SELECT clause. A missing file then fails at OPEN with 35 instead of the job running quietly with no data.
- Add or correct the DD statement.
- Prime a new VSAM cluster before it's read. Load it with IDCAMS REPRO, or write a dummy record and delete it. After that the cluster counts as available even when it's empty.
- Test for success on the first digit of the status, so 05 isn't reported as an error by a check that only accepts 00.
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
Why did my program read nothing and end normally?
If the input file is OPTIONAL and missing, OPEN INPUT returns 05 and the first READ goes straight to end of file. Check the OPEN status and the DD statement.
Does OPEN OUTPUT ever return 05?
No. OPEN OUTPUT creates the file, so a missing file isn't a special case for it.
What is the difference between 05 and 35?
Both mean the file wasn't available at OPEN. With OPTIONAL the OPEN works and returns 05. Without it the OPEN fails with 35.