For sequential files, the ENDFILE statement writes an end-of-file record to the file and positions the file after this record (the terminal point). For direct access files, the ENDFILE statement truncates the file after the current record.
An ENDFILE statement takes one of the following forms:
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 performed on a direct access file always truncates the file.
An ENDFILE statement must not be issued for a file that is open for 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:
ENDFILE (UNIT=9, IOSTAT=IOS, ERR=10)
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: