CLOSE statement

The CLOSE statement terminates the processing of volumes and files.

Format 1: CLOSE statement for sequential files

Read syntax diagramSkip visual syntax diagramCLOSEfile-name-1REEL1UNIT1FORREMOVALWITH NO REWINDWITHNO REWIND1LOCK
Notes:
  • 1 The UNIT, REEL, and NO REWIND phrases are treated as a comment, although the file status will be set to 07, indicating a successful completion of a CLOSE for a non-reel/unit medium.

Format 2: CLOSE statement for indexed and relative files

Read syntax diagramSkip visual syntax diagramCLOSEfile-name-1WITHLOCK

Format 3: CLOSE statement for line-sequential files

Read syntax diagramSkip visual syntax diagramCLOSEfile-name-1REEL1UNIT1FORREMOVALWITH NO REWINDWITHNO REWIND1LOCK
Notes:
  • 1 The UNIT, REEL, and NO REWIND phrases are treated as a comment, although the file status will be set to 07, indicating a successful completion of a CLOSE for a non-reel/unit medium.
file-name-1
Designates the file upon which the CLOSE statement is to operate. If more than one file-name is specified, the files need not have the same organization or access. file-name-1 must not be a sort or merge file.
REEL and UNIT
REEL and UNIT are syntax checked, but have no effect on the execution of the program.
WITH NO REWIND and FOR REMOVAL
WITH NO REWIND and FOR REMOVAL are syntax checked, but have no effect on the execution of the program.

A CLOSE statement can be executed only for a file in an open mode. After successful execution of a CLOSE statement (without the REEL/UNIT phrase if using format 1):

  • The record area associated with the file-name is no longer available. Unsuccessful execution of a CLOSE statement leaves availability of the record data undefined.
  • An OPEN statement for the file must be executed before any other input/output statement can be executed for the file and before data is moved to a record description entry associated with the file.
  • Any record locks and file locks held by the file connector on the closed file are released.

If the FILE STATUS clause is specified in the file-control entry, the associated file status key is updated when the CLOSE statement is executed.

If the file is in an open status and the execution of a CLOSE statement is unsuccessful, the EXCEPTION/ERROR procedure (if specified) for this file is executed.