HP 3000 Manuals

CLOSE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

CLOSE Statement 

The CLOSE statement terminates the processing of sequential, random,
relative, and indexed files.  It can only be executed for an open file.

Syntax 

The CLOSE statement has two formats, depending upon whether you want to
close a sequential file or one of the other three types of files.

Sequential Files - Format 1 

[]
Description. Rules that apply to a CLOSE statement for any type of file are described below.[REV BEG] For information on handling I/O errors, see "Input-Output Error Handling Procedures" .[REV END] A CLOSE statement can only be issued for a file that is open, and has not yet been closed. If a CLOSE statement has been successfully executed for a file, no other statement can be executed that references the closed file, either explicitly or implicitly, unless an intervening OPEN statement for that file is executed. There is one exception to this rule. A sequential file that has been closed may be referred to in SORT and MERGE statements that use the USING or GIVING phrases. In this case, the file or files named in the USING and GIVING phrases must not be open. Following the successful execution of the CLOSE statement (without the REEL or UNIT phrases in the case of sequential files), the record area associated with the name of the closed file is no longer available. If a CLOSE statement is unsuccessful in its execution, the availability of the record area for the specified file is undefined. If a CLOSE statement has not been issued for an open file when a STOP RUN statement (or a GOBACK statement in a main program) is executed, the file is automatically closed by the COBOL run-time system. If a called program has been canceled by the CANCEL statement, all open files of that program will be closed. If the file being closed is a new file or a temporary file, it is closed in the temporary file domain. If it is a permanent file, it remains in the permanent file domain when it is closed. The FILE STATUS data item, if any, specified for the file named in the CLOSE statement is updated to indicate the success or failure of the closing operation. Refer to "FILE STATUS Clause" in Chapter 6 for valid status keys. Using a format 1 CLOSE statement, as shown above, allows you to terminate the processing of files whose organization is sequential. It also provides you with the options of placing the serial access device at its physical beginning and of locking the file so that it cannot be opened again during the execution of the current run-unit. REEL/UNIT and REMOVAL Phrases. The REEL/UNIT phrase and the REMOVAL phrase are treated as comments in format 1 of the CLOSE statement. Furthermore, if the REEL/UNIT phrase is specified in a format 1 CLOSE statement, the entire CLOSE statement is treated as a comment. Thus, the file specified in the CLOSE REEL/UNIT statement remains open. Each of the remaining optional phrases are described below. If no optional phrases are used, that is, if the format 1 CLOSE statement consists entirely of the statement, CLOSE file-name-1 then the system's closing operations are executed, no matter what kind of operations (input, input-output, output or extend) the file was opened for. If the file resides on a magnetic tape, the reel is rewound when the file is closed. NO REWIND Phrase. The NO REWIND phrase applies only to labeled magnetic tape files. Used without either a REEL or UNIT phrase, the NO REWIND phrase alters the execution of the system's standard closing procedure. The tape device, instead of being rewound when the file is closed, remains in its current position. This phrase should be used in the closing of a file only if another file residing near the end of the same tape is to be opened later in the program. Upon completion of the program, the tape is rewound by the operating system. If the file resides on a device that allows no rewinding, such as a line printer, the NO REWIND phrase is ignored when specified for that file in a CLOSE statement; it has no effect on the file. WITH LOCK Phrase. The WITH LOCK phrase can be used in the CLOSE statement to ensure that the file being closed cannot be opened again during the execution of the current run-unit. This locking is accomplished by the program, following the successful closing of the file. Random, Relative and Indexed Files - Format 2 The second format of the CLOSE statement is: CLOSE {file-name-1 [WITH LOCK] }... This form of CLOSE closes the files named by file-name-1, and so forth, and optionally locks the files so that they cannot be opened again during execution of the current run-unit. The files named by file-name-1, and so forth need not all have the same organization or access. When a CLOSE statement without the LOCK phrase is issued for a relative, random, or indexed file, the MPE file system closing procedures are used to close the file or files specified, no matter how the files are used (that is, input, input-output, or output). Additionally, if the LOCK phrase is used with a relative, random access, or indexed file, the compiler ensures that the file cannot be opened again during execution of the current run-unit. Example : ENVIRONMENT DIVISION. : INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INDEXER ASSIGN TO "FILE-INDX, DA, A, DISC" ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS INDX-FOR-FL. SELECT RNDM-FL ASSIGN TO "RANDOM" ACCESS MODE IS RANDOM PROCESSING MODE IS SEQUENTIAL ACTUAL KEY IS DATA-5. : PROCEDURE DIVISION. : CLOSE INDEXER WITH LOCK, RNDM-FL WITH LOCK. : In the above CLOSE statement, the files named INDEXER and RNDM-FL are closed and locked so that they may not be opened again during execution of the run-unit.


MPE/iX 5.0 Documentation