Arithmetic Operations

The arithmetic operations are shown in the following table.

Table 1. Arithmetic Operations
Operation Traditional Syntax Free-Form Syntax
Absolute Value %ABS (Absolute Value of Expression)
Add ADD (Add) + operator
Divide DIV (Divide) / operator or %DIV (Return Integer Portion of Quotient)
Division Remainder MVR (Move Remainder) %REM (Return Integer Remainder)
Multiply MULT (Multiply) * operator
Square Root SQRT (Square Root) %SQRT (Square Root of Expression)
Subtract SUB (Subtract) - operator
Zero and Add Z-ADD (Zero and Add) (not allowed)
Zero and Subtract Z-SUB (Zero and Subtract) (not allowed)

For examples of arithmetic operations, see Figure 1.

Remember the following when specifying arithmetic operations:
  • Arithmetic operations can be done only on numerics (including numeric subfields, numeric arrays, numeric array elements, numeric table elements, numeric named constants, numeric figurative constants, and numeric literals).
  • In general, arithmetic operations are performed using the packed-decimal format. This means that the fields are first converted to packed-decimal format prior to performing the arithmetic operation, and then converted back to their specified format (if necessary) prior to placing the result in the result field.
    However, note the following exceptions:
    • If all operands are unsigned, the operation will use unsigned arithmetic.
    • If all are integer, or integer and unsigned, then the operation will use integer arithmetic.
    • If any operands are float, then the remaining operands are converted to float.

    However, the DIV operation uses either the packed-decimal or float format for its operations. For more information on integer and unsigned arithmetic, see Integer and Unsigned Arithmetic.

  • Decimal alignment is done for all arithmetic operations. Even though truncation can occur, the position of the decimal point in the result field is not affected.
  • The result of an arithmetic operation replaces the data that was in the result field.
  • An arithmetic operation does not change factor 1 and factor 2 unless they are the same as the result field.
  • If you use conditioning indicators with DIV and MVR, it is your responsibility to ensure that the DIV operation occurs immediately before the MVR operation. If conditioning indicators on DIV cause the MVR operation to be executed when the immediately preceding DIV was not executed, then undesirable results may occur.
  • For information on using arrays with arithmetic operations, see Specifying an Array in Calculations.