version 1.5
OP Sum (connectionID; tableID; fieldID; result) Longint
Parameter | Type | Description | |
connectionID | Longint | Connection ID with target server | |
tableID | Longint | Number of the table in the database | |
fieldID | Longint | Number of the field in the table | |
result | Variable | Sum of the values in field for the current selection | |
Function result | Longint | Error 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 Code | Description |
-9969 | Invalid field type requested (field type is not Longint, Integer, Time, or Real). |
-9971 | Field number is out of range. |
-9972 | Table number is out of range. |
10128 | The 4D Open for 4th Dimension package has not been initialized. |
10136 | The connection does not exist. |
10154 | This 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