Compaq COBOL
Reference Manual


Previous Contents Index

6.6.5 CORRESPONDING Phrase

The CORRESPONDING phrase allows you to specify group items as operands in order to use their corresponding subordinate items in an operation. See the Section 6.8.2, Section 6.8.37, and Section 6.8.22 statements.

The following rules apply to the identifiers of operands in a statement containing the CORRESPONDING phrase:

  1. All identifiers must refer to group items.
  2. The data description entries of these identifiers can contain a REDEFINES or OCCURS clause.
  3. Identifiers can be subordinate to a data description entry that has a REDEFINES or OCCURS clause.
  4. You cannot specify identifiers with level-number 66, 77 or 88, or the USAGE IS INDEX clause.
  5. Identifiers cannot be reference-modified.

The following rules describe the requirements for correspondence between data items subordinate to the identifiers. In these rules, identifier-1 refers to the sending group item and identifier-2 refers to the group in which results of the operation are stored.

  1. Data items subordinate to both identifier-1 and identifier-2 must have the same data-name.
  2. All possible qualifiers for a data item contained in identifier-1 (up to but not including identifier-1), must be identical to all possible qualifiers for the matching item in identifier-2 (up to but not including identifier-2).
  3. In an ADD or SUBTRACT statement, the CORRESPONDING phrase affects only elementary numeric data items. Other data items do not take part in the operation.
  4. In a MOVE statement, either the sending or receiving subordinate item can be a group item, but both cannot be. The classes of the data items in any corresponding pair can be different, but the resulting move must be legal according to the MOVE statement rules. (See the Section 6.8.22 statement.)
  5. The CORRESPONDING phrase disallows data items with the following:
    A data item subordinate to one that is not eligible for correspondence is also disallowed.
  6. FILLER data items and their subordinates are disallowed.
  7. Neither identifier-1 nor identifier-2 can be reference modified.

6.6.6 ON EXCEPTION Phrase

The ON EXCEPTION phrase allows execution of an imperative statement when an exception (or error) condition occurs.

The NOT ON EXCEPTION phrase allows execution of an imperative statement when an exception condition (or any other error condition) does not occur.

The format is as follows:


stment is an imperative statement.

The ON EXCEPTION phrase of the CALL statement prevents control transfer of the CALL and triggers the execution of the imperative statement related to the CALL.

The ON EXCEPTION phrase of the ACCEPT statement (Formats 3 and 4) allows you to handle data entry errors when data is accepted into a numeric data field using ACCEPT WITH CONVERSION. For additional information, see the Section 6.8.1 statement.

The ON EXCEPTION phrase allows execution of an imperative statement when an ACCEPT statement (Format 5) terminates unsuccessfully. When there is an applicable CRT STATUS clause, unsuccessful termination is indicated by a value of '1' or '9' in the first character of the CRT STATUS data item (see the SPECIAL-NAMES section of Chapter 4).

When an exception condition occurs and the statement contains an ON EXCEPTION phrase:

  1. The imperative statement associated with the ON EXCEPTION phrase is executed.
  2. The NOT ON EXCEPTION phrase, if specified, is ignored.
  3. Control is transferred to the end of the statement unless control has been transferred by executing the imperative statement of the ON EXCEPTION phrase.

When an exception condition occurs and the statement does not contain an ON EXCEPTION phrase:

  1. The NOT ON EXCEPTION phrase, if specified, is ignored.
  2. The program terminates abnormally.

When an exception condition does not occur:

  1. The imperative statement associated with the NOT ON EXCEPTION phrase, if specified, is executed.
  2. The ON EXCEPTION phrase, if specified, is ignored.
  3. Control is transferred to the end of the statement unless control has been transferred by executing the imperative statement of the NOT ON EXCEPTION phrase.

6.6.7 Overlapping Operands and Incompatible Data

When statements refer to data items, two conditions can occur that can make program results unpredictable.

Undefined results occur when a sending and receiving item in an arithmetic statement or an INITIALIZE, INSPECT, MOVE, SET, STRING, or UNSTRING statement share a part of their storage areas.

Procedure Division references to a data item are undefined when a data item's contents are incompatible with the class of data defined by the item's PICTURE clause, or (if the item is a function) its function definition. Conditional statements containing the class condition allow you to do the following:

See Section 6.5.2 for more information on class condition.

6.6.8 I-O Status

If a file description entry has a FILE STATUS clause, a value is placed in the two-character FILE STATUS data item during execution of the following I/O statements:

The two characters from the FILE STATUS data item combine to form a file status value. The first character (Status Key 1), which occupies the leftmost character position in the item, represents a specific class of I/O operation (0--success, 1--at end, 2--invalid key, 3--permanent error, 4--logic error, or 9--Compaq defined). The second character (Status Key 2), which occupies the rightmost position, provides additional information about the result of an I/O operation. In combination, Status Key 1 and Status Key 2 indicate the status of an I/O operation. For example, if you are interested in duplicate keys, you check for File Status 02.

When Status Key 1 contains 1, the AT END phrase executes. When Status Key 1 contains 2, the INVALID KEY phrase executes. When Status Key 1 contains 3, 4, or 9 the Declarative USE procedure executes. Any applicable USE AFTER EXCEPTION procedure executes after the FILE STATUS value is set.

Figure 6-1 shows the possible combinations of Status Keys 1 and 2. In the figure, X indicates a valid combination of keys.

Figure 6-1 Possible Combinations of Status Keys 1 and 2


Status Key 1

Status Key 1 indicates one of the following conditions when an input-output operation ends:

  1. Successful Completion. The input-output statement executed successfully.
  1. At End. A sequential READ statement unsuccessfully executed because of the following:
  1. Invalid Key. The input-output statement executed unsuccessfully because of one of the following conditions:
  1. Permanent Error. The input-output statement executed unsuccessfully because of a boundary error for a sequential file. This value can also indicate an input-output error, such as data check, parity error, or transmission error.
  1. Logic Error. The input-output statement was unsuccessfully executed as a result of an improper sequence of input-output operations that were performed on the file or as a result of violating a limit set by the user.
  1. Compaq defined. The input-output statement executed unsuccessfully because of a condition defined by Compaq.

Status Key 2

Status Key 2 further describes the result of the input-output operation as follows: