13.2 CLOSE Statement

The CLOSE statement disconnects a file from a unit. It takes the following form:

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

Is an external unit specifier.

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

'KEEP' or 'SAVE'   Retains the file after the unit closes. 
'DELETE'   Deletes the file after the unit closes.1 
'PRINT' 2  Submits the file to the line printer spooler, then retains it. 
'PRINT/DELETE' 2  Submits the file to the line printer spooler, then deletes it. 
'SUBMIT'   Forks a process to execute the file. 
'SUBMIT/DELETE'   Forks a process to execute the file, then deletes the file after the fork is completed. 

1 Unless OPEN(READONLY) is in effect.
2 Use only on sequential files.

The default is 'DELETE' for scratch files and QuickWin applications (WNT, W9*). For all other files, the default is 'KEEP'.

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

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.


Consider the following statement:


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

For More Information:

Previous Page Next Page Table of Contents