Optimizing COMPUTE Statements

Only use COMPUTE statements to perform calculations that involve floating-point data. For floating-point data, COMPUTE is the most efficient statement.

COMPUTE is defined to evaluate its result in a temporary field of the largest possible significance to hold the result. This temporary field might be of a larger significance than is actually required, causing the operations to be slower. The temporary field is stored in the target field with any necessary truncation. This also applies to IF statements involving expressions. For example:

 IF a + b < c

It is often better to define a temporary data item of the required size and use that to hold the result of the arithmetic, as follows:

 MOVE a TO temp
 ADD b TO temp
 IF temp < c