End-of-File processing
Whenever a CLIST performs I/O, include code that handles end-of-file conditions. In a CLIST, end-of-file causes an error condition (error code 400). To process this condition, provide an error routine before the code that performs the I/O.
An error routine is a block of code that gets control when an error occurs in a CLIST. The error routine can try to identify the error (such as error code 400) and take appropriate action. For a complete description of how to write an error routine, see Writing ATTN and ERROR routines.
The following error routine saves the value of &LASTCC, closes
and frees the open file, and branches to a statement that determines
whether end-of-file was reached.
SET RCODE=0 /* Initialize the return code variable to 0 */
SET EOF=OFF /* Set the end-of-file indicator off */
⋮
ERROR +
DO
SET RCODE = &LASTCC /* Save the value of &LASTCC */
IF &RCODE=400 THEN +
DO
CLOSFILE PAYCHEKS /* Close the open file
free f(paycheks) /* Free the open file
WRITE No record to update because end-of-file was reached.
SET EOF=ON
RETURN /* Branch to statement that tests for
END /* EOF (IF &EOF=ON THEN...)
ELSE EXIT /* For other errors, EXIT
END
allocate file(paycheks) da('d58tan.checks.data') shr reu /* Allocate
/* file */
/* and establish file name of paycheks */
OPENFILE PAYCHEKS UPDATE /* Open file for updating */
SET COUNTER=1 /* Initialize counter to 1 */
DO WHILE &COUNTER <= 4
GETFILE PAYCHEKS /* Skip records */
SET COUNTER= &COUNTER+1 /* Increase counter by 1 */
/* If EOF reached, end loop. Null else */
IF &EOF=ON THEN GOTO OUT
END
SET PAYCHEKS = 480BUZZBEE /* Set variable to new value */
PUTFILE PAYCHEKS /* Update fourth record */
CLOSFILE PAYCHEKS /* Close the file */
⋮
(rest of CLIST)
⋮
OUT: END