Example: FILE STATUS and INVALID KEY
The following example shows how you can use the file status
code and the
INVALID KEY phrase to determine more
specifically why an input or output statement failed.
Assume that you have a file that contains main customer records and you need to update some of these records with information from a transaction update file. The program reads each transaction record, finds the corresponding record in the main file, and makes the necessary updates. The records in both files contain a field for a customer number, and each record in the main file has a unique customer number.
FILE-CONTROL entry for
the main file of customer records includes statements that define
indexed organization, random access,
the prime record key, and
the file status key.
. (read the update transaction record)
MOVE "TRUE" TO TRANSACTION-MATCH
MOVE UPDATE-CUSTOMER-NUMBER TO MAIN-CUSTOMER-NUMBER
READ MAIN-CUSTOMER-FILE INTO WS-CUSTOMER-RECORD
DISPLAY "MAIN CUSTOMER RECORD NOT FOUND"
DISPLAY "FILE STATUS CODE IS: " CUSTOMER-FILE-STATUS
MOVE "FALSE" TO TRANSACTION-MATCH