File status 46: READ with no valid next record
File status 46 means a sequential READ was issued when there was no valid next record, because the previous READ hit end of file or failed, or a START failed. Usually the program read again after status 10.
Other names for this code
Also written as FS 46, file status code 46, COBOL status 46, VSAM status 46, read past end of file COBOL, status key 46, SK46.
What it means
Status 46 is a logic error. After a sequential READ returns end of file (10) or fails, the file has no valid position. Another sequential READ in that state gets 46. The same applies after an unsuccessful START, which leaves the file with no position to read from.
It applies to QSAM, VSAM and line-sequential files read in sequence, and to indexed and relative files read with READ NEXT. For VSAM files it replaced status 94 from the older CMPR2 behavior. For QSAM files the old code was 92.
Status 46 isn't an at-end condition, so the AT END phrase doesn't run for it. An error declarative does, if you have one. If the program carries on regardless, the record area holds undefined data, and whatever it writes next is based on the last record it really read, or on nothing.
Common causes
- The read loop doesn't stop on status 10. A common version reads at the bottom of the loop and tests the end flag at the top, and one path skips the test.
- AT END sets a flag, but the program issues another READ before testing it.
- A START failed with 23 and the program went straight into READ NEXT.
- Match or merge logic reads past the end of the shorter file.
How to find the problem
- Find the READ or START before the failing READ and check its status. It will be 10, an error status, or a failed START.
- Check the loop around the READ for paths that skip the end-of-file test.
- In match and merge programs, check how the end flag or high-values key is set when one file runs out.
How to fix it
- Stop reading as soon as you get 10. Set an end-of-file flag in AT END and test it before the next READ.
- Check the status of START before READ NEXT. On 23, position somewhere else or end the browse.
- To read a sequential file again from the beginning, CLOSE it and OPEN it again. For an indexed file, a new START also sets a fresh position.
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
What is the difference between file status 10 and 46?
10 is the normal end-of-file result. 46 is what you get if you READ again after the 10, or after a READ or START that failed.
Why didn't AT END run on the second READ?
Because 46 isn't an at-end condition. It's a logic error, so only an error declarative or your own status check will catch it.
How do I reread a file after end of file?
CLOSE it and OPEN it again. For an indexed or relative file you can also issue a new START.