RDD

DbTotal()

Summarize numeric fields by a key

Syntax

Signature
DbTotal( cFile, bKey, [aFields], [bFor], [bWhile], [nNext], [nRecord], [lRest] ) --> lSuccess

Arguments

cFile

Destination file. bKey Grouping block. aFields Numeric fields to total. Remaining arguments define the scope.

Return value

.T. when the summary file is created; otherwise .F..

Description

DbTotal() scans the current work area, applies its optional scope, evaluates bKey for each selected record, and combines records with equal keys. It sums the numeric fields named in aFields and writes one summary record per key to cFile. The source area stays open, while its pointer is used during the scan.

Notes

cFile must be writable and aFields must name numeric fields. Invalid blocks, scopes or structures raise an error. DbTotal() aggregates records; DbSort() only orders them and DbSum() returns one scalar without creating a file.

Example

DbTotal.prg
PROCEDURE Main()

   DbUseArea( .T., , "sales.dbf", "Sales" )
   QOut( "Total file: " + IIF( DbTotal( "sales_total.dbf", {|| FIELD->CUSTOMER }, { "AMOUNT" } ), "OK", "ERROR" ) )
   DbCloseArea()
   FErase( "sales_total.dbf" )

RETURN

Output

See also