SUM

Computes a total for specified numeric fields in the current table.

Syntax

SUM [<exp list>]

[<scope>]

[FOR <condition 1>]

[WHILE <condition 2>]

[TO <memvar list> | TO ARRAY <array>]

<exp list>

The numeric fields, or expressions involving numeric fields, to sum.

<scope>

FOR <condition 1>

WHILE <condition 2>

The scope of the command. The default scope is ALL.

TO <memvar list> | TO ARRAY <array>

Initializes and stores sums to the variables (or properties) of <memvar list> or stores sums to the existing array <array>. If you specify an array, each field sum is stored to elements in the order in which you specify the fields in <exp list>. If you don't specify <exp list>, each field sum is stored in field order. <array> can be a single- or multidimensional array; the array elements are accessed via their element numbers, not their subscripts.

Description

The SUM command computes the sum of numeric expressions and stores the results in specified variables or array elements. If you store the values in variables, the number of variables must be exactly the same as the number of fields or expressions summed. If you store the values in an array, the array must already exist, and the array must contain at least as many elements as the number of summed expressions.

If SET TALK is ON, SUM also displays its results in the result pane of the Command window. The SET DECIMALS setting determines the number of decimal places that SUM displays. Numeric fields in blank records are evaluated as zero. To exclude blank records, use the ISBLANK( ) function in defining a FOR condition. EMPTY( ) excludes records in which a specified expression is either 0 or blank.

SUM is similar to TOTAL, which operates on an indexed or sorted table to create a second table containing the sums of the numeric and float fields of records grouped on a key expression.

OODML

Loop through the rowset to calculate the sum.