Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Programming Guide


Using COMPUTE and other arithmetic statements

Use the COMPUTE statement for most arithmetic evaluations rather than ADD, SUBTRACT, MULTIPLY, and DIVIDE statements. Often you can code only one COMPUTE statement instead of several individual arithmetic statements.

The COMPUTE statement assigns the result of an arithmetic expression to one or more data items:

Compute z     = a + b / c ** d - e
Compute x y z = a + b / c ** d - e

Some arithmetic calculations might be more intuitive using arithmetic statements other than COMPUTE. For example:

COMPUTE Equivalent arithmetic statements
Compute Increment = Increment + 1
Add 1 to Increment
Compute Balance =
    Balance - Overdraft
Subtract Overdraft from Balance
Compute IncrementOne =
    IncrementOne + 1
Compute IncrementTwo =
    IncrementTwo + 1
Compute IncrementThree =
    IncrementThree + 1
Add 1 to IncrementOne,
    IncrementTwo,
    IncrementThree

You might also prefer to use the DIVIDE statement (with its REMAINDER phrase) for division in which you want to process a remainder. The REM intrinsic function also provides the ability to process a remainder.

When you perform arithmetic calculations, you can use national decimal data items as operands just as you use zoned decimal data items. You can also use national floating-point data items as operands just as you use display floating-point operands.

related tasks  
Defining numeric data


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)