Performing math on variables that are declared - explicitly or implicitly - as
NATIONAL is much less efficient
BINARY variables. That’s because
COMP variables, for instance, are
defined for binary storage, which makes math on them more efficient. That’s why values that are going to be used primarily for math should be declared
with a math type. When math isn’t a primary use, it may not make sense to change the declared type, but
MOVEing the value to a
COMP variable and performing the math on it instead would.
It is important to note however, that
BINARY formats should be used with caution if
the variable will be passed to other systems which may not use the same storage format.
Noncompliant Code Example
01 W-AMOUNT-VALUE PIC 9(17).
01 W-AMOUNT-DECIMAL PIC 9.
COMPUTE W-CONV-AMOUNT = W-AMOUNT-VALUE * 10 ** W-AMOUNT-DECIMAL *> Noncompliant
01 W-AMOUNT-VALUE PIC 9(17) COMP-5.
01 W-AMOUNT-DECIMAL PIC 9 COMP-5.
COMPUTE W-CONV-AMOUNT = W-AMOUNT-VALUE * 10 ** W-AMOUNT-DECIMAL