What is File Status?

File status is a two-byte code that indicates how a file operation completed; either successfully, or with some form of error. If an error occurs, file status indicates the cause of the error.

If you have a file status data item defined for a file, after every input/output operation on the file (OPEN, CLOSE, READ, WRITE, REWRITE, START and DELETE) the run-time system updates it to indicate how the operation completed.

Defining a file status data item is optional. If a file status data item is not declared and a serious file error occurs, the COBOL run-time system displays an error message and aborts your program.

You should check the file status data item after each input/output operation, to see if the operation completed successfully. For example, when your program is writing to disk, there might not be enough disk space to complete the WRITE operation. If you have not defined a file status data item and you run out of disk space, the run-time system displays an error number and aborts the program. If you have a file status data item defined (for the file you are writing), it is updated and the program continues to run. The program can then check the file status data item, determine from it that the disk is full and take the appropriate action.