version 1.5
OP Array to selection (connectionID; bindID) Longint
Parameter | Type | Description | |
connectionID | Longint | Connection ID with target server | |
bindID | Longint | Bind list ID | |
Function result | Longint | Error code result for the function |
Description
OP Array to selection copies the arrays of the bind list bindID into a selection of records. All of the fields defined by bindID must be in the same table. If there is no current selection this routine has no effect.
If a selection exists, the elements of the array are put into the records based on the order of the array and the order of the records. If there are more elements than there are records, new records are created.
If the arrays are of different sizes, the array with the smallest number of elements is used to determine how many elements will be copied.
Error Codes
If OP Array to selection executes successfully, it returns 0. Otherwise, this function returns one of the following errors:
Error Code | Description |
-108 | Not enough memory to perform this operation. |
-9969 | Invalid field type requested. |
-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. |
10135 | Invalid parameter type. |
10136 | The connection does not exist. |
10137 | The bind list does not exist. |
10138 | The bind list is not related to this file. |
10139 | The bind list is not defined. |
10153 | Unable to convert this type of data. |
10154 | This command cannot be executed right now. |
10162 | The array(s) contain no elements. |
Example
This example loads the [Customers]Gross sales into an array, adds the invoice amount of the day to each individual entry, and stores the result back to the [Customers] table.
C_LONGINT($i;$ErrCode) C_LONGINT ($custSalesBind;$invAmountBind) ARRAY REAL (aCustSales;0) ARRAY REAL (aInvAmount;0) ARRAY STRING (10;aCustID;0) ARRAY STRING (10;aInvCustID;0) ` Create a new bind list $ErrCode := OP Create bind ($custSalesBind) ` Add to the list a bind between [Customers]Gross sales (1;7) and the aCustSales array $ErrCode := $ErrCode + OP Define bind by pointer ($custSalesBind;1;7;->aCustSales) ` Add to the list a bind between [Customers]Customer ID (1;1) and the aCustID array $ErrCode := $ErrCode + OP Define bind by pointer ($custSalesBind;1;1;->aCustID) ` Create a new bind list $ErrCode := OP Create bind ($invAmountBind) ` Add to the list a bind between [Invoices]Total (2;4) and the aInvAmount array $ErrCode := $ErrCode + OP Define bind by pointer ($invAmountBind;2;4;->aInvAmount) ` Add to the list a bind between [Invoices]Customer ID (2;2) and the aInvCustID array $ErrCode := $ErrCode + OP Define bind by pointer ($invAmountBind;2;2;->aInvCustID) C_LONGINT (vRecords; $ErrCode) C_STRING (10;vValue) `Compute today's date vValue:= String ( Current date ) ` Query for invoices dated of the day $errCode:=OP Single query (vConnectID;2;3;"=";->vValue;vRecords) ` Load today's invoice amounts into the aInvAmount array $errCode:= OP Selection to array (vConnectID;$invAmountBind;2) ` Create a selection of customers for those invoices $errCode:=OP Many to one join (vConnectID;1;2) ` Load customers gross sales into the aCustSales array $errCode:= OP Selection to array (vConnectID;$custSalesBind;1) ` For each invoice For ($i;1; Size of array (aInvAmount) ) ` Find the customer's entry in the customer ID array $cust:= Find in array (aCustID;aInvCustID{$i}) If ($cust>0) ` Accumulate invoice amount into customer gross sales array entry aCustSales{$cust} := aCustSales{$cust} + aInvAmount{$i} End if End for ` Write back the gross sales values $errCode:= OP Array to selection (vConnectID;$custSalesBind)
See Also
ARRAY TO SELECTION, OP Array to selection, OP Create bind, OP Many to one join, OP Selection to array, OP Single query.