Command TOTAL Foundation
Sums data from numeric fields of a work area into a second file.
TOTAL ON <IndexKey> FIELDS <cFieldname,...> TO <cFilename> ; [FOR <lForCondition>] ; [WHILE <lWhileCondition>] ; [NEXT <nCount>] ; [RECORD <xRecordID>] ; [REST] ; [ALL]
The command TOTAL generates a file which has the same structure as the file open in the current work area. The exception is memo fields, which are not included in the new file. All records in the current work area are processed sequentially. Each record where the key value <IndexKey> changes is copied to the new file. Also, the numeric values of the fields in the list <cFieldname,...> are summed in the corresponding fields of the new file until the key word changes again or a condition is no longer fulfilled.
A correct sum can only occur when the records in the current work area are sorted by the key <IndexKey>. This occurs via an index (logical sorting) or by the file being physically sorted beforehand using the command SORT. It should also be noted that the length of the numeric fields must be large enough to hold the result. Otherwise, a runtime error is caused by the numeric overflow.
records marked for deletion are considered when SET DELETED is set to OFF. If the first record with a new key value (which does not yet exist in the new file) is marked for deletion, this deletion mark is copied into the new file. records with "Deleted" status are not included when SET DELETED is set to ON.
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.