Sum numeric expressions and assign results to variables


      SUM <nExp list> TO <idVar list>
            [<scope>] [WHILE <lCondition>] [FOR <lCondition>]


<nExp list> is the list of numeric values to sum for each record processed.

TO <idVar list> identifies the receiving variables to be assigned assign the results of the sum. Variables that either do not exist or are not visible are created as private variables. <idVar list> must contain the same number of elements as <nExp list>.

<scope> is the portion of the current database file to SUM. The default scope is ALL records.

WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.

FOR <lCondition> specifies the conditional set of records to SUM within the given scope.


SUM is a database command that totals a series of numeric expressions for a range of records in the current work area and assigns the results to a series of variables. The variables specified in <idVar list> can be field, local, private, public, or static.

Note that the <nExp list> is required and not optional as it is in other dialects.


      .  This example illustrates the use of SUM:

      LOCAL nTotalPrice, nTotalAmount
      USE Sales NEW
      SUM Price * .10, Amount TO nTotalPrice, nTotalAmount
      ? nTotalPrice               // Result: 151515.00
      ? nTotalAmount              // Result: 150675.00




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s