The CLOSE Statement

The CLOSE statement terminates the processing of reels/units and files, with optional rewind, lock or removal where applicable.

General Formats for Format 1 (Record Sequential Files)


*

General Formats for Format 2 ( MF Line Sequential, Relative and Indexed Files)


*

Syntax Rules for All Formats (All Files)

  1. The files referenced in the CLOSE statement need not all have the same organization or access.

Syntax Rules for Format 1 (Record Sequential Files)

  1. MF The REEL and UNIT phrases should be specified only for files which have had MULTIPLE REEL or MULTIPLE UNIT specified in their SELECT clause. If your run-time system does not recognize multi-unit files, the statements CLOSE REEL and CLOSE UNIT are "null" statements; that is, they are documentary only. It is important that no other files are open on the device(s) closed by a CLOSE REEL or CLOSE UNIT statement.

    OSVS The statements CLOSE REEL WITH LOCK and CLOSE UNIT WITH LOCK are treated as equivalent to CLOSE REEL FOR REMOVAL.

  2. OSVS The DISP option is applicable only to tape files.

    It is documentary only.

General Rules for All Formats (All Files)

  1. A CLOSE statement can be executed only for a file in an open mode.
  2. Following the successful execution of a CLOSE statement the record area associated with file-name-1 is no longer available. The unsuccessful execution of such a CLOSE statement leaves the availability of the record area undefined.
  3. ANS85 If a file is in the open mode when a STOP RUN statement is executed, the fileis closed. If a file has been opened in a called program and not closed in that program prior to the execution of a CANCEL statement for the program, that file is closed.
  4. MF Following the successful execution of a CLOSE statement, all record or file locks held by the run unit on the closed file are released.
  5. The execution of the CLOSE statement causes the value of the I/O status associated with file-name-1 to be updated. (See the topic I-O Status in the chapter Procedure Division.)
  6. The results of executing each type of CLOSE statement for each category of file are summarized in the table below.
    Table 1. Relationship of Categories of Files and the Formats of the CLOSE Statement
    CLOSE Statement Format File Category
    Non-Reel/Unit Record Sequential Single-Reel/Unit Record Sequential Multi-Reel/Unit Non-record Sequential Single/ Multi-Reel/Unit
    CLOSE C C, G A, C, G C
    CLOSE WITH LOCK C, E C, E, G A, C, E, G C, E
    CLOSE WITH NO REWIND record sequential only ANS85 C, H B, C A, B, C X
    CLOSE REEL/UNIT record sequential only ANS85 F ANS85 F, G F, G X
    CLOSE REEL/UNIT FOR REMOVAL record sequential only ANS85 F ANS85 D, F, G D, F , G X
    CLOSE REEL/UNIT WITH NO REWIND record sequential only X X F, B X

    The definitions of the symbols in the table are given below. Where the definition depends on whether the file is an input, output or input-output file, alternate definitions are given; otherwise, a definition applies to input, output, and input-output files.

    A. Previous Reels/Units Unaffected
     
    • Input Files and Input-output Files:

      All reels/units in the file prior to the current reel/unit are processed except those reels/units controlled by a prior CLOSE REEL/UNIT statement. If the current reel/unit is not the last in the file, the reels/units in the file following the current one are not processed.

    • Output Files:

      All reels/units in the file prior to the current reel/unit are processed except those reels/units controlled by a prior CLOSE REEL/UNIT statement.