SUM Function

The SUM function calculates the sum of numeric data in a dynamic array string.

Format

SUM(string)

Parameter(s)

string

Dynamic array string.

Description

Data is added by the SUM function only at the lowest delimiter level in the string. The SUM function adds each group of lowest-level elements into a single number, removing the lowest-level delimiters.

If the string contains all three levels (subvalues, values, and attributes), the SUM function has to be called three times to produce a single numeric value; if the string contains two of the three levels, the SUM function has to be called twice.

Examples

If STRING contains:

10^20\30\40^50]60\70]80^90

then:

STRING= SUM(STRING)

produces as STRING:

10^90^50]130]80^90

If we once again performed STRING= SUM(STRING), we would have:

10^90^260^90

and STRING = SUM(STRING) again would finally give us:

450

In the next application, a program to maintain inventory for a shoe store keeps a record of each shoe style in a separate file item. The format for each file item is that each attribute represents a color that the shoe style is manufactured in, and within each attribute are eight MultiValues representing different sizes in that color, ranging from 5 1/2 to 9.

A program to perform a quick calculation of the number of shoes still available in that style might read:

EQUATE AM TO CHAR(254)

OPEN "SHOES" TO STYLEFILE ELSE …

PRINT "ENTER STYLE NO."

INPUT ID

READ STYLEREC FROM STYLEFILE, ID ELSE …

COLORREC = SUM(STYLEREC)

NO.OF.COLORS = DCOUNT(STYLEREC, AM)

FOR I = 1 TO NO.OF.COLORS

   PRINT "COLOR " : I, COLORREC< I >

NEXT I

PRINT "TOTAL ON HAND", SUM(COLORREC)

See Also

Statement and Function Reference