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

DISPLAY

DISPLAY

Display records to the console

Syntax

      DISPLAY <exp list>
             [TO PRINTER] [TO FILE <xcFile>]
             [<scope>] [WHILE <lCondition>]
             [FOR <lCondition>] [OFF]

Arguments

<exp list> is the list of values to display for each record processed.

TO PRINTER echoes output to the printer.

TO FILE <xcFile> echoes output to the indicated file which can be specified either as a literal file name or as a character expression enclosed in parentheses. If an extension is not specified, .txt is added.

<scope> is the portion of the current database file to DISPLAY. The default is the current record, or NEXT 1. If a condition is specified, the scope becomes 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 DISPLAY within the given scope.

OFF suppresses the display of the record number.

Description

DISPLAY is a database command that sequentially accesses records in the current work area, sending the results of the <exp list> to the console in a tabular format with each column separated by a space. The command does not display column headers or pause at predetermined intervals. DISPLAY is identical to LIST with the exception that its default scope is NEXT 1 rather than ALL.

When invoked, output is sent to the screen and optionally to the printer and/or a file. To suppress output to the screen while printing or echoing output to a file, SET CONSOLE OFF before the DISPLAY command line.

Notes

. Interrupting output: To let the user interrupt the processing of a DISPLAY command, using the INKEY() function, add a test for the interrupt key press to the FOR condition. See the example below. . Printer margin: Since DISPLAY is a console command, it honors the current SET MARGIN for output echoed to the printer.

Examples

      .  This example illustrates a simple DISPLAY, and a conditional
      DISPLAY to the printer:
      USE Sales NEW
      DISPLAY DATE(), TIME(), Branch
      DISPLAY Branch, Salesman FOR Amount > 500 TO PRINTER
      .  This example interrupts a DISPLAY using INKEY() to test
      whether the user pressed the Esc key:
      #define K_ESC  27
      USE Sales INDEX SalesMan NEW
      DISPLAY Branch, Salesman, Amount WHILE ;
         INKEY() != K_ESC

Seealso

DBEVAL(), INKEY(), LIST, SET MARGIN

DELETE

DELETE

Mark records for deletion

Syntax

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

Arguments

<scope> is the portion of the current database file to DELETE. If a scope is not specified, DELETE acts only on the current record. If a conditional clause is specified, the default becomes 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 DELETE within the given scope.

Description

DELETE is a database command that tags records so they can be filtered with SET DELETED ON, queried with DELETED(), or physically removed from the database file with PACK. In addition, display commands such as LIST and DISPLAY identify deleted records with an asterisk (*) character. Once records are deleted, you can reinstate them by using RECALL. If you want to remove all records from a database file, use ZAP instead of DELETE ALL and PACK.

Any deleted record can be recalled as long as the PACK or ZAP command has not been issued. Once the PACK or ZAP command has been issued, the deleted data cannot be retrieved.

In a network environment, DELETE requires the current record be locked with RLOCK() if you are deleting a single record. If you are deleting several records, the current database file must be locked with FLOCK() or USEed EXCLUSIVEly. Refer to the “Network Programming” chapter in the Programming and Utilities Guide for more information.

Notes

. DELETE with SET DELETED ON: If the current record is deleted with SET DELETED ON, it will be visible until the record pointer is moved.

Examples

      .  This example demonstrates use of the FOR clause to mark a set
         of records for deletion:
      USE Sales INDEX Salesman NEW
      DELETE ALL FOR Inactive

Seealso

DBEVAL(), DELETED(), FLOCK(), PACK, RECALL, RLOCK()

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

Harbour All Functions – D

Date()
Day()
Days()

DaysInMonth()
DaysToMonth()

dbAppend()
dbClearFilter()
dbCloseAll()
dbCloseArea()
dbCommit()
dbCommitAll()
dbCreate()
dbDelete()
dbEval()
dbF()
dbFilter()
dbGoBottom()
dbGoTo()
dbGoTop()
dbReCall()
dbRLock()
dbRLockList()
dbRUnlock()
dbSeek()
dbSelectArea()
dbSetDriver()
dbSetFilter()
dbSkip()
dbSkipper()
dbStruct()
dbUnlock()
dbUnlockAll()
dbUseArea()

DecToBin()
DecToHexa()
DecToOctal()

Deleted()
Descend()
DevOutPict()
DirChange()
DirRemove()
DiskSpace()

DMY()
Do()
DoW()

DOY
DToC()

DToR
DToS()

Harbour Database Functions

Database Functions

AFields Fills referenced arrays with database field information
Alias Returns the alias name of a work area
BOF Test for the beggining-of-file condition
dbAppend Appends a new record to a database file
dbClearFilter Clears the current filter condiction in a work area
dbCloseAll Close all open files in all work areas.
dbCloseArea Close a database file in a work area
dbCommit Updates all index and database buffers for a given workarea
dbCommitAll Flushes the memory buffer and performs a hard-disk write
dbCreate Creates an empty database from a array
dbDelete Mark a record for deletion in a database
dbEval Performs a code block operation on the current Database
DBF Alias name of a work area
dbFilter Return the filter expression in a work area
dbGoBottom Moves the record pointer to the bottom of the database
dbGoto Position the record pointer to a specific location
dbGoTop Moves the record pointer to the top of the database
dbRecall Recalls a record previousy marked for deletion
dbSeek Searches for a value based on an active index
dbSelectArea Change to another work area
dbSetDriver Establishes the RDD name for the selected work area
dbSetFilter Establishes a filter condition for a work area
dbSkip Moves the record pointer in the selected work area
dbSkipper Helper function to skip a database
dbStruct Builds a multidimensional array of a database structure
dbUseArea Opens a work area and uses a database file
Deleted Tests the record’s deletion flag
EOF Test for end-of-file condition
FCount Counts the number of fields in an active database
FieldDeci Determines the number of decimal places of a given numeric field
FieldGet Obtains the value of a specified field
FieldName Return the name of a field at a numeric field location
FieldPos Return the ordinal position of a field
FieldPut Set the value of a field variable
FieldSize Determines the size of a given field
FieldType Determines the type of a given field
Found Determine the success of a previous search operation
Header Return the length of a database file header
LastRec Returns the number of records in an active work area or database
LUpdate Yields the date the database was last updated
RecCount Counts the number of records in a database
RecNo Returns the current record number or identity
RecSize Returns the size of a single record in an active database
Select Returns the work area number for a specified alias
Used Checks whether a database is in use in a work area