The CLOSE statement disconnects an external file from a unit.
The default is DELETE if the file status is SCRATCH; otherwise, the default is KEEP.
A CLOSE statement that refers to a unit can occur in any program unit of an executable program and need not occur in the same scoping unit as the OPEN statement referring to that unit. You can specify a unit that does not exist or has no file connected; the CLOSE statement has no effect in this case.
Unit 0 cannot be closed.
When an executable program stops for reasons other than an error condition, all units that are connected are closed. Each unit is closed with the status KEEP unless the file status prior to completion was SCRATCH, in which case the unit is closed with the status DELETE. The effect is as though a CLOSE statement without a STATUS= specifier were executed on each connected unit.
If a preconnected unit is disconnected by a CLOSE statement, the rules of implicit opening apply if the unit is later specified in a WRITE statement (without having been explicitly opened).
CLOSE(15) CLOSE(UNIT=16,STATUS='DELETE')