Handling Input/Output Exception Conditions

7.2 Planning for the Invalid Key Condition

in the file, or when you receive the AT END condition for a subsequent read
operation, indicating that no more records exist in the file.
Example 72 Handling the Invalid Key Condition
.
.
.
MOVE "SMITH" TO LAST-NAME TEST-LAST-NAME.
MOVE "Y" TO ANY-MORE-DUPLICATES.
PERFORM A500-READ-DUPLICATES
UNTIL ANY-MORE-DUPLICATES = "N".
.
.
.
STOP RUN.
A500-READ-DUPLICATES.
READ INDEXED-FILE RECORD INTO HOLD-RECORD
KEY IS LAST-NAME
INVALID KEY
MOVE "N" TO ANY-MORE-DUPLICATES
DISPLAY "Name not in file!"
NOT INVALID KEY
PERFORM A510-READ-NEXT-DUPLICATES
UNTIL ANY-MORE-DUPLICATES = "N"
END-READ.
A510-READ-NEXT-DUPLICATES.
READ INDEXED-FILE NEXT RECORD
AT END MOVE "N" TO ANY-MORE-DUPLICATES
NOT AT END
PERFORM A520-VALIDATE
END-READ.
IF ANY-MORE-DUPLICATES = "Y" PERFORM A700-PRINT.
A520-VALIDATE.
IF LAST-NAME NOT EQUAL TEST-LAST-NAME
MOVE "N" TO ANY-MORE-DUPLICATES.
END READ.
A700-PRINT.
.
.
.
7.3 Using File Status Values and OpenVMS RMS Completion Codes
Yourprogram can check for the specific cause of the failure of a file operation
by checking for specific file status values in its exception handling routines. To
obtain Compaq COBOL file status values, use the FILE STATUSclause in the
file description entry.
On OpenVMS, to access RMS completion codes, use the Compaq COBOL special
registers RMS-STS and RMS-STV,or RMS-CURRENT-STS and RMS-CURRENT-
STV.
Handling Input/Output Exception Conditions 73