HP 3000 Manuals

Procedure Division for File Input and Output [ COBOL/HP-UX Language Reference for the Series 700 and 800 ] MPE/iX 5.0 Documentation


COBOL/HP-UX Language Reference for the Series 700 and 800

Procedure Division for File Input and Output 

The CLOSE Statement 

Function 

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

General Formats 

Format 1 (Record Sequential Files) 

[]
________________________________________________________________________ |(ANS85) | | | |Format 2 (Line Sequential, Relative and Indexed Files) | | | | CLOSE file-name-1 [WITH LOCK] [file-name-2 [ WITH LOCK ] ] ... | ________________________________________________________________________ Syntax Rules All Formats (All Files) 1. The files referenced in the CLOSE statement need not all have the same organization or access. Format 1 (Record Sequential Files) ________________________________________________________________________ |(MF) | | | | | | | |2. 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. | | | ________________________________________________________________________ ________________________________________________________________________ |(OSVS) | | | | | | | |3. The DISP option is only applicable to tape files. | | | | It is documentary only. (MF) | | | ________________________________________________________________________ General Rules 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. ________________________________________________________________________ |(ANS85) | | | | | | | |3. If a file is in the open mode when a STOP RUN statement is | | executed the file will be 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 will be| | closed. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |4. 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 "I/O Status" earlier in this chapter.) 6. The results of executing each type of CLOSE statement for each category of file are summarized in Table 5-5 . Table 5-5. Relationship of Categories of Files and the Formats of the CLOSE Statement ----------------------------------------------------------------------------------------------------- | | | | CLOSE Statement | File Category | | Format | | | | | ----------------------------------------------------------------------------------------------------- | | | | | | | | Non-Reel/ | Record | Record | Non-record | | | Unit | Sequential | Sequential | Sequential | | | | Single-Reel/ | Multi-Reel/ | Single/ | | | | Unit | Unit | 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 | C, H (ANS85) | B, C | A, B, C | X | | REWIND record | | | | | | sequential only | | | | | | | | | | | | CLOSE REEL/UNIT | F (ANS85) | F, G (ANS85) | F, G | X | | record sequential | | | | | | only | | | | | | | | | | | | CLOSE REEL/UNIT | F (ANS85) | D, F, G (ANS85) | D, F , G | X | | FOR REMOVAL | | | | | | record sequential | | | | | | only | | | | | | | | | | | | CLOSE REEL/UNIT | X | X | F, B | X | | WITH NO REWIND | | | | | | record sequential | | | | | | only | | | | | | | | | | | ----------------------------------------------------------------------------------------------------- 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. B. No Rewind of Current Reel The current reel/unit is left in its current position. C. Close File Input Files and Input-Output Files (Sequential Access Mode): If the file is at the end and label records are specified for the file, the labels are processed according to the operating system label convention. The behavior of the CLOSE statement when label records are specified but not present, or when label records are not specified but are present, is undefined. If the file is at the end and label records are not specified for the file, label processing does not take place, but other closing operations dependent on the Run-Time System are executed. (See your COBOL System Reference.) If the file is not at the end, the closing operations dependent on the RTS are executed, but there is no ending label processing. Input Files and Input-output Files (Random or Dynamic Access Mode); Output Files (Random, Dynamic or Sequential Access Mode): If label records are specified for the file, the labels are processed according to the operating system standard label convention. The behavior of the CLOSE statement when label records are specified but not present, or when label records are not specified but are present, is undefined. If label records are not specified for the file, label processing does not take place, but other closing operations dependent on the Run-Time System are executed. D. Reel/Unit Removal The reel or unit can be accessed again, in the proper order of reels or units within the file, if a CLOSE statement without the REEL or UNIT phrase has previously been executed for this file followed by the execution of an OPEN statement for the file. E. File Lock This file cannot be opened again during this execution of this run unit. F. Close Reel/Unit Input Files and Input-Output Files (Reel/Unit Media): ________________________________________________________________________ |(ANS85) | | | | | | | |1. If the current reel/unit is the last or only reel/unit for the | | file, there is no reel/unit swap; the current volume pointer | | remains unchanged, and the file position indicator is set to | | indicate that no next reel/unit exists. | | | ________________________________________________________________________ 2. If another reel/unit exists for the file, a reel/unit swap occurs, the current volume pointer is updated to point to the next reel/unit existing in the file, the standard beginning reel/unit label procedure is executed, and the file position indicator is set to one less than the number of the first record existing on the new current volume. If no data records exist for the current volume, another reel/unit swap occurs. Output Files (Reel/Unit Media): The following operations take place; a. Execution of the standard ending reel/unit label procedure. b. A reel/unit swap. c. Execution of the standard beginning reel/unit label procedure. d. The next executed WRITE statement that references that file directs the next logical data record to the next reel/unit of the file. ________________________________________________________________________ |(ANS85) | | | |Input Files, Input-Output Files, and Output Files (Non-Reel/Unit | |Media): | | | |Execution of this statement is considered successful. The file | |remains in the open mode, the file position indicator remains | |unchanged, and no action takes place except as specified in General | |Rule 4. | ________________________________________________________________________ G. Rewind The current reel or analogous device is positioned at its physical beginning. ________________________________________________________________________ |(ANS85) | | | | | | | |H. Optional Phrases Ignored | | | | The CLOSE statement is executed as if none of the optional | | phrases is present. | | | ________________________________________________________________________ X. Illegal This is an illegal combination of a CLOSE option and a file category. The results at object time are undefined. Format 1 (Record Sequential Files) Except where otherwise stated in the general rules below, the terms "reel" and "unit" are equivalent and completely interchangeable in the CLOSE statement. Treatment of sequential mass storage files is logically equivalent to the treatment of a file on tape or analogous sequential media. 7. In order to show the effect of various types of CLOSE statements as applied to various storage media, all files are divided into the following categories: a. Non-reel/unit. A file whose input or output medium is such that the concepts of rewind and reels/units have no meaning. b. Sequential single-reel/unit. A sequential file that is entirely contained on one reel/unit. c. Sequential multi-reel/unit. A sequential file that is contained on more than one reel/unit. 8. If the OPTIONAL phrase has been specified for the file in the FILE-CONTROL paragraph of the Environment Division and the file is not present, the standard end-of-file processing is not performed for that file. 9. If a CLOSE statement without the REEL or UNIT phrase has been executed for a file, no other statement (except the SORT or MERGE statements with the USING or GIVING phrases) can be executed that references that file, either explicitly or implicitly, unless an intervening OPEN statement for that file is executed. 10. The WITH NO REWIND and FOR REMOVAL phrases will have no effect at object time if they do not apply to the storage media on which the file resides. 11. If WITH LOCK is specified, the file cannot be reopened during the current execution of the run unit. Otherwise a normal CLOSE takes effect. ________________________________________________________________________ |(MF) | |(This option has no connection with the record or file locking used | |when sharing files.) | ________________________________________________________________________ All Formats (All Files) 12. If a CLOSE statement has been executed for a file, no statement other than a delete file (MF) can be executed that references that file, either explicitly or implicitly, unless an intervening OPEN statement for that file is executed. 13. If WITH LOCK is specified, the file cannot be reopened during the current execution of the run unit. ________________________________________________________________________ |The COMMIT Statement | | | |(MF) | | | |Function | | | |The COMMIT statement releases all record locks in all files held by | |this run unit. For COBOL systems that support the WITH...ROLLBACK | |clause of the SELECT statement as other than documentary, COMMIT | |indicates the end of the current transaction and makes the effects of | |that transaction permanent. | | | |General Format | | | | COMMIT | | | |General Rules | | | | | | * Execution of the COMMIT statement causes all record locks in | | all files held by the run unit to be released. | | | | * The file lock on an exclusive file is not affected by the | | COMMIT statement. | | | | * If your COBOL system supports the WITH ... ROLLBACK clause of | | the SELECT statement as other than documentary, then the COMMIT| | verb: | | | | | | a. Indicates completion of the current transaction | | | | b. Makes all changes applied during the transaction | | permanent | | | |See your COBOL System Reference for details. | ________________________________________________________________________ The DELETE Statement Function The DELETE statement logically removes a record from a mass storage file. It can be specified only for files with relative or indexed organization. General Format
[]
Syntax Rules * The INVALID KEY phrase must not be specified for a DELETE statement which references a file in sequential access mode. * The INVALID KEY phrase must be specified for a DELETE statement which references any file not in sequential access mode for which an applicable USE AFTER STANDARD EXCEPTION PROCEDURE is not specified. ________________________________________________________________________ |This rule is not enforced. (MF) | ________________________________________________________________________ General Rules 1. The associated file must be open in the I/O mode at the time of execution of this statement. (See the section The OPEN Statement later in this chapter.) 2. For files in sequential access mode, the last input-output statement executed for file-name-1 prior to the execution of the DELETE statement must have been a successfully executed READ statement. The operating system logically removes from the file the record that was accessed by that READ statement. 3. For a file in random or dynamic access mode, the operating system logically removes from the file that record identified by the contents of a KEY data item associated with file-name. For a relative file, this KEY data item is the RELATIVE KEY and for an indexed file, it is the prime RECORD KEY. If the file does not contain the record specified by the key, an INVALID key condition exists. (See the section "The INVALID KEY Condition" in this chapter.) 4. After the successful execution of a DELETE statement, the identified record is logically removed from the file and can no longer be accessed. 5. The execution of a DELETE statement does not affect the contents of the record area associated with file-name-1. 6. The file position indicator is not affected by the execution of a DELETE statement. 7. Execution of the DELETE statement causes the value of the specified FILE STATUS data item, if any, associated with the file name to be updated. (See the section I/O Status earlier in this chapter.) 8. Transfer of control following the successful or unsuccessful execution of the DELETE operation depends on the presence or absence of the optional INVALID KEY phrase and NOT INVALID KEY phrase (ANS85) in the DELETE statement. (See the section "The INVALID KEY Condition" in this chapter.) ________________________________________________________________________ |(ANS85) | | | | | | | |9. The END-DELETE phrase delimits the scope of the DELETE statement.| | (See the section "Explicit and Implicit Scope Terminators" in| | the chapter COBOL Concepts. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |10. When using DELETE, the record to be deleted must not be locked by| | another run unit. | | | |11. Following the successful execution of a DELETE statement, any | | record lock held by the run unit on the deleted record is | | released. | | | ________________________________________________________________________ 12. Execution of the DELETE statement causes the value of the I/O status associated with file-name-1 to be updated. (See the section "I/O Status" earlier in this chapter.) ________________________________________________________________________ |(MF) | | | |The DELETE FILE Statement | | | |Function | | | |The DELETE FILE statement physically removes the specified files from | |the physical devices on which they reside. | | | |General Format | | | | DELETE FILE {file-name} ... | | | |General Rules | | | | | | 1. The DELETE FILE statement physically removes the specified | | files from the physical devices on which they reside. | | | | 2. The specified files must be closed when the statement is | | executed, but not CLOSED WITH LOCK. | ________________________________________________________________________


MPE/iX 5.0 Documentation