SUM

SUM

Sum numeric expressions and assign results to variables

Syntax

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

Arguments

<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.

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.

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

Examples

      .  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

Seealso

AVERAGE, DBEVAL(), TOTAL

Advertisements

COUNT

COUNT

Tally records to a variable

Syntax

      COUNT TO <idVar>
             [<scope>] [WHILE <lCondition>] [FOR <lCondition>]

Arguments

TO <idVar> identifies the variable that holds the COUNT result. A variable that either does not exist or is invisible is created as a private variable whose scope is the current procedure.

<scope> is the portion of the current database file to COUNT. The default 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 COUNT within the given scope.

Description

COUNT tallies the number of records from the current work area that match the specified record scope and conditions. The result is then placed in the specified variable. <idVar> can be a variable of any storage class including a field.

Examples

      .  This example demonstrates a COUNT of Branches in Sales.dbf:
      USE Sales NEW
      COUNT TO nBranchCnt FOR Branch = 100
      ? nBranchCnt                           // Result: 4
      .  This example tallies the number of records in Sales.dbf whose
      Branch has the value of 100 and assigns the result to the Count field
      in Branch.dbf for branch 100:
      USE Branch INDEX Branch NEW
      SEEK 100
      USE Sales INDEX SalesBranch NEW
      SEEK 100
      COUNT TO Branch->Count WHILE Branch = 100

Seealso

AVERAGE, DBEVAL(), SUM, TOTAL

AVERAGE

AVERAGE

Average numeric expressions in the current work area

Syntax

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

Arguments

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

TO <idVar list> identifies a list of receiving variables which will contain the average results. 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> defines the portion of the current database file to AVERAGE. The default scope is ALL.

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 AVERAGE within the given scope.

Description

AVERAGE calculates the average of one or more numeric expressions to variables for a range of records in the current database file. Zero values are counted in the AVERAGE unless explicitly ruled out with a FOR condition.

Examples

      .  This example averages a single numeric field using a condition
         to select a subset of records from the database file:
      USE Sales NEW
      AVERAGE Amount TO nAvgAmount FOR Branch = "100"
      .  This example finds the average date for a range of dates:
      AVERAGE (SaleDate - CTOD("00/00/00")) ;
         TO nAvgDays FOR !EMPTY(SaleDate)
      dAvgDate := CTOD("00/00/00") + nAvgDays

Seealso

DBEVAL(), SUM, TOTAL

C5_TOTAL

TOTAL
 Summarize records by key value to a database (.dbf) file
------------------------------------------------------------------------------
 Syntax

     TOTAL ON <expKey> [FIELDS <idField list>]
        TO <xcDatabase>
        [<scope>] [WHILE <lCondition>] [FOR <lCondition>]

 Arguments

     ON <expKey> defines the group of records that produce a new record
     in the target database file.  To make the summarizing operation
     accurate, the source database file should be INDEXed or SORTed on this
     expression.

     FIELDS <idField list> specifies the list of numeric fields to TOTAL.
     If the FIELDS clause is not specified, no numeric fields are totaled.
     Instead each numeric field in the target file contains the value for the
     first record matching the key expression.

     TO <xcDatabase> is the name of the target file that will contain the
     copy of the summarized records.  Specify this argument as a literal file
     name or as a character expression enclosed in parentheses.  Unless
     otherwise specified, TOTAL assumes a .dbf extension.

     <scope> is the portion of the current database file to TOTAL.  The
     default 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 TOTAL
     within the given scope.

 Description

     TOTAL is a database command that sequentially processes the current
     database file, summarizing records by the specified key value and
     copying them to a new database file.  TOTAL works by first copying the
     structure of the current database file to <xcDatabase>, except for memo
     fields.  It then sequentially scans the current database file within the
     specified scope of records.  As each record with a unique <expKey> value
     is encountered, that record is copied to the new database file.  The
     values of numeric fields specified in <idField list> from successive
     records with the same <expKey> value are added to fields with the same
     names in <xcDatabase>.  Summarization proceeds until a record with a new
     key value is encountered.  The process is then repeated for this record.

     Since TOTAL processes the source database file sequentially, it must be
     INDEXed or SORTed in <expKey> order for the summarization to be correct.

     To successfully TOTAL numeric fields, the source numeric fields must be
     large enough to hold the largest total possible for that numeric field.
     If not, a runtime error is generated.

 Notes

     .  Deleted source records:  If DELETED is OFF, deleted records in
        the source file are TOTALed.  Records in the target <xcDatabase>
        inherit the deleted status of the first matching record in the source
        file, just as nontotaled fields inherit their values.  If DELETED is
        ON, however, none of the deleted source records are TOTALed.

 Examples

     .  In this example, a database file is TOTALed ON the key
        expression of the controlling index using a macro expression.  When
        the macro expression is encountered, the expression is evaluated and
        the resulting character string is substituted for the TOTAL <expKey>
        argument:

        USE Sales INDEX Branch NEW
        TOTAL ON &(INDEXKEY(0)) FIELDS Amount TO Summary

 Files   Library is CLIPPER.LIB.

See Also: AVERAGE INDEX SORT SUM



C5 Commands

 ?|??            Display one or more values to the console
 @...BOX         Draw a box on the screen
 @...CLEAR       Clear a rectangular region of the screen
 @...GET         Create a new Get object and display it
 @...PROMPT      Paint a menu item and define a message
 @...SAY         Display data at a specified screen or printer row and column
 @...TO          Draw a single- or double-line box
 ACCEPT*         Place keyboard input into a memory variable
 APPEND BLANK    Add a new record to the current database file
 APPEND FROM     Import records from a database (.dbf) file or ASCII text file
 AVERAGE         Average numeric expressions in the current work area
 CALL*           Execute a C or Assembler procedure
 CANCEL*         Terminate program processing
 CLEAR ALL*      Close files and release public and private variables
 CLEAR GETS      Release Get objects from the current GetList array
 CLEAR MEMORY    Release all public and private variables
 CLEAR SCREEN    Clear the screen and return the cursor home
 CLEAR TYPEAHEAD Empty the keyboard buffer
 CLOSE           Close a specific set of files
 COMMIT          Perform a solid-disk write for all active work areas
 CONTINUE        Resume a pending LOCATE
 COPY FILE       Copy a file to a new file or to a device
 COPY STRUCTURE  Copy the current .dbf structure to a new database (.dbf) file
 COPY STRU EXTE  Copy field definitions to a .dbf file
 COPY TO         Export records to a database (.dbf) file or ASCII text file
 COUNT           Tally records to a variable
 CREATE          Create an empty structure extended (.dbf) file
 CREATE FROM     Create a new .dbf file from a structure extended file
 DELETE          Mark records for deletion
 DELETE FILE     Remove a file from disk
 DELETE TAG      Delete a tag
 DIR*            Display a listing of files from a specified path
 DISPLAY         Display records to the console
 EJECT           Advance the printhead to top of form
 ERASE           Remove a file from disk
 FIND*           Search an index for a specified key value
 GO              Move the pointer to the specified identity
 INDEX           Create an index file
 INPUT*          Enter the result of an expression into a variable
 JOIN            Create a new database file by merging from two work areas
 KEYBOARD        Stuff a string into the keyboard buffer
 LABEL FORM      Display labels to the console
 LIST            List records to the console
 LOCATE          Search sequentially for a record matching a condition
 MENU TO         Execute a lightbar menu for defined PROMPTs
 NOTE*           Place a single-line comment in a program file
 PACK            Remove deleted records from a database file
 QUIT            Terminate program processing
 READ            Activate full-screen editing mode using Get objects
 RECALL          Restore records marked for deletion
 REINDEX         Rebuild open indexes in the current work area
 RELEASE         Delete public and private memory variables
 RENAME          Change the name of a file
 REPLACE         Assign new values to field variables
 REPORT FORM     Display a report to the console
 RESTORE         Retrieve memory variables from a memory (.mem) file
 RESTORE SCREEN* Display a saved screen
 RUN             Execute a DOS command or program
 SAVE            Save variables to a memory (.mem) file
 SAVE SCREEN*    Save the current screen to a buffer or variable
 SEEK            Search an order for a specified key value
 SELECT          Change the current work area
 SET ALTERNATE   Echo console output to a text file
 SET BELL        Toggle sounding of the bell during full-screen operations
 SET CENTURY     Modify the date format to include or omit century digits
 SET COLOR*      Define screen colors
 SET CONFIRM     Toggle required exit key to terminate GETs
 SET CONSOLE     Toggle console display to the screen
 SET CURSOR      Toggle the screen cursor on or off
 SET DATE        Set the date format for input and display
 SET DECIMALS    Set the number of decimal places to be displayed
 SET DEFAULT     Set the CA-Clipper default drive and directory
 SET DELETED     Toggle filtering of deleted records
 SET DELIMITERS  Toggle or define GET delimiters
 SET DESCENDING  Change the descending flag of the controlling order
 SET DEVICE      Direct @...SAYs to the screen or printer
 SET EPOCH       Control the interpretation of dates with no century digits
 SET ESCAPE      Toggle Esc as a READ exit key
 SET EXACT*      Toggle exact matches for character strings
 SET EXCLUSIVE*  Establish shared or exclusive USE of database files
 SET FILTER      Hide records not meeting a condition
 SET FIXED       Toggle fixing of the number of decimal digits displayed
 SET FORMAT*     Activate a format when READ is executed
 SET FUNCTION    Assign a character string to a function key
 SET INDEX       Open one or more order bags in the current work area
 SET INTENSITY   Toggle enhanced display of GETs and PROMPTs
 SET KEY         Assign a procedure invocation to a key
 SET MARGIN      Set the page offset for all printed output
 SET MEMOBLOCK   Change the block size for memo files
 SET MESSAGE     Set the @...PROMPT message line row
 SET OPTIMIZE    Change the setting that optimizes using open orders
 SET ORDER       Select the controlling order
 SET PATH        Specify the CA-Clipper search path for opening files
 SET PRINTER     Toggle echo of output to printer or set the print destination
 SET PROCEDURE*  Compile procedures and functions into the current object file
 SET RELATION    Relate two work areas by a key value or record number
 SET SCOPE       Change the boundaries for scoping keys in controlling order
 SET SCOPEBOTTOM Change bottom boundary for scoping keys in controlling order
 SET SCOPETOP    Change top boundary for scoping keys in controlling order
 SET SCOREBOARD  Toggle the message display from READ or MEMOEDIT()
 SET SOFTSEEK    Toggle relative seeking
 SET TYPEAHEAD   Set the size of the keyboard buffer
 SET UNIQUE*     Toggle inclusion of non-unique keys into an index
 SET WRAP*       Toggle wrapping of the highlight in menus
 SKIP            Move the record pointer to a new position
 SORT            Copy to a database (.dbf) file in sorted order
 STORE*          Assign a value to one or more variables
 SUM             Sum numeric expressions and assign results to variables
 TEXT*           Display a literal block of text
 TOTAL           Summarize records by key value to a database (.dbf) file
 TYPE            Display the contents of a text file
 UNLOCK          Release file/record locks set by the current user
 UPDATE          Update current database file from another database file
 USE             Open an existing database (.dbf) and its associated files
 WAIT*           Suspend program processing until a key is pressed
 ZAP             Remove all records from the current database file

 

Clipper and Networking

Clipper and Networking

C5 Database Commands

Database Commands and Statements

APPEND BLANK

Add a new record to current database file.

APPEND BLANK

APPEND FROM :

Import records from a (.dbf) or ASCII file

APPEND FROM <xcFile>
     [FIELDS <idField list>]
     [<scope>] 
     [WHILE <lCondition>] 
     [FOR <lCondition>]
     [SDF | DELIMITED [WITH BLANK | <xcDelimiter>] |
     [VIA <xcDriver>]]

AVERAGE :

Average numeric expressions in the current work area

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

CLEAR ALL* :

Close files and release public and private variables.

CLEAR ALL

CLOSE :

Close a specific set of files

CLOSE [<idAlias> | ALL | ALTERNATE | DATABASES | FORMAT |INDEXES ]

COMMIT :

Perform a solid-disk write for all active work areas

COMMIT

CONTINUE :

Resume a pending LOCATE

CONTINUE

COPY STRUCTURE :

Copy the current (.dbf) structure to a new (.dbf) file

COPY STRUCTURE [FIELDS <idField list>] TO <xcDatabase>

COPY STRUCTURE EXTENDED :

Copy field definitions to a (.dbf) file

COPY STRUCTURE EXTENDED TO <xcExtendedDatabase>

COPY TO :

Export records to a new (.dbf) or ASCII file

COPY [FIELDS <idField list>] TO <xcFile>
     [<scope>] 
     [WHILE <lCondition>] 
     [FOR <lCondition>]
     [SDF | DELIMITED [WITH BLANK | <xcDelimiter>] |
     [VIA <xcDriver>]]

COUNT :

Tally records to a variable

COUNT TO <idVar>
     [<scope>] 
     [WHILE <lCondition>] 
     [FOR <lCondition>]

CREATE :

Create an empty structure extended (.dbf) file

CREATE <xcExtendedDatabase>

CREATE FROM :

Create a new (.dbf) file from a structure extended file

CREATE <xcDatabase> 
    FROM <xcExtendedDatabase> 
    [NEW]
    [ALIAS <xcAlias>] 
    [VIA <cDriver>]

DELETE :

Mark records for deletion

DELETE [<scope>] 
    [WHILE <lCondition>]
    [FOR <lCondition>]

FIELD :

Declare database field names

FIELD <idField list> [IN <idAlias>]

FIND* :

Search an index for a specified key value

FIND <xcSearchString>

GO :

Move the record pointer to a specific record

GO[TO] <nRecord> | BOTTOM | TOP

JOIN :

Merge two (.dbf) files to create a new (.dbf) file

JOIN WITH <xcAlias> TO <xcDatabase>
     FOR <lCondition> 
     [FIELDS <idField list>]

LOCATE :

Search sequentially for a record matching a condition

LOCATE [<scope>] 
    FOR <lCondition>
    [WHILE <lCondition>]

PACK :

Remove deleted records from a database file

PACK

RECALL :

Restore records marked for deletion

RECALL [<scope>] 
     [WHILE <lCondition>]
     [FOR <lCondition>]

REPLACE :

Assign new values to field variables

REPLACE <idField> WITH <exp>
    [, <idField2> WITH <exp2>...]
    [<scope>] 
    [WHILE <lCondition>] 
    [FOR <lCondition>]

SEEK :

Search an index for a specified key value

SEEK <expSearch>

SELECT :

Change the current work area

SELECT <xnWorkArea> | <idAlias>

SET DELETED :

Toggle filtering of deleted records

SET DELETED on | OFF | <xlToggle>

SET EXCLUSIVE :

Establish shared or exclusive USE of database files

SET EXCLUSIVE ON | off | <xlToggle>

SET FILTER :

Hide records not meeting a condition

SET FILTER TO [<lCondition>]

SET  MEMOBLOCK :

     Change the block size for memo files

     SET MEMOBLOCK TO <nSize>

SET PATH :

Specify the search path for opening files

SET PATH TO [<xcPathspec list>]

SET RELATION :

Relate two work areas by a key value or record number

SET RELATION TO [<expKey> | <nRecord> INTO <xcAlias>]
    [, [TO] <expKey2> | <nRecord2> INTO <xcAlias2>...]
    [ADDITIVE]

SET SOFTSEEK :

Toggle relative SEEKing

SET SOFTSEEK on | OFF | <xlToggle>

SET UNIQUE :

Toggle the inclusion of nonunique keys into an index

SET UNIQUE on | OFF | <xlToggle>

SKIP :

Move the record pointer to a new position

SKIP [<nRecords>] [ALIAS <idAlias> | <nWorkArea>]

SORT :

Copy to a (.dbf) file in sorted order

SORT TO <xcDatabase> ON <idField> [/[A | D][C]]
    [, <idField2> [/[A | D][C]]...]
    [<scope>] 
    [WHILE <lCondition>] 
    [FOR <lCondition>]

SUM :

Sum numeric expressions to variables

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

TOTAL

Summarize records by key value to a (.dbf) file

TOTAL ON <expKey> FIELDS <idField list>
    TO <xcDatabase>
    [<scope>] 
    [WHILE <lCondition>] 
    [FOR <lCondition>]

UNLOCK :

Release file/record locks set by the current user

     UNLOCK [ALL]

UPDATE : 

Update current database file from another database file

UPDATE FROM <xcAlias>
   ON <expKey> [RANDOM]
   REPLACE <idField> WITH <exp>
   [, <idField2> WITH <exp2>...]

USE

Open an existing (.dbf) and its associated files

USE [<xcDatabase>
    [INDEX <xcIndex list>]
    [ALIAS <xcAlias>] 
    [EXCLUSIVE | SHARED]
    [NEW] [READONLY]
    [VIA <cDriver>]]

ZAP

Remove all records from the current database file

ZAP