HP 3000 Manuals

General Formats (Continued) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation


Micro Focus COBOL Language Reference

General Formats (Continued) 

The OPEN Statement 

Function.   

The OPEN statement initiates the processing of files.  It also performs
checking and/or writing of labels and other input-output operations.

For ANS85 only:  The REVERSED phrase of the OPEN statement is classed as
an obsolete element in the ANSI'85 standard and is scheduled to be
deleted from the next full revision of the ANSI Standard.

For MF only:    All dialects in this COBOL implementation fully support
this syntax.  Refer to your COBOL System Reference for details on using
the FLAGSTD directive to detect all occurrences of this syntax.

For XOPEN only:  Although it is a part of the standard COBOL definition,
the REVERSED phrase of the OPEN statement is explicitly excluded from the
X/Open COBOL language definitions and should not be used in a conforming
X/Open COBOL source program.

General Formats.   

Format 1 (Record Sequential Files).   

[]
Format 2 (Line Sequential,- MF only) Relative And Indexed Files).
[]
Syntax Rules. All Formats (All Files). 1. The files referenced in the OPEN statement need not all have the same organization or access. Format 1 (Record Sequential Files). 2. For MF only: NO REWIND is documentary only. 3. The I/O phrase can be used only for disk files. 4. The EXTEND phrase must be used only for files for which the LINAGE clause has not been specified. 5. The EXTEND phrase must not be specified with multiple file reels. Format 2 (Line Sequential,- MF only) Relative and Indexed Files). 6. The EXTEND phrase can be used for files in sequential access mode (ANS85). General Rules. All Formats (All Files). 1. Prior to the successful execution of an OPEN statement for a given file, no statement (except for a SORT or MERGE statement with the USING or GIVING phrases) can be executed that references that file, either explicitly or implicitly. 2. The successful execution of an OPEN statement determines the availability of the file and results in the file being in an open mode. 3. The successful execution of an OPEN statement makes the associated record area available to the program. 4. In Table 4-14, "X" at an intersection indicates that the specified statement, used in the access mode given for that row, can be used with the open mode given at the top of the column. 5. For MF only: If the WITH LOCK phrase is specified, the OPEN statement acquires a lock on the shole file. (This is equivalent to specifying LOCK MODE IS EXCLUSIVE in the SELECT statement for the file. See the section The SELECT Statement in this chapter.) 6. For ANS85 only: If, during the execution of an OPEN statement, a file attribute conflict occurs, the execution of the OPEN statement is unsuccessful. Your COBOL system defines which of the fixed file attributes are validated during the execution of the OPEN statement. See your file handling documentation for more details. The validation of fixed file attributes can vary depending on the organization and/or storage medium of the file. Table 4-14 : Permissible Combinations of Statements and OPEN Modes ----------------------------------------------------------------- | | | | File Access | OPEN Mode | | Mode | | | | | ----------------------------------------------------------------- | | | | | | | | | Statement| Input | Output | Input- | Extend | | | | | | Output | | | | | | | | | ----------------------------------------------------------------- | | | | | | | | Sequential | READ | X | | X | X | | | WRITE | | X | | | | | REWRITE | | | X | | | | | | | | | ----------------------------------------------------------------- | | | | | | | | Random (Non- | READ | X | | X | | | Sequential | WRITE | | X | X | | | Files) | REWRITE | | | X | | | | START | | | | | | | DELETE | | | X | | | | | | | | | ----------------------------------------------------------------- | | | | | | | | Dynamic (Non- | READ | X | | X | | | Sequential | WRITE | | X | X | | | Files) | REWRITE | | | X | | | | START | X | | X | | | | DELETE | | | X | | | | | | | | | -----------------------------------------------------------------
NOTE The START and DELETE statements can not be used with record or line (MF only) sequential files
7. A file can be opened with the INPUT, OUTPUT, EXTEND and I/O phrases in the same program. Following the initial execution of an OPEN statement for a file, each subsequent OPEN statement execution for that same file must be preceded by the execution of a CLOSE statement for that file (ANS85). 8. Execution of the OPEN statement does not obtain or release the first data record. 9. The external name of the file specified in the SELECT clause for a file is processed as follows: a. When the INPUT phrase is specified, execution of the OPEN statement causes the name to be checked in accordance with the operating system conventions for opening files for input. b. When the OUTPUT phrase is specified, execution of the OPEN statement causes the name to be checked in accordance with the operating system conventions for opening files for output. 10. The file description entry for file-name-1, file-name-2, file-name-3, and file-name-4 must be equivalent to that used when this file was created. 11. For files being opened with the INPUT or I/O phrase, the OPEN statement sets the file position indicator to the first record currently existing in the file for indexed and sequential files, and record position one for relative files. If no records exist in the file, the file position indicator is set such that the next executed READ statement for an indexed or sequential file will result in an AT END condition. If the file does not exist, OPEN INPUT will cause an error status. 12. When the I/O phrase is specified and the LABEL RECORDS clause indicates label records are present, the execution of the OPEN statement includes the following steps: a. The labels are checked in accordance with the operating system-specified conventions for input-output label checking. b. The new labels are written in accordance with the operating system-specified conventions for input-output label writing. 13. Upon successful execution of an OPEN statement with the OUTPUT phrase specified, a file is created. At that time the associated file contains no data records. If a file of the same name exists it will be deleted. If write-protected an error will occur. 14. For ANS85 only: When the EXTEND phrase is specified, the OPEN statement positions the file immediately after the last logical record for that file. The last logical record for a sequential file is the last record written in the file. In a relative file it is the currently existing record with the highest relative record number, and in an indexed file it is the currently existing record with the highest prime key value. 15. Execution of the OPEN statement causes the value of the FILE STATUS data item to be updated (see the section I/O Status earlier in this chapter). 16. For MF only: When LOCK MODE IS EXCLUSIVE is specified in the SELECT/ ASSIGN statement of a file, successful execution of an OPEN statement of that file locks the file exclusively to that run unit. 17. For MF only: When LOCK MODE IS AUTOMATIC or LOCK MODE IS MANUAL is specified in the SELECT/ASSIGN statement of a file, the file that is referred to is shareable. More than one run unit can successfully open such a file. 18. For MF only: A file opened for OUTPUT, and relative and indexed files opened EXTEND, are implicitly defined as files with an exclusive lock, that is, they are not shareable. 19. For MF only: Only shareable files opened for I/O can acquire record locks. 20. If execution of the OPEN statement is unsuccessful, the physical file is not affected and the following actions take place in this order: a. A value is placed in the I/O status associated with file-name to indicate the condition that caused the OPEN statement to be unsuccessful. b. Any applicable USE AFTER EXCEPTION procedure is executed. (See the section The USE Statement in this chapter.) 21. The I/O phrase permits the opening of a file for both input and output operations. If the file does not exist, the following rules apply: a. If the OPTIONAL phrase is specified, the file is created b. If the NOT OPTIONAL phrase is specified, an error occurs c. If neither phrase is specified, and the directive OPTIONAL-FILE was specified when the program was compiled, the file is created. d. If neither phrase is specified, and the directive NOOPTIONAL-FILE was specified when the program was compiled, an error occurs. 22. If an input file is designated with the OPTIONAL phrase in its SELECT clause, the object program causes an interrogation for the presence or absence of this file. If the file is not present, the first READ statement for this file causes the AT END condition to occur. 23. When the EXTEND phrase is specified, the OPEN statement positions the file immediately following the last logical record of that file. Subsequent WRITE statements referencing the file will add records to the file as though the file had been opened with the OUTPUT phrase. If the file does not exist it will be created. 24. For ANS85 only: When the EXTEND phrase is specified and the LABEL RECORDS clause in this file's FD indicates label records are present, the execution of the OPEN statement includes the following steps: a. The beginning file labels are processed only in the case of a single reel/unit file. b. The beginning reel/unit labels on the last existing reel/unit are processed as though the file was being opened with the INPUT phrase. c. The existing ending file labels are processed as though the file is being opened with the INPUT phrase. These labels are then deleted. d. Processing then proceeds as though the file had been opened with the OUTPUT phrase. Format 1 (Record Sequential Files). 25. If the storage medium for the file permits rewinding, the following rules apply: a. Execution of the OPEN statement causes the file to be positioned at its beginning. b. When the REVERSED phrase is specified, the file is positioned at its end by execution of the OPEN statement. 26. When the REVERSED phrase is specified, the subsequent READ statements for the file make the data available in reversed order; that is, starting with the last record. Format 2 (Line Sequential Files). 27. I/O mode is not allowed for line sequential files unless the REWRITE-LS system directive is set (see your COBOL System Reference ) (MF). Formats 1 and 2 (Record ,( Line - MF only)) Sequential,. Relative and Indexed Files) 28. The I/O phrase permits the opening of a file for both input and output operations, except files with ORGANIZATION LINE SEQUENTIAL (MF). If the file does not exist, it will be created and used as an empty file for input unless NOT OPTIONAL was specified in the SELECT statement (MF only). An attempt to READ from the newly created file will cause an error. The PERFORM Statement Function. The PERFORM statement is used to transfer control explicitly to one or more procedures and to return control implicitly whenever execution of the specified procedure is complete. For ANS85 only: The PERFORM statement is also used to control execution of one or more imperative statements which are in the scope of that PERFORM statement. See also the section The EXIT Statement earlier in this chapter. General Formats. Format 1.
[]
Format 2.
[]
Format 3. Please see hardcopy for this graphic. Format 4.
[]
Syntax Rules. All Formats. 1. For ANS85 only: If procedure-name-1 is omitted, imperative-statement-1 and the END-PERFORM phrase must be specified; if procedure-name-1 is specified, imperative-statement-1 and the END-PERFORM phrase must not be specified. For ANS85 and MF only: When an imperative-statement-1 is specified, then the END-PERFORM phrase is optional. 2. The words THROUGH and THRU are equivalent. 3. Where procedure-name-1 and procedure-name-2 are both specified and either is the name of a procedure in the declaratives portion of the Procedure Division, both must be procedure-names in the same declarative section. Formats 2 and 4. 4. Each identifier represents a numeric elementary item described in the Data Division. In Format 2, identifier-1 must be described as a numeric integer. 5. For OSVS, VSC2 and MF only: Floating-point data items and literals can be used anywhere a numeric data item or literal can be specified. They can not be used where an integer is required. Formats 3 and 4. 6. For ANS85 only: If neither the TEST BEFORE nor the TEST AFTER phrase is specified, the TEST BEFORE phrase is assumed. 7. Condition-1, condition-2,..., can be any conditional expression. (See the section Conditional Expressions earlier in this chapter.) Format 4. 8. For ANS85 only: In Format 4, if procedure-name-1 is omitted, the AFTER phrase must not be specified. 9. Each literal represents a numeric literal. 10. If an index-name is specified in the VARYING or AFTER phrase, then: a. The identifier in the associated FROM and BY phrases must reference an integer data item. b. The literal in the associated FROM phrase must be a positive integer. c. The literal in the associated BY phrase must be a nonzero integer. 11. If an index-name is specified in the FROM phrase, then: a. The identifier in the associated VARYING or AFTER phrase must reference an integer data item. b. The identifier in the associated BY phrase must reference an integer data item. c. The literal in the associated BY phrase must be an integer. 12. The literal in the BY phrase must not be zero. 13. Two AFTER phrases are permitted in Format 4 of the PERFORM statement. For ANS85 only: Six AFTER phrases are permitted in Format 4 of the PERFORM statement. For MF only: This limit is raised to fifteen.


MPE/iX 5.0 Documentation