Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Mach SIx v1.1c - Reference Guide - <b>sum - sum numeric variables in database</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  SUM              - Sum numeric variables in database
-------------------------------------------------------------------------------

  Syntax:

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


  Arguments:

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

  <idVar list> identifies the receiving variables to 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.  Mach SIx only supports the ALL scope.

  WHILE <lCondition> specifies the set of records meeting the condition
  from the current record until the condition fails.  Mach SIx does not
  support the WHILE condition.

  FOR <lCondition> specifies the conditional set of records to SUM within
  the given scope.  Mach SIx will optimize any FOR condition that contains
  one or more active index keys.

  NOOPTIMIZE, preempts optimization and forces default Clipper processing.

  Description:

  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.

  The SUM command may be optimized by specifying one or more active index
  keys in the FOR condition.  Note that Mach SIx will only optimize a SUM
  with a FOR condition and a scope of ALL.  WHILE conditions and alternate
  scopes cannot be optimized by Mach SIx.

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

  ---------------------------------| EXAMPLE |--------------------------------
  /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  *  Demonstrates optimized SUM command                                     *
  *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

  #include "DBFSIX.CH"
  #include "MACHSIX.CH"

  LOCAL nSum:=0

  USE Account VIA "DBFSIX"  // Structural index ACCOUNT.CDX opened
                            // automatically
  CLEAR SCREEN
  ? "Example of an optimized SUM command."
  ?

  // Fully optimized sum of income, taking advantage
  // of the STATE index tag
  SUM Income TO nSum FOR account->STATE = "CA" .or. State = "FL"
  CLOSE ALL



See Also: COUNT TOTAL

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson