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 REEL, UNIT, and NO REWIND phrases are not valid for VSAM files.

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-1REELUNITFORREMOVALWITH NO REWINDWITHNO REWINDLOCK
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
You can specify these phrases only for QSAM multivolume or single volume files. The terms REEL and UNIT are interchangeable.
WITH NO REWIND and FOR REMOVAL
These phrases apply only to QSAM tape files. If they are specified for storage devices to which they do not apply, the close operation is successful and a status key value is set to indicate the file was on a non-reel medium.

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.

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.