Command SUM Foundation
Calculates sums for numeric expressions in the current work area.
Syntax
SUM <nExpression,...> TO <VarName,...> ;
[FOR <lForCondition>] ;
[WHILE <lWhileCondition>] ;
[NEXT <nCount>] ;
[REST] ;
[ALL]
Parameters
<nExpression,...>
<nExpression,...> is a comma-separated list of numeric expressions which are summed for each record.
<VarName,...>
<VarName,...> is a comma separated list of variables to contain the sum of each numeric expression from the list <nExpression,...>. The variable list <VarName,...> must be exactly as long as the expression list <nExpression,...>.
<lForCondition>
<lForCondition> is an optional logical expression which sets a condition. Only records for which <lForCondition> returns the value .T. (true) are included in the summation.
<lWhileCondition>
<lWhileCondition> is an optional logical expression which sets a condition. The summation is terminated as soon as the expression returns the value .F. (false).
<nCount>
<nCount> optionally specifies the number of records used in calculating the sum, starting with the current record.
REST
The option REST specifies whether the sum is to be calculated only for the records from the current to the last record. If a condition is specified, the option ALL is used as the default value.
ALL
The option ALL includes all records in calculating the sums. If a condition is specified, the condition is tested for all records.
Description
The command SUM calculates the sum of one or more numeric expressions from the values of the records in the current work area. The range for the summation can be limited by specifying a condition or the number of records. The sum of each numeric expression in <nExpression,...> is assigned to a variable in <VarName,...>.
Examples
// In the example, the daily sales for the month of
// June are totaled.
PROCEDURE Main
LOCAL nIncomeJune
Use Invoice NEW
SUM Payment TO nIncomeJune ;
FOR Month(InvDate) == 6
? "Sales in June:", nIncomeJune
USE
RETURN
Feedback
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.