Rational Developer for System z
COBOL for Windows, Version 7.5, Language Reference


CLOSE statement

The CLOSE statement terminates the processing of volumes and files.

Format 1: sequential
Read syntax diagramSkip visual syntax diagram>>-CLOSE-------------------------------------------------------->
 
   .------------------------------------------------------.  
   V                                                      |  
>----file-name-1--+-------------------------------------+-+----><
                  |        (1)                          |    
                  +-+-REEL------+--+------------------+-+    
                  | |      (1)  |  +-+-----+--REMOVAL-+ |    
                  | '-UNIT------'  | '-FOR-'          | |    
                  |                '-WITH NO REWIND---' |    
                  |                       (1)           |    
                  '-+------+--+-NO REWIND------+--------'    
                    '-WITH-'  '-LOCK-----------'             
 

Notes:
  1. The UNIT, REEL, and NO REWIND phases 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: indexed and relative files
Read syntax diagramSkip visual syntax diagram          .---------------------------------.  
          V                                 |  
>>-CLOSE----file-name-1--+----------------+-+------------------><
                         '-+------+--LOCK-'    
                           '-WITH-'            
 

Format 3: line-sequential files
Read syntax diagramSkip visual syntax diagram>>-CLOSE-------------------------------------------------------->
 
   .------------------------------------------------------.  
   V                                                      |  
>----file-name-1--+-------------------------------------+-+----><
                  |        (1)                          |    
                  +-+-REEL------+--+------------------+-+    
                  | |      (1)  |  +-+-----+--REMOVAL-+ |    
                  | '-UNIT------'  | '-FOR-'          | |    
                  |                '-WITH NO REWIND---' |    
                  |                       (1)           |    
                  '-+------+--+-NO REWIND------+--------'    
                    '-WITH-'  '-LOCK-----------'             
 

Notes:
  1. The UNIT, REEL, and NO REWIND phases 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):

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 present at run time, standard end-of-file processing is not performed.

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 Btrieve, RSD, and STL files are 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 Btrieve, RSD, and STL files are single volume.
Sequential multivolume
A sequential file that is contained on more than one volume. The concept of volume has no meaning for Btrieve, RSD, or STL files.

The permissible combinations of CLOSE statement phrases are shown in:

The meaning of each key letter is shown in Meanings of key letters for sequential file types (Table 40).

Table 37. 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 WITH LOCK C, E C, E, G A, C, E, G

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

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

Table 40. 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).

 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.

 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.
 G Rewind: The current volume is positioned at its physical beginning.

Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)