OP Sum

4D - Documentation   Français   English   German   4D Open for 4D, Command Theme List   4D Open for 4D, Command Alphabetical List   Back   Previous   Next

version 1.5


OP Sum (connectionID; tableID; fieldID; result) Longint

ParameterTypeDescription
connectionIDLongintConnection ID with target server
tableIDLongintNumber of the table in the database
fieldIDLongintNumber of the field in the table
resultVariableSum of the values in field for the current selection
Function resultLongintError code result for the function

Description

OP Sum returns the sum of all the values for fieldID in the current selection in result. If fieldID is an indexed field the index is used to sum the values (i.e. the response time is shorter).

Error Codes

If OP Sum executes successfully, it returns 0. Otherwise, this function returns one of the following errors:

Error CodeDescription
-9969Invalid field type requested (field type is not Longint, Integer, Time, or Real).
-9971Field number is out of range.
-9972Table number is out of range.
10128The 4D Open for 4th Dimension package has not been initialized.
10136The connection does not exist.
10154This command cannot be executed right now.

Example

This example presents the user with a message displaying the amount of the smallest invoice of the day, the largest amount, the average amount and the total sales fo the day.

   C_LONGINT (vTable;vFieldAmount;vFieldDate;$errCode;vRecords)
   C_STRING (10;vValue)
   C_REAL (vAverage;vMax;vMin;vSum)

   ` Get table and field IDs 
   $errCode:=OP Get one field number (vConnectID;"[Invoices]Total";vTable;vFieldAmount)
   $errCode:=OP Get one field number (vConnectID;"[Invoices]Invoice date";vTable;vFieldDate)

   ` Compute today's date
   vValue:= String ( Current date )
   ` Make a selection of today's invoices
   $errCode:=OP Single query selection (vConnectID;vTable;vFieldDate;"=";»vValue;vRecords)

   ` Get total amount
   $errCode := $ErrCode + OP Sum (vConnectID;vTable;vFieldAmount;vSum)

   ` Get smallest amount
   $errCode := $ErrCode + OP Min (vConnectID;vTable;vFieldAmount;vMin)

   ` Get largest amount
   $errCode := $ErrCode + OP Max (vConnectID;vTable;vFieldAmount;vMax)

   ` Get average amount
   $errCode := $ErrCode + OP Average (vConnectID;vTable;vFieldAmount;vAverage)

   If ($ErrCode=0)
      $mes := " Today' results are " + Char (Carriage return)
      $mes := $mes + "   smallest invoice : " + String (vMin;"### ###.00 ) + Char (Carriage return)
      $mes := $mes + "   largest invoice   : " + String (vMax;"### ###.00 ) + Char (Carriage return)
      $mes := $mes + "   average invoice  : " + String (vAverage;"### ###.00 ) + Char (Carriage return)
      $mes := $mes + "   total invoiced     : " + String (vSum;"### ###.00 )
      ALERT ($mes)
   End if 

See Also

OP Average, OP Max, OP Min.


4D - Documentation   Français   English   German   4D Open for 4D, Command Theme List   4D Open for 4D, Command Alphabetical List   Back   Previous   Next