CPF5006: Record not found
CPF5006 means a program asked the database for one particular record, by key or by relative record number, and the file member doesn't contain it. Most programs expect this and handle it, so it only stops a job when the program doesn't.
Other names for this code
Also written as CPF5006 record not found, MSGID CPF5006, record not found IBM i, CPF5006 CHAIN, AS400 record not found.
What it means
CPF5006 is one of the database I/O messages in the CPF5001 to CPF50FF range. IBM describes these as notify messages with a default reply of cancel. That means the program that did the I/O gets the first chance to handle the condition. If nothing handles it, the job is treated as if someone had replied cancel.
The condition itself is plain. A random read asked for a record that isn't there. The request can be by key, as with an RPG CHAIN or a COBOL READ with a KEY, or by relative record number. It also covers a record number that falls outside the member.
The high-level languages turn CPF5006 into their own status values. In ILE RPG a CHAIN, SETLL or SETGT that finds no record sets status 00012, which RPG counts as a normal code, not an error. The %FOUND built-in comes back off and the program carries on. Status 01241 is the error form, used when a record number from a record address file isn't in the file. In ILE COBOL, IBM maps CPF5006 to file status 23 (no record for a random access) and to file status 24 (a boundary problem on a relative or indexed file).
So when CPF5006 shows up in a job log or dump, it is often next to the program's own message. That message, and the key value the program used, tell you more than CPF5006 alone.
Common causes
- The key value the program built doesn't match any record. Leading zeros, trailing blanks, the wrong case or a packed field built from bad data all give a key that looks right on screen but isn't in the file.
- The record was deleted, or never added, for example because an earlier step that loads the file didn't run.
- The program reads through the wrong file or member. A library list, override or member parameter points it at a different copy of the data.
- The program reads by relative record number and the number is past the end of the member or points to a deleted record.
- The program reads through a logical file whose select and omit rules leave the record out, even though it is in the physical file.
How to find the problem
- Run DSPJOBLOG and read the messages around CPF5006. The language message after it (an RPG RNQ message or a COBOL runtime message) names the program and the statement.
- Find the key or record number the program used. A program dump (from the dump option on the RPG inquiry) or the debugger shows the key fields at the time of the read.
- Look up that key in the file yourself with SQL, for example
SELECT * FROM ACCTLIB.CUSTMAST WHERE CUSTNO = 104772, or with RUNQRY. - Check which file and member the job really opened. DSPLIBL, DSPOVR and the open files option of WRKJOB show this.
- If the read is through a logical file, run
DSPFD FILE(ACCTLIB/to see whether select and omit rules hide the record.CUSTL2) TYPE(*SELECT)
How to fix it
- In RPG, test %FOUND (or the not-found indicator) after every CHAIN and decide what the program should do when the record is missing.
- In COBOL, code an INVALID KEY phrase or check the file status after the READ, so status 23 is handled instead of ending the run.
- Clean up the key value before the read, for example with right-justification and zero fill for numeric keys held in character fields.
- If the data should be there, rerun the step that loads it, or add the missing record, then rerun the program.
- Fix the library list, override or member name if the program read the wrong copy of the file.
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(CPF5006) MSGF(QSYS/QCPFMSG)
Also inspect the full job log and second-level message text, including substitution values.
Related codes
Questions
Is CPF5006 always an error?
No. A lookup that finds nothing is often a normal result. RPG turns it into status 00012 and turns %FOUND off without stopping the program. It only becomes a failure when the program has no handling for it.
What is the difference between CPF5006 and CPF5001?
CPF5001 is end of file on a sequential read. CPF5006 is a random read by key or record number that found no record.
Why does the key look right but the read still fails?
Hidden differences are common. Trailing blanks, leading zeros, lower case letters or a numeric field held as text can make the key differ from the one stored in the file.