Professional Documents
Culture Documents
Note: If you declare a USE procedure (in the Declarative section of your program) to handle I/O errors, the procedure is only executed if a file status is also defined for the file. The file status item is updated before the USE procedure is executed. See the Language Reference for more information about Declaratives and USE procedures.
Value 0 1 2 3 4 9
Condition Successful operation AT END Invalid Key Permanent Error Logic Error (improper sequence of I/O operations) COBOL run-time system error message
If the first byte of the file status data item is other than 9, the second byte (known as status key 2) should be treated as alphanumeric. The values and meanings of status key 2 are listed in the chapter File Status Code Tables. If the first byte of the file status data item is "9", the second byte is a binary field containing a Micro Focus defined RTS error code. These messages are listed and explained in your Error Messages. Example select in-file assign to.... . . . file status is ws-file-status. data division. file section. fd in-file.... . . . working-storage section. 01 ws-file-status pic xx.
000150 03 stat-bin redefines s2 pic 9(2) comp-x. 000160 01 disply-stat. 000170 03 s1-displ pic x. 000180 03 filler pic x(3). 000190 03 s2-displpic pic zz9. 000200 procedure division. 000210 start-test. 000220 open input file1 000230 move s1 to s1-displ 000240 if s1 not= 9 000250 move s2 to s2-displpic 000260 else 000270 move stat-bin to s2-displpic 000280 end-if 000290 display disply-stat 000300 stop run. If you have not specified a file status item in the SELECT clause of your program, file errors with a first byte value of 9 result in display of a run-time error.
when "4" display "logic error" when "9" display "run-time-system error" perform check-mf-error-message end-evaluate. check-eof-status. if status-key-2 = "0" display "no next logical record" end-if. check-inv-key-status. evaluate status-key-2 when "2" display "attempt to write dup key" when "3" display "no record found" end-evaluate. check-perm-err-status. if status-key-2 = "5" display "file not found" end-if. check-mf-error-message. evaluate binary-status when 002 display "file not open" when 007 display "disk space exhausted" when 013 display "file not found" when 024 display "disk error " when 065 display "file locked " when 068 display "record locked " when 039 display "record inconsistent" when 146 display "no current record " when 180 display "file malformed " when 208 display "network error " when 213 display "too many locks " when other display "not error status " display binary-status end-evaluate. In the paragraph check-status, the value of status-key-1 is evaluated in order to determine whether status-key-2 should also be interrogated. Common run-time system errors are listed in the EVALUATE statement in the paragraph check-mferror-message. Of course, in your own program, you need to process these errors, not simply display them.