# 12.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 }
  io-unit
  Is an external unit specifier.
  p
  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' | Submits the file to the batch job queue, then retains it.
  'SUBMIT/DELETE' | Submits the file to the batch job queue, then deletes it.
  1 Unless OPEN(READONLY) is in effect. 2 Use only on sequential files.

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

  label
  Is the label of the branch target statement that receives control if an error occurs.
  i-var
  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 specifier 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.

Examples

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.

Consider the following statement:

      CLOSE (UNIT=1, STATUS='PRINT')

This statement closes the file on unit 1 and submits it for printing.

For More Information:

- On the UNIT control specifier, see Section 10.2.1.1.
- On the ERR control specifier, see Section 10.2.1.8.
- On the IOSTAT control specifier, see Section 10.2.1.7.
- On the READONLY specifier, see Section 12.6.24.

Previous Page Next Page Table of Contents