ADD

Use the ADD script function to return the sum of two values as a 16-digit alphanumeric string with leading zeros.

Syntax

ADD (Operand1, Operand2)

Parameters

  • ADD
    Script function that adds Operand1 and Operand2

  • 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.

Return Code

The script function returns the result of the addition.

Examples

The following example stores the result of an arithmetic operation that adds two values in a script variable. Operand1 and Operand2 are numeric expressions.

:SET &RESULT# = ADD(1000,333)

The following example uses the ADD script function to define a condition:

:SET &MAXIMUM# = 3000
:
SET &RUN1# = 5000
:
SET &RUN2# = 2000 
!...

:
IF ADD(&RUN1#,&RUN2#) > &MAXIMUM#  
!...
 
:
ENDIF

The following example adds two floating-point numbers, and prints the result in the activation report:

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

The result in the activation report would look like this:

U0020408 +0000000000000004.8600000000000000

The following example shows another way of adding numbers by setting the value of a variable with an arithmetic expression:

:SET &ADD# = 1 + 1
:
P &ADD#

The result in the activation report would look like this:

U0020408 0000000000000002

See also: