CLOSE statement

The CLOSE statement terminates the processing of volumes and files.

Read syntax diagramSkip visual syntax diagram
Format 1: CLOSE statement for sequential files

>>-CLOSE-------------------------------------------------------->

   .-----------------------------------------------------.   
   V                                                     |   
>----file-name-1--+------------------------------------+-+-----><
                  |        (1)                         |     
                  +-+-REEL-----+--+------------------+-+     
                  | |      (1) |  +-+-----+--REMOVAL-+ |     
                  | '-UNIT-----'  | '-FOR-'          | |     
                  |               '-WITH NO REWIND---' |     
                  |                       (1)          |     
                  '-+------+--+-NO REWIND-----+--------'     
                    '-WITH-'  '-LOCK----------'              

Notes:
  1. The REEL, UNIT, and NO REWIND phrases are not valid for VSAM files.
Read syntax diagramSkip visual syntax diagram
Format 2: CLOSE statement for indexed and relative files

          .---------------------------------.   
          V                                 |   
>>-CLOSE----file-name-1--+----------------+-+------------------><
                         '-+------+--LOCK-'     
                           '-WITH-'             

Read syntax diagramSkip visual syntax diagram
Format 3: CLOSE statement for line-sequential files

          .-------------------------------------------------.   
          V                                                 |   
>>-CLOSE----file-name-1--+--------------------------------+-+--><
                         +-+-REEL-+--+------------------+-+     
                         | '-UNIT-'  +-+-----+--REMOVAL-+ |     
                         |           | '-FOR-'          | |     
                         |           '-WITH NO REWIND---' |     
                         '-+------+--+-NO REWIND-+--------'     
                           '-WITH-'  '-LOCK------'              

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):

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.