File status 23: Record not found
File status 23 means the record a keyed request asked for doesn't exist. A random READ, a START, or a random REWRITE or DELETE used a key or relative record number that isn't in the file.
Other names for this code
Also written as FS 23, file status code 23, COBOL status 23, VSAM status 23, record not found COBOL, status key 23, SK23.
What it means
Status 23 is an invalid key condition for indexed and relative files. A random READ, a START, or a REWRITE or DELETE in random access looked for a record by key or relative record number and found nothing. IBM also sets 23 when a START or random READ is issued against an OPTIONAL input file that wasn't present at OPEN.
For VSAM it usually comes from register 15 = 8 with feedback code 16 (X'10'), record not found. On a relative record data set, a relative record number VSAM can't accept comes back as feedback code 192 (X'C0'). QSAM and line-sequential files are only read in sequence, so they never return 23.
Not finding a record is often normal business logic, such as checking whether a customer exists before adding one. It becomes a problem when the program assumes the READ worked and goes on to use the record area, which still holds an old record or undefined data.
Common causes
- The record really isn't there. The key is new, was deleted, or belongs to a different file.
- The key field was built wrongly. Common slips are missing leading zeros, spaces where zeros belong, a packed value moved into a display key, or text in the wrong case.
- A START with KEY IS EQUAL TO a value that doesn't exist, where GREATER THAN or NOT LESS THAN was meant.
- The file is read through an alternate index that isn't in the upgrade set, so it lacks records added since it was last built with BLDINDEX.
- A relative key of zero, or one larger than any record written to the RRDS.
How to find the problem
- DISPLAY the key exactly as it was passed, in hex if you can. Hidden low-values or the sign half-byte of a numeric key are common culprits.
- Check whether the record exists with a file browse tool, or an IDCAMS PRINT with FROMKEY and TOKEY around the key.
- Display data-name-8. Return code 8 with feedback 16 means VSAM searched and found nothing. Feedback 192 on an RRDS means the relative record number itself was invalid.
- For an alternate index path, check LISTCAT ALL of the alternate index for UPGRADE, and find out when it was last rebuilt.
How to fix it
- Handle 23 as an expected result wherever a missing record is possible. Code INVALID KEY, or test the status before using the record area.
- Build the key the same way the program that loaded the file did. Use the copybook's key field, not a redefinition of it.
- Rebuild an out-of-date alternate index with IDCAMS BLDINDEX, and define it with UPGRADE so it stays current.
- For START, use a relational operator that positions on the next key when an exact match isn't required.
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 23 and 10?
23 means a keyed lookup found no record. 10 means a sequential READ ran out of records at the end of the file.
Why do I get 23 when I can see the record in a browse?
The key you pass doesn't match the stored key byte for byte. Compare them in hex, looking at leading zeros, spaces, sign and case.
Does status 23 stop the program?
Only if you code none of FILE STATUS, INVALID KEY or an error declarative. With any of them the program gets control back and decides what to do.