Purpose
The ENDFILE statement writes an endfile record as the next
record of an external file connected for sequential access. This record
becomes the last record in the file.
An ENDFILE statement for a file connected for stream access
causes the terminal point to become the current file position. File
storage units before the current position are considered written, and can be
read. You can write additional data to the file by using subsequent
stream output statements.
Syntax
>>-ENDFILE--+-u-------------------+----------------------------><
'-(--position_list--)-'
|
- u
- is an external unit identifier. The value of u must not be
an asterisk or a Hollerith constant.
- position_list
- is a list that must contain one unit specifier
([UNIT=]u) and can also contain one of each of the
other valid specifiers:
- [UNIT=] u
- is a unit specifier in which u must be an external unit
identifier whose value is not an asterisk. An external unit identifier
refers to an external file that is represented by a scalar integer expression,
whose value is in the range 1 through 2147483647. If the optional
characters UNIT= are omitted, u must be the first item in
position_list.
- IOMSG= iomsg_variable
- is an input/output status specifier that specifies the message returned by
the input/output operation. iomsg_variable is a scalar default
character variable. It must not be a use-associated nonpointer
protected variable. When the input/output statement containing this
specifier finishes execution, iomsg_variable is defined as
follows:
- If an error, end-of-file, or end-of-record condition occurs, the variable
is assigned an explanatory message as if by assignment.
- If no such condition occurs, the value of the variable is
unchanged.
- IOSTAT= ios
- is an input/output status specifier that specifies the status of the
input/output operation. ios is a scalar variable of type
INTEGER(4) or default integer. When the ENDFILE
statement finishes executing, ios is defined with:
- A zero value if no error condition occurs
- A positive value if an error occurs.
- ERR= stmt_label
- is an error specifier that specifies the statement label of an executable
statement in the same scoping unit to which control is to transfer in the case
of an error. Coding the ERR= specifier suppresses error
messages.
Rules
+-------------------------------IBM Extension--------------------------------+
If the unit is not connected, an implicit OPEN specifying
sequential access is performed to a default file named
fort.n, where n is the value of u
with leading zeros removed.
If two ENDFILE statements are executed for the same file
without an intervening REWIND or BACKSPACE statement, the
second ENDFILE statement is ignored.
+----------------------------End of IBM Extension----------------------------+
After execution of an ENDFILE statement for a file
connected for sequential access, a BACKSPACE or REWIND
statement must be used to reposition the file prior to execution of any data
transfer input/output statement.
If the ERR= and IOSTAT= specifiers are set and an error
is encountered, transfer is made to the statement specified by the
ERR= specifier and a positive integer value is assigned to
ios.
+-------------------------------IBM Extension--------------------------------+
If IOSTAT= and ERR= are not
specified,
- The program stops if a severe error is encountered.
- The program continues to the next statement if a recoverable error is
encountered and the ERR_RECOVERY run-time option is set to
YES. If the option is set to NO, the program
stops.
+----------------------------End of IBM Extension----------------------------+
Examples
ENDFILE 12
ENDFILE (IOSTAT=IOSS,UNIT=11)
Related Information
