File status 04: Record length doesn't match the FD
File status 04 means a READ worked, but the length of the record read is outside the minimum and maximum record sizes in the program's file description. The program carries on, but the record area may not line up with the copybook.
Other names for this code
Also written as FS 04, file status code 04, COBOL status 04, status key 04, record length mismatch COBOL, SK04.
What it means
Status 04 is in the successful class, so the READ completed. IBM sets it when the record just read is shorter than the smallest record or longer than the largest record the FD describes. In plain terms, the program's picture of the record and the real data have drifted apart.
It applies to QSAM and VSAM files. With QSAM it shows up most with variable-length (RECFM=V or VB) data sets, where every record carries its own length. With VSAM it shows up when a record in the cluster is shorter or longer than the FD allows. A conflict in fixed attributes found at OPEN, such as the wrong maximum record length, is a different status, 39.
Recent Enterprise COBOL releases have a VLR compiler option that changes this. With VLR(STANDARD) the runtime reports 04 as described. With VLR(COMPAT) the same READ returns 00, which keeps the behavior of earlier releases. That's why some shops first meet 04 after moving programs to a newer compiler.
Common causes
- The copybook used in the FD is out of date. Someone lengthened or shortened the record and only some programs were recompiled.
- The FD says
RECORD VARYING FROM x TO ywith a range that doesn't cover every record, for example a short header or trailer record. - A variable-length QSAM file was written by another program or a file transfer with records longer than the FD maximum.
- A VSAM cluster's RECORDSIZE allows longer records than the FD describes, and some records use that extra length.
How to find the problem
- DISPLAY the file status after each READ and note which records return 04. Write out their keys or record numbers.
- Compare the FD's RECORD CONTAINS or RECORD VARYING clause with the data set. For QSAM, check RECFM and LRECL in ISPF option 3.4. For VSAM, run IDCAMS LISTCAT ALL and look at AVGLRECL and MAXLRECL.
- Browse a failing record in hex. In a RECFM=V record, the first two bytes of the 4-byte record descriptor word hold the length, and that length includes the 4 bytes of the RDW itself.
- Check the options page of the compiler listing for VLR, so you know which behavior the program was built with.
How to fix it
- Bring the FD and the data back into line. Update the copybook and recompile every program that reads the file.
- Widen the RECORD VARYING range if short or long records are valid data.
- If you need the old behavior while you sort out the data, compile with VLR(COMPAT). Treat it as a stopgap, because the records still don't match the layout.
- Accept 04 as success in your status test only after you've checked that the missing or extra bytes don't matter to the program.
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
Is file status 04 an error?
No. The READ worked. It warns you that the record's length is outside what the FD allows, so the fields in the record area may not hold what you expect.
Why did 04 start appearing after a compiler upgrade?
Newer Enterprise COBOL releases check record lengths on READ more strictly. Compiling with VLR(COMPAT) returns 00 for these reads, as earlier releases did.
What is the difference between 04 and 39?
39 comes from OPEN, when fixed attributes such as record format or maximum length conflict and the file can't be used. 04 comes from a single READ, when one record's length is outside the FD's range.