SUM function

Syntax

SUM (dynamic.array)

Description

Use the SUM function to calculate the sum of numeric data. Only elements at the lowest delimiter level of a dynamic array are summed. The total is returned as a single element at the next highest delimiter level.

The delimiters from highest to lowest are field, value, and subvalue.

There are seven levels of delimiters from CHAR(254) to CHAR(248): field mark, value mark, subvalue mark, text mark, CHAR(250), CHAR(249), and CHAR(248).

The SUM function removes the lowest delimiter level from a dynamic array. In a dynamic array that contains fields, values, and subordinate values, the SUM function sums only the subordinate values, returning the sums as values. In a dynamic array that contains fields and values, the SUM function sums only the values, returning the sums as fields. In a dynamic array that contains only fields, the SUM function sums the fields, returning the sum as the only field of the array. SUM functions can be applied repeatedly to raise multilevel data to the highest delimiter level or to a single value.

Nonnumeric values, except the null value, are treated as 0. If dynamic.array evaluates to the null value, null is returned. Any element that is the null value is ignored, unless all elements of dynamic.array are null, in which case null is returned.

Examples

In the following examples a field mark is shown by F, a value mark is shown by V, and a subvalue mark is shown by S.

Source Lines
Program Output
X=20:@VM:18:@VM:9:@VM:30:@VM:80 PRINT "SUM(X)=",SUM(X)
SUM(X)= 157
X=17:@FM:18:@FM:15 Y=10:@FM:20 PRINT "SUM(X)+SUM(Y)= ",SUM(X)+SUM(Y)
SUM(X)+SUM(Y)=     80
X=3:@SM:4:@SM:10:@VM:3:@VM:20 Y=SUM(X) PRINT "Y= ",Y Z=SUM(Y) PRINT "Z= ",Z
Y=    17V3V20
Z=    40