7.1.1.10 Transfer-of-Control Specifiers

The transfer-of-control specifier identifies an executable statement and transfers control to that statement if an end-of-file or error condition occurs. It takes either one of the following forms:

{ END=s }
{ ERR=s }
s
Is the label of the executable statement that receives control.

A sequential READ statement can include either or both of the previous specifications, in any order. The following statements can only include the ERR=s specification:

The statement label in the END=s or ERR=s specification must refer to an executable statement within the same program unit as that of the I/O statement.

An end-of-file condition occurs when no more records exist in a file during a sequential read, or when an end-of-file record produced by the ENDFILE statement is encountered. End-of-file conditions do not occur in direct access or indexed (keyed access) READ statements.

If a READ statement encounters an end-of-file condition during an I/O operation, it transfers control to the statement designated by the END=s specification. If there is no END=s specification, control transfers to the statement designated by the ERR=s specification. If neither specification (nor an IOSTAT specifier) exists, the program terminates.

If a READ, WRITE, or REWRITE statement encounters an error condition during an I/O operation, it transfers control to the statement whose label appears in the ERR=s specification. If neither an ERR specifier nor an IOSTAT specifier exists, the I/O error terminates program execution.

For information on the type of I/O error that occurs, use the IOSTAT specifier.

Examples

The following READ statement transfers control to statement 550 if an end-of-file condition occurs on logical unit 8.

READ (8,END=550) (MATRIX(K),K=1,100)

The following WRITE statement transfers control to statement 390 if an error occurs while it is being executed.

WRITE (6,50,ERR=390) VAR1, VAR2, VAR3

The following READ statement transfers control to statement 150 (if an error occurs while it is being executed) or to statement 200 (if an end-of-file condition occurs).

READ (1,FORM,ERR=150,END=200) ARRAY

For More Information:


Previous Page Next Page Table of Contents