Assigning arithmetic results (MOVE or COMPUTE)
When assigning a number to a
data item, consider using
the COMPUTE
statement instead of the MOVE
statement.
About this task
Move w to z
Compute z = w
In the example above,
the two statements in most cases have the same effect. The MOVE
statement
however carries out the assignment with truncation. You can use the DIAGTRUNC
compiler
option to request that the compiler issue a warning for MOVE
statements
that might truncate numeric receivers.
When significant left-order
digits would be lost in execution, the COMPUTE
statement
can detect the condition and allow you to handle it. If you use the ON
SIZE ERROR
phrase of the COMPUTE
statement,
the compiler generates code to detect a size-overflow condition. If
the condition occurs, the code in the ON SIZE ERROR
phrase
is performed, and the content of z
remains unchanged.
If you do not specify the ON SIZE ERROR
phrase, the
assignment is carried out with truncation. There is no ON
SIZE ERROR
support for the MOVE
statement.
You
can also use the COMPUTE
statement to assign the
result of an arithmetic expression or intrinsic function to a data
item. For example:
Compute z = y + (x ** 3)
Compute x = Function Max(x y z)