[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

Appendix C lists all the possible file status values that can appear in the FILE STATUS data item, along with the I-O status condition corresponding to each value.

6.6.9 AT END Phrase

The AT END phrase specifies the action your program takes when an at end condition occurs (when Status Key 1 contains 1).

The NOT AT END phrase specifies the action your program takes if an at end (or any other error condition) does not occur.

The format is as follows:


stment is one or more imperative statements.

When a program detects the end of a file, the condition is called the at end condition. The at end condition might occur as a result of ACCEPT, READ, RETURN, or SEARCH statement execution. (For additional information, see the previously mentioned statements.)

When an at end condition occurs and the statement contains an AT END phrase:

  1. The imperative statement associated with the AT END phrase, if specified, executes.
  2. The NOT AT END phrase, if specified, is ignored.
  3. Control is transferred to the end of the ACCEPT, READ, RETURN, or SEARCH statement unless control has been transferred by executing the imperative statement of the AT END phrase.

When an at end condition occurs and the statement does not contain an AT END phrase:

  1. If the at end condition is associated with a READ statement, the applicable USE AFTER EXCEPTION procedure, if specified, executes.
  2. If the at end condition is associated with an ACCEPT, RETURN, or SEARCH statement, any USE procedure associated with that file is not applicable.
  3. The NOT AT END phrase, if specified, is ignored.

When an at end condition does not occur, and no other exception condition exists:

  1. The AT END phrase, if specified, is ignored.
  2. The imperative statement associated with the NOT AT END phrase, if specified, is executed. Otherwise, control is transferred to the end of the ACCEPT, READ, RETURN, or SEARCH statement.

When an at end condition does not occur, and another exception condition does exist:

  • The applicable USE AFTER EXCEPTION procedure, if specified, executes and control is then transferred according to the rules of the USE statement.
  • If there is no applicable USE AFTER EXCEPTION procedure, the imperative statement associated with the NOT AT END phrase, if specified, is executed, unless the exception condition causes the run unit to terminate abnormally.
  • If there is neither a USE AFTER EXCEPTION procedure nor a NOT AT END phrase, then control is transferred to the end of the statement, unless the exception condition causes the run unit to terminate abnormally.

6.6.10 INVALID KEY Phrase

The INVALID KEY phrase specifies the action your program takes when an invalid key condition is detected (when Status Key 1 contains 2) for the file being processed.

The NOT INVALID KEY phrase specifies the action your program takes when an invalid key condition (or any other error condition) is not detected for the file being processed.

The format is as follows:


stment is one or more imperative statements.

The invalid key condition occurs when the I/O system cannot complete a COBOL DELETE, READ, REWRITE, START, or WRITE statement because of one of the following conditions:

  • Sequence error
  • Duplicate key when the COBOL program did not specify this condition
  • No record found
  • Boundary violation on a relative or indexed file
  • Optional file not present

(For more information on these conditions, refer to Section 6.6.8.) When the invalid key condition occurs, execution of the statement that produced the condition is unsuccessful, and the file is unaffected. (For additional information, see the previously mentioned statements.)

When the invalid key condition occurs:

  1. A value that indicates the invalid key condition is placed in the FILE STATUS data item for the file.
  2. If the statement that caused the condition has the INVALID KEY phrase:
    1. Any USE AFTER EXCEPTION procedure is not executed.
    2. The imperative statement associated with the INVALID KEY phrase executes.
    3. The NOT INVALID KEY phrase, if specified, is ignored.
    4. Control is transferred to the end of the I-O statement unless control has been transferred by executing the imperative statement of the INVALID KEY phrase.
  3. If the statement that caused the condition does not have an INVALID KEY phrase:
    1. The NOT INVALID KEY phrase, if specified, is ignored.
    2. Control is transferred to the applicable USE AFTER EXCEPTION procedure for the file.

When an invalid key condition does not occur, and no other exception condition exists:

  1. The INVALID KEY phrase, if specified, is ignored.
  2. The imperative statement associated with the NOT INVALID KEY phrase, if specified, is executed. Otherwise, control is transferred to the end of the I/O statement.

When an invalid key condition does not occur, and another exception condition does exist:

  • The applicable USE AFTER EXCEPTION procedure, if specified, executes and control is then transferred according to the rules of the USE statement.
  • If there is no applicable USE AFTER EXCEPTION procedure, the imperative statement associated with the NOT INVALID KEY phrase, if specified, is executed, unless the exception condition causes the run unit to terminate abnormally.
  • If there is neither a USE AFTER EXCEPTION procedure nor a NOT INVALID KEY phrase, then control is transferred to the end of the statement, unless the exception condition causes the run unit to terminate abnormally.

6.6.11 FROM Phrase


record-name and identifier must not refer to the same storage area.

The result of executing a RELEASE, REWRITE, or WRITE statement with the FROM phrase is equivalent to: (1) executing the statement "MOVE identifier TO record-name" according to the rules of the MOVE statement without the CORRESPONDING phrase, followed by (2) executing the same RELEASE, REWRITE, or WRITE statement without the FROM phrase.

After statement execution ends, the data in the area referenced by identifier is available to the program. The data is not available in the area referenced by record-name, unless there is an applicable SAME clause. (See Section 4.2.10, I-O-CONTROL, the Section 6.8.30 statement, and the Section 6.8.43 statement.)

6.6.12 INTO Phrase

The INTO phrase implicitly moves a current record from the record storage area into an identifier.

The format is as follows:


A READ or RETURN statement can have the INTO phrase if either of the following conditions is true:

  • Only one record description is subordinate to the file description entry.
  • All record-names associated with file-name and the data item associated with identifier describe a group item or an elementary alphanumeric item.

Executing a READ or RETURN statement with the INTO phrase is equivalent to: (1) executing the same statement without the INTO phrase, then (2) moving the current record from the record area to the area specified by identifier. The move occurs according to the rules of the MOVE statement without the CORRESPONDING phrase. The move does not occur for an unsuccessful execution of the READ or RETURN statement.

Subscript or index evaluation occurs after the input operation and immediately before the move.

The record is available to the program in both the record area and the area associated with the identifier.

6.7 Segmentation

HP COBOL programs execute in a virtual memory environment. Therefore, programs need not manage physical memory by overlaying Procedure Division code. HP COBOL provides support for segmentation only for compatibility with existing applications developed on older hardware such as the PDP-11. You should not use segmentation in newly written COBOL programs since segmentation results in the generation of extra code which might impact performance.

Segmentation controls the assignment of Procedure Division sections to fixed or independent segments. The optional segment-number in the section header determines the type of segment.


section-name

names a Procedure Division section.

segment-number

must be an integer in the range 0 to 99. If there is no segment-number in a section header, the implied segment-number is 0.

segment-number classifies a segment into fixed segments or independent segments. Sections with segment-numbers from 0 to 49 are in fixed segments. Those with segment-numbers from 50 to 99 are in independent segments.

Sections in the Declaratives part of the Procedure Division must have segment-numbers less than 50.

A segment consists of all sections that have the same segment-number.

Both fixed and independent segments are in their initial state the first time entered. A fixed segment appears to reside in memory at all times and is, therefore, in its last used state each time it is entered.

The state of an independent segment depends on how and when it receives control. On subsequent control transfers, HP COBOL resets the segment's ALTERed GO TO statements to their initial states whenever an independent segment is entered in one of the following ways:

  1. Explicitly, by means of a GO TO statement with a target within the section.
  2. Explicitly, by means of an out-of-line PERFORM statement in another segment whose range is within the section.
  3. Implicitly, when a SORT or MERGE statement in another segment specifies an input or output procedure within the section.
  4. Implicitly, by transfer of control between consecutive statements from a segment with a different segment-number.


Previous Next Contents Index