CLOSE

Statement: Disconnects a file from a unit.

Syntax

CLOSE ( [UNIT=]io-unit [, STATUS | DISPOSE | DISP = p] [, ERR=label] [, IOSTAT=i-var] )

io-unit
(Input) an external unit specifier.

p
(Input) a scalar default character expression indicating the status of the file after it is closed. It has one of the following values:

The default is 'DELETE' for scratch files and QuickWin applications. For all other files, the default is 'KEEP'.

Files opened without a filename are called "scratch" files. Scratch files are temporary and are always deleted upon normal program termination; specifying STATUS='KEEP' for scratch files causes a run-time error.

For QuickWin applications, STATUS='KEEP' causes the child window to remain on the screen even after the unit closes. The default status is 'DELETE', which removes the child window from the screen.

label
Is the label of the branch target statement that receives control if an error occurs.

i-var
(Output) 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

The CLOSE statement specifiers can appear in any order. An I/O unit must be specified, but the UNIT= keyword is optional if the unit specifier is the first item in the I/O control list.

The status specified in the CLOSE statement supersedes the status specified in the OPEN statement, except that a file opened as a scratch file cannot be saved, printed, or submitted, and a file opened for read-only access cannot be deleted.

If a CLOSE statement is specified for a unit that is not open, it has no effect.

You do not need to explicitly close open files. Normal program termination closes each file according to its default status. The CLOSE statement does not have to appear in the same program unit that opened the file.

Closing unit 0 automatically reconnects unit 0 to the keyboard and screen. Closing units 5 and 6 automatically reconnects those units to the keyboard or screen, respectively. Closing the asterisk (*) unit causes a compile-time error. In QuickWin, use CLOSE with unit 0, 5, or 6 to close the default window. If all of these units have been detached from the console (through an explicit OPEN), you must close one of these units beforehand to reestablish its connection with the console. You can then close the reconnect unit to close the default window.

If a parameter of the CLOSE statement is an expression that calls a function, that function must not cause an I/O operation or the EOF intrinsic function to be executed, because the results are unpredictable.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: Data Transfer I/O Statements, Branch Specifiers

Example

C    Close and discard file:
     CLOSE (7, STATUS = 'DELETE')

Consider the following statement:

  CLOSE (UNIT=J, STATUS='DELETE', ERR=99)

This statement closes the file connected to unit J and deletes it. If an error occurs, control is transferred to the statement labeled 99.