OP Reduce selection

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 Reduce selection (connectionID; tableID; selectionSize) Longint

ParameterTypeDescription
connectionIDLongintConnection ID with target server
tableIDLongintNumber of the table in the database
selectionSizeLongintNew size for the target table's current selection
Function resultLongintError code result for the function

Description

OP Reduce selection creates a new selection of records for table tableID. The new selection contains the first selectionSize records from previous current selection in table tableID.

If selectionSize is greater than the number of records in the current selection, all the records in the selection are selected.

Error Codes

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

Error CodeDescription
-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 finds the average amount of the top ten invoices of last year.

   C_LONGINT(vRecords; $ErrCode)
   C_REAL(vValue;vMeanAmount)
   C_LONGINT(vTable;vFieldDate;vFieldAmount)

   $errCode:=OP Get one field number (vConnectID;"[Invoices]Invoice date";vTable;vFieldDate)   
   $errCode:=OP Get one field number (vConnectID;"[Invoices]Invoice amount";vTable;vFieldAmount)
   
      `Compute last year's 1st of January
   vValue:="01/01/" + String ( year of ( Current date ) -1;"####") 
 
      ` Query for last year's invoices
   $errCode:=OP Single query (vConnectID;vTable;vFieldDate;">";->vValue;vRecords)

      `Order by decreasing amount (largest amount is first of selection)
   $errCode:=OP Single order by (vConnectID;vTable;vFieldAmount;"<") 
   
      ` Focus on the 10 largest invoices
   $errCode:=OP Reduce selection (vConnectID;vTable;10)

      `compute mean value
   $errCode:=OP Sum (vConnectID;vTable;vFieldAmount;vMeanAmount)

   ALERT (" Mean value for last year's top ten invoices is :"+ String (vMeanAmount;"### ### ###.##"))

See Also

OP All records, OP Records in selection, OP Single order by, OP Single query, REDUCE SELECTION.


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