The general practice is to use the COMPUTE statement for most arithmetic evaluations rather than the ADD, SUBTRACT, MULTIPLY, and DIVIDE statements. This is because one COMPUTE statement can often be coded instead of several individual statements.
The COMPUTE statement assigns the result of an arithmetic expression to a data item:
COMPUTE Z = A + B / C ** D - E
or to many data items:
COMPUTE X Y Z = A + B / C ** D - E
Some arithmetic might be more intuitive using the other arithmetic statements. For example:
ADD 1 TO INCREMENT.
instead of:
COMPUTE INCREMENT = INCREMENT + 1.
Or,
SUBTRACT OVERDRAFT FROM BALANCE.
instead of:
COMPUTE BALANCE = BALANCE - OVERDRAFT.
Or,
ADD 1 TO INCREMENT-1, INCREMENT-2, INCREMENT-3.
instead of:
COMPUTE INCREMENT-1 = INCREMENT-1 + 1 COMPUTE INCREMENT-2 = INCREMENT-2 + 1 COMPUTE INCREMENT-3 = INCREMENT-3 + 1
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.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.