Enterprise COBOL for z/OS, V4.2, Language Reference

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.

Effect of CLOSE statement on file types

If the SELECT OPTIONAL clause is specified in the file-control entry for a file, and the file is not available at run time, standard end-of-file processing is not performed. For QSAM files, the file position indicator and current volume pointer are unchanged.

Files are divided into the following types:

Non-reel/unit
A file whose input or output medium is such that rewinding, reels, and units have no meaning. All VSAM files are non-reel/unit file types. QSAM files can be non-reel/unit file types.
Sequential single volume
A sequential file that is contained entirely on one volume. More than one file can be contained on this volume. All VSAM files are single volume. QSAM files can be single volume.
Sequential multivolume
A sequential file that is contained on more than one volume. QSAM files are the only files that can be multivolume. The concept of volume has no meaning for VSAM files.

The permissible combinations of CLOSE statement phrases are shown in the following tables:

The meaning of each key letter is shown in Table 4.

Table 1. Sequential files and CLOSE statement phrases
CLOSE statement phrases Non-reel/ unit Sequential single-volume Sequential multivolume
CLOSE C C, G A, C, G
CLOSE REEL/UNIT F F, G F, G
CLOSE REEL/UNIT WITH NO REWIND F B, F B, F
CLOSE REEL/UNIT FOR REMOVAL D D D
CLOSE WITH NO REWIND C, H B, C A, B, C
CLOSE WITH LOCK C, E C, E, G A, C, E, G

Table 2. Indexed and relative file types and CLOSE statement phrases
CLOSE statement phrases Action
CLOSE C
CLOSE WITH LOCK C,E

Table 3. Line-sequential file types and CLOSE statement phrases
CLOSE statement phrases Action
CLOSE C
CLOSE WITH LOCK C,E

Table 4. Meanings of key letters for sequential file types
Key Actions taken
 A Previous volumes unaffected

Input and input-output files: Standard volume-switch processing is performed for all previous volumes (except those controlled by a previous CLOSE REEL/UNIT statement). Any subsequent volumes are not processed.

Output files: Standard volume-switch processing is performed for all previous volumes (except those controlled by a previous CLOSE REEL/UNIT statement).

 B No rewinding of current reel: The current volume is left in its current position.
 C Close file

Input and input-output files: If the file is at its end, and label records are specified, the standard ending label procedure is performed. Standard system closing procedures are then performed.

If the file is at its end, and label records are not specified, label processing does not take place, but standard system closing procedures are performed.

If the file is not at its end, standard system closing procedures are performed, but there is no ending label processing.

Output files: If label records are specified, standard ending label procedures are performed. Standard system closing procedures are then performed.

If label records are not specified, ending label procedures are not performed, but standard system closing procedures are performed.

 D Volume removal: Treated as a comment.
 E File lock: The compiler ensures that this file cannot be opened again during this execution of the object program. If the file is a tape unit, it will be rewound and unloaded.
 F Close volume

Input and input-output files: If the current reel/unit is the last or only reel/unit for the file or if the reel is on a non-reel/unit medium, no volume switching is performed. If another reel/unit exists for the file, the following operations are performed: a volume switch, beginning volume label procedure, and the first record on the new volume is made available for reading. If no data records exist for the current volume, another volume switch occurs.

Output (reel/unit media) files: The following operations are performed: the ending volume label procedure, a volume switch, and the beginning volume label procedure. The next executed WRITE statement places the next logical record on the next direct access volume available. A close statement with the REEL phrase does not close the output file; only an end-of-volume condition occurs.

Output (non-reel/unit media) files: Execution of the CLOSE statement is considered successful. The file remains in the open mode and no action takes place except that the value of the I-O status associated with the file is updated.

 G Rewind: The current volume is positioned at its physical beginning.
 H Optional phrases ignored: The CLOSE statement is executed as if none of the optional phrases were present.


Rate this page

[ Index | Table of contents ]