version 1.5
OP Reduce selection (connectionID; tableID; selectionSize) Longint
| Parameter | Type | Description | |
| connectionID | Longint | Connection ID with target server | |
| tableID | Longint | Number of the table in the database | |
| selectionSize | Longint | New size for the target table's current selection | |
| Function result | Longint | Error 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 Code | Description |
| -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 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.