12.4 ENDFILE Statement

The ENDFILE statement writes an end-of-file record to a sequential file and positions the file after this record (the terminal point).

An ENDFILE statement takes one of the following forms:

 ENDFILE ([UNIT=]io-unit [,ERR=label] [,IOSTAT=i-var])
 ENDFILE io-unit
Is an external unit specifier.
Is the label of the branch target statement that receives control if an error occurs.
Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.

Rules and Behavior

If the unit specified in the ENDFILE statement is not open, the default file is opened for unformatted output.

An end-of-file record can be written only to files with sequential organization that are accessed as formatted-sequential or unformatted-segmented sequential files.

An ENDFILE statement must not be issued for a file that is open for direct or keyed access.

An end-of-file record written to a file on magnetic tape is not the same as a tape mark.

End-of-file records should not be written in files that are read by programs written in a language other than Fortran, because other languages do not support the embedded end-of-file concept.


The following statement writes an end-of-file record to I/O unit 2:


Suppose the following statement is specified:


An end-of-file record is written to the file connected to unit 9. If an error occurs, control is transferred to the statement labeled 10, and a positive integer is stored in variable IOS.

For More Information:

Previous Page Next Page Table of Contents