Arithmetic expressions in nonarithmetic statements

Arithmetic expressions can appear in contexts other than arithmetic statements. For example, you can use an arithmetic expression with the IF or EVALUATE statement.

In such statements, the rules for intermediate results with fixed-point data and for intermediate results with floating-point data apply, with the following changes:

  • Abbreviated IF statements are handled as though the statements were not abbreviated.
  • In an explicit relation condition where at least one of the comparands is an arithmetic expression, dmax is the maximum number of decimal places for any operand of either comparand, excluding divisors and exponents. The rules for floating-point arithmetic apply if any of the following conditions is true:
    • Any operand in either comparand is COMP-1, COMP-2, external floating point, or a floating-point literal.
    • An exponent contains decimal places.
    • An exponent is an expression that contains an exponentiation or division operator, and dmax is greater than zero.

    For example:

    
    IF operand-1 = expression-1 THEN . . .
    

    If operand-1 is a data-name defined to be COMP-2, the rules for floating-point arithmetic apply to expression-1 even if it contains only fixed-point operands, because it is being compared to a floating-point operand.

  • When the comparison between an arithmetic expression and another data item or arithmetic expression does not use a relational operator (that is, there is no explicit relation condition), the arithmetic expression is evaluated without regard to the attributes of its comparand. For example:
    
    EVALUATE expression-1
      WHEN expression-2 THRU expression-3
      WHEN expression-4
      . . .
    END-EVALUATE
    

    In the statement above, each arithmetic expression is evaluated in fixed-point or floating-point arithmetic based on its own characteristics.

Related references  
Terminology used for intermediate results  
Fixed-point data and intermediate results  
Floating-point data and intermediate results  
IF statement (Enterprise COBOL for z/OS® Language Reference)  
EVALUATE statement (Enterprise COBOL for z/OS Language Reference)  
Conditional expressions (Enterprise COBOL for z/OS Language Reference)