COBOL file status

File status 10: End of file

File status 10 means a sequential READ found no next record, so the program has reached the end of the file. The AT END phrase runs if one is coded.

Other names for this code

Also written as FS 10, file status code 10, COBOL status 10, AT END condition, end of file COBOL, status key 10, SK10.

What it means

Status 10 is the at-end condition. It's set on a sequential READ, or a READ NEXT on an indexed or relative file, when there are no more records to return. It also comes back on the first READ of an OPTIONAL input file that wasn't present at OPEN.

It is a normal result. Most batch programs read until they see 10 and then finish. The status is set before the AT END phrase or an error declarative runs, so both can rely on it. After a 10 the record area holds undefined data, so don't use it. If you need the last record later, keep a copy in WORKING-STORAGE or use READ INTO, which only moves data on a successful READ.

It looks the same for QSAM, VSAM and line-sequential files. For QSAM the end of data is found by the access method's end-of-data routine. For VSAM it comes from a GET that ended with register 15 = 8 and feedback code 4 (X'04'), end of data, so the VSAM return code area (data-name-8) is filled in. If the program issues another READ after a 10, it doesn't get a second 10. It gets status 46, a logic error.

Common causes

  • The program has read every record. This is the expected case.
  • The input is empty, so the first READ gets 10. That often points to an upstream step that wrote nothing, or a DD that names the wrong generation of a GDG.
  • An OPTIONAL input file was missing at OPEN (status 05), so the first READ returns end of file.
  • A START or random READ positioned the file near its end, and the following READ NEXT ran past the last record.

How to find the problem

  1. DISPLAY a record count when the program ends. If the count is zero, the 10 came on the first READ and the problem is the input, not the program.
  2. Check the step that created the file. Look at its record counts in SYSOUT, and compare the data set name or GDG generation on its output DD with the input DD of the failing step.
  3. For QSAM, browse the data set in ISPF. For VSAM, IDCAMS LISTCAT ALL shows REC-TOTAL, and 0 means the cluster is empty.
  4. If status 46 appears later in the run, look for a READ issued after the 10 without a check.

How to fix it

  • Handle end of file explicitly. Use AT END, or test for 10 after every READ, and leave the read loop.
  • Don't use the record area after a 10. Save the last good record in WORKING-STORAGE if you need it.
  • If an empty input means something went wrong upstream, check the count after the first READ and end the step with a nonzero return code so the scheduler notices.
  • Fix the JCL if the DD points at the wrong data set or generation.

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.

Report a correction to WND Software.

Questions

Is file status 10 an error?

No. It's the normal end-of-file signal. Your read loop should expect it.

Why do I get 10 on the very first READ?

The file is empty, or it's an OPTIONAL file that wasn't there at OPEN. Check the step that should have created it and the data set name on the DD.

What happens if I READ again after status 10?

The second READ fails with status 46, which is a logic error rather than another end-of-file signal.