[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

6.5.8 Abbreviated Combined Relation Conditions

When you combine simple or negated simple conditions in a consecutive sequence, you can abbreviate any of the relation conditions except the first. You do this by either:

  • Omitting the subject of the relation condition
  • Omitting both the subject and the relational operator of the condition
  • Ensuring that a relation condition in the consecutive sequence contains a subject (or subject and relational operator) that is common with the preceding relation condition
  • Ensuring that there are no parentheses in the consecutive sequence

The general format for abbreviated combined relation conditions is as follows:


The evaluation of a sequence of combined relation conditions proceeds as if the last preceding subject appears in place of the omitted subject and the last preceding relational operator appears in place of the omitted relational operator. The result of these substitutions must form a valid condition. (See Table 6-5.)

When the word NOT appears in a sequence of abbreviated conditions, its treatment depends upon the word that follows it. NOT is considered part of the relational operator when immediately followed by: GREATER, >, LESS, <, EQUAL, or =. Otherwise, NOT is considered a logical operator that negates the relation condition.

Table 6-6 shows abbreviated combined (and negated combined) relation conditions and their expanded equivalents:

Table 6-6 Expanded Equivalents for Abbreviated Combined Relation Conditions
Abbreviated Combined
Relation Condition
Expanded Equivalent
a > b AND NOT < c OR d ((a > b) AND (a NOT < c)) OR (a NOT < d)
a NOT = b OR c (a NOT = b) OR (a NOT = c)
NOT a = b OR c (NOT (a = b)) OR (a = c)
NOT (a GREATER b OR < c) NOT ((a GREATER b) OR (a < c))
a / b NOT = c AND NOT d ((a / b) NOT = c) AND (NOT ((a / b) NOT = d))
NOT (a NOT > b AND c AND NOT d) NOT ((((a NOT > b) AND (a NOT > c)) AND (NOT (a NOT > d))))

6.5.9 Condition Evaluation Rules

Parentheses can specify the evaluation order in complex conditions. Conditions in parentheses are evaluated first. In nested parentheses, evaluation starts with the innermost set of parentheses. It proceeds to the outermost set.

Conditions are evaluated in a hierarchical order when there are no parentheses in a complex condition. This same order applies when all sets of parentheses are at the same level (none are nested). The hierarchy is shown in the following list:

  1. Values for arithmetic expressions
  2. Truth values for simple conditions, in this order:
    1. Relation
    2. Class
    3. Condition-name
    4. Switch-status
    5. Sign
    6. Success/failure
  3. Truth values for negated simple conditions
  4. Truth values for combined conditions, in this order:
    1. AND logical operators
    2. OR logical operators
  5. Truth values for negated combined conditions

In the absence of parentheses, the order of evaluation of consecutive operations at the same hierarchical level is from left to right.

6.6 Common Rules and Options for Data Handling

This section describes the rules and options that apply when statements handle data. Data handling includes the following:

  • Arithmetic operations
  • Multiple receiving fields in arithmetic statements
  • The ROUNDED phrase
  • The ON SIZE ERROR phrase
  • The CORRESPONDING phrase
  • The ON EXCEPTION phrase
  • Overlapping operands and incompatible data
  • I/O status
  • The INVALID KEY phrase
  • The AT END phrase
  • The FROM phrase
  • The INTO phrase

6.6.1 Arithmetic Operations

The arithmetic statements begin with the verbs ADD, COMPUTE, DIVIDE, MULTIPLY, and SUBTRACT. When an operand in these statements is a data item, its PICTURE must be numeric and specify no more than 31 digit positions on Alpha or I64 (18 on VAX). However, operands do not have to be the same size, nor must they have the same USAGE. Conversion and decimal point alignment occur throughout the calculation.

When you write an arithmetic statement, you specify one or more data items to receive the results of the operation. These data items are called resultant identifiers. However, the evaluation of each arithmetic statement can also use an intermediate data item. An intermediate data item is a compiler-supplied signed numeric data item that the program cannot access. It stores the results of intermediate steps in the arithmetic operation before moving the final value to the resultant identifiers.

When the final value of an arithmetic operation is moved to the resultant identifiers, it is transferred according to MOVE statement rules. Rounding and size error condition checking occur just before this final move. (See the Section 6.8.22 statement, Section 6.6.4, ON SIZE ERROR Phrase, and Section 6.6.3, ROUNDED Phrase.)

6.6.2 Multiple Receiving Fields in Arithmetic Statements

An arithmetic statement can move its final result to more than one data item. In this case, the statement is said to have multiple receiving fields (or multiple results). The statement operates as if it had been written as a series of statements. The following example illustrates these steps. The first statement in the example is equivalent to the four that follow it. (Temp is an intermediate data item.)


ADD a, b, c TO c, d (c), e

ADD a, b, c GIVING temp
ADD temp TO c
ADD temp TO d (c)
ADD temp TO e

6.6.3 ROUNDED Phrase

The ROUNDED phrase allows you to specify rounding at the end of an arithmetic operation. The rounding operation adds 1 to the absolute value of the low-order digit of the resultant identifier if the absolute value of the next least significant (lower-valued) digit of the intermediate data item is greater than or equal to 5.

When the PICTURE string of the resultant identifier represents the low-order digit positions with the P character, rounding or truncation is relative to the rightmost integer position for which the compiler allocates storage. Therefore, when PIC 999PPP describes the item, the value 346711 is rounded to 347000.

If you do not use the ROUNDED phrase, any excess low-order digits in the arithmetic result are truncated when the result is moved to the resultant identifiers.

6.6.4 ON SIZE ERROR Phrase

The ON SIZE ERROR phrase allows you to specify an action for your program to take when a size error condition exists.

The NOT ON SIZE ERROR phrase allows you to specify an action for your program to take when a size error condition does not exist.

The format is as follows:


stment is an imperative statement.

Size error checking occurs after decimal point alignment. Rounding occurs before size error checking. Also, truncation of rightmost digits occurs before size error checking.

A size error condition is caused by the following:

  • Division by zero or invalid evaluation of exponentiation (see Section 6.4.2). Both actions terminate the arithmetic operation.
  • The absolute value of an arithmetic operation's result exceeds the value that is specified by the PICTURE clause of one or more of the resultant identifiers.
  • Evaluation of an arithmetic expression would cause the new value to be outside the allowed range for the intermediate data item.

In the second case above, the size error condition affects the contents of only those resultant identifiers for which the size error exists.

When a size error condition occurs and the statement contains an ON SIZE ERROR phrase:

  1. When standard arithmetic is in effect, the values of those resultant identifiers for which the size error exists are the same as before the operation began; when native arithmetic is in effect, those values are undefined.
  2. The values of those resultant identifiers for which no size error exists are the same as they would have been if the size error condition had not occurred for any of the resultant identifiers.
  3. The imperative statement in the ON SIZE ERROR phrase executes.
  4. The NOT ON SIZE ERROR phrase, if specified, is ignored.
  5. Control is transferred to the end of the arithmetic statement unless control has been transferred by executing the imperative statement of the ON SIZE ERROR phrase.
  6. When a size error occurs in any arithmetic statement with multiple results, your program must analyze the results to determine where the size error occurred.

When a size error condition occurs and the statement does not contain an ON SIZE ERROR phrase:

  1. The values of those resultant identifiers for which the size error exists are undefined.
  2. The NOT ON SIZE ERROR phrase, if specified, is ignored.
  3. Control is transferred to the end of the arithmetic statement.

When a size error condition does not occur:

  1. The ON SIZE ERROR phrase, if specified, is ignored.
  2. The imperative-statement in the NOT ON SIZE ERROR phrase, if specified, is executed.
  3. Control is transferred to the end of the arithmetic statement unless control has been transferred by executing the imperative statement of the NOT ON SIZE ERROR phrase.


Previous Next Contents Index