SUB

Use the SUB script function to return the difference between two values as a 16-digit alphanumeric string with leading zeros.

Syntax

SUB (Operand1, Operand2)

Parameters

  • SUB
    Subtracts Operand2from Operand1
    Return code: result of the subtraction

  • Operand1
    First expression
    Format: script literal, script variable or number specified without quotation marks

  • Operand2
    Second expression
    Format: script literal, script variable or number specified without quotation marks

Notes:

  • Ensure that the values lie within the allowed range for the declared data types of your script variables. The data type of the result is decisive, not the data type of the operand. Not all data types support negative values and decimals. Negative values result in an error if the variable is not data type float. If the data type of the variable does not allow decimals, any decimals in your result are truncated. For more information, see Script Variable Data Types.
  • Results are returned in the default 16-digit format, with leading zeros. Floating-point numbers also include 16 decimal places. If negative numbers are supported, an algebraic sign (+ or -) is used as the first character.
  • If the result is a floating-point number and the target variable is data type signed or unsigned, the decimals are rounded up or down to the nearest whole number.

Tip: You can remove leading zeros and otherwise edit the format of results with the FORMAT script function.

Examples

The example below stores the result of a subtraction in a script variable. Operand1 and Operand2 are specified as numeric expressions.

:SET &RESULT# = SUB(1000,999)

The example below shows a subtraction with floating-point numbers: 

:DEFINE &RESULT#,float
:SET &RESULT#SUB(10.31,-5.45)
:P &RESULT#

The following result is output in the activation report:

U0020408 +0000000000000015.7600000000000000

The example below shows another way of subtracting values, by using an arithmetic expression and storing the result in a script variable.

:SET &SUBTRACT# = 3 - 2
:
P &SUBTRACT#

The following result is output in the activation report:

U0020408 0000000000000001

See also: