Wednesday, February 17, 2010

10. Trapping Runtime errors

The FILE clause
The clause can be used with the SELECT statement to determine the exact type of input or output error that has occurred when either reading from or writing to a file. The SELECT statement could include FILE STATUS as its last clause. The data name specified with the FILE STATUS clause must appear in the WORKING-STORAGE as a two-position alphanumeric field.

Eg 10.1:
SELECT EMPLOYEE-FILE
ASSIGN TO “EMP.DAT”
ORGANIZATION IS LINE SEQUENTIAL
FILE STATUS IS WS-STATUS.
:
WORKING-STORAGE SECTION.
01 WS-STATUS PIC X(2).

The possible values that may be placed in the FILE STATUS field when an input or output operation is performed are listed in Appendix – E.

OPEN INPUT EMPLOYEE-FILE.
IF WS-STATUS NOT = “00”
DISPLAY “ERROR OPENING EMPLOYEE FILE”
STOP RUN.
READ EMPLOYEE-FILE ….
:
:

Back to COBOL Index

No comments: