CPF0864: End of file detected
CPF0864 means a CL program's RCVF command reached the end of the database file, so there are no more records to read. The text reads "End of file detected for file <file> in <library>." It's expected in a read loop and should be handled with MONMSG.
Other names for this code
Also written as MSGCPF0864, CPF0864 end of file detected, end of file detected for file, RCVF CPF0864, MONMSG CPF0864, iSeries CPF0864.
What it means
CL reads database files with DCLF and RCVF. DCLF declares the file and gives the program a CL variable for each field. Each RCVF reads the next record into those variables. When there are no more records, RCVF ends with the escape message CPF0864.
In a read loop that's the normal way to finish. IBM's own RCVF example monitors for CPF0864 and branches to an end label. If the program doesn't monitor for it, CPF0864 is unhandled. The program then gets a function check (CPF9999), and the job usually stops with an inquiry message such as CPA0701 asking whether to cancel.
When RCVF hits end of file, the file is closed. Another RCVF against the same file after that fails. To read the file again in the same program, close it first with the CLOSE command, available from IBM i 6.1, and then RCVF opens it again from the start.
Common causes
- The read loop reached the last record, which is normal.
- The program has no
MONMSG MSGID(CPF0864)after RCVF, so normal end of file becomes an error. - The file or member was empty, for example because an earlier step that builds it with DSPFD, DSPOBJD or a query wrote no records.
- An override (OVRDBF) points the program at a different member than expected, and that member is empty.
- The program reads the file a second time without closing it first.
How to find the problem
- Run
DSPJOBLOGand find CPF0864. Its text names the file and library. A CPF9999 or CPA0701 right after it means nothing handled it. - Look at the CL source for the RCVF that reads that file, and check for a MONMSG straight after it.
- Check how many records the file has with
DSPFD FILE(lib/file) TYPE(*MBR)orDSPPFM. Zero records means CPF0864 on the first read. - Check for overrides with
DSPOVRwhile the program runs, or look for OVRDBF in the calling program.
How to fix it
- Add a monitor right after the RCVF, as in
RCVFthenMONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF)), or leave a DOWHILE loop with LEAVE. - If an empty file is possible, decide what the program should do in that case and handle it on the first read.
- To read the file again, issue
CLOSEbefore the next RCVF. - Check that any OVRDBF selects the member you expect.
IBM documentation
IBM Display Message Descriptions (DSPMSGD). 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.
Read the installed message description:
DSPMSGD MSGID(CPF0864) MSGF(QSYS/QCPFMSG)
Also inspect the full job log and second-level message text, including substitution values.
Related codes
Questions
Is CPF0864 an error?
It's an escape message, but in a read loop it's the normal sign that all records have been read. It only becomes a problem when the program doesn't monitor for it.
Why does my program fail on the first RCVF with CPF0864?
The file or member is empty, or an override points the program at an empty member.
How do I read the same file twice in one CL program?
Close the file with the CLOSE command after the first pass. The next RCVF opens it again and starts at the first record.