FILE STATUS
A two-character code that COBOL sets after every file operation, telling the program whether it worked and, if not, why.
Also written FILE STATUS IS, file status code, file status 35, file status 39
FILE STATUS is how a COBOL program finds out whether a file operation worked. You name a two-character field in the SELECT statement, with FILE STATUS IS WS-STATUS, and COBOL fills it in after every OPEN, READ, WRITE, REWRITE, DELETE and CLOSE.
The codes follow a pattern. A first character of 0 means success: 00 is a clean result, and 02 or 04 mean it worked with a note. 10 means end of file. 2x codes are key problems in indexed files: 22 is a duplicate key and 23 is a record not found. 3x codes are permanent errors, often at OPEN: 35 means the file was not there, usually because a DD statement is missing or wrong, and 39 means the file's attributes, such as record length, do not match the program.
A well-written program checks the status after every operation and stops cleanly with a clear message when something is wrong. A program that does not check may carry on with bad data, or end with an abend that is harder to explain.
When a status is not 00, look it up first. It usually points to the DD statement or the record that caused the problem.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- File descriptionThe FD entry in a COBOL program that describes a file's records, connecting the program to data supplied by the JCL.
- KSDSThe most common VSAM dataset type, where every record has a unique key used to find it directly.
- VSAMA family of dataset types built for fast record access by key, used where applications need to look records up rather than read them in order.
- DD statementThe JCL statement that connects a name inside a program to a real dataset outside it.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.
- PROCEDURE DIVISIONThe part of a COBOL program that contains the actual logic, the statements that run.