version 1.5
OP Cut named selection (connectionID; tableID; selectionName) Longint
Parameter | Type | Description | |
connectionID | Longint | Connection ID with target server | |
tableID | Longint | Number of the table in the database | |
selectionName | String | Name of the selection | |
Function result | Longint | Error code result for the function |
Description
OP Cut named selection creates a selection named selectionName and moves the current selection for tableID to it. After this routine is called, the selection in tableID becomes empty.
When you use that named selection by calling OP Use named selection, it gets deleted.
Error Codes
If OP Cut named 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 is very similar to the example for OP Copy named selection. The difference is that it lets the user create several named selections and print them in the background. Since the user will create the selections but not display them, we do not need to use OP Copy named selection to preserve the current selection. Instead, we use OP Cut named selection to avoid wasting server memory.
C_LONGINT($ErrCode;vRecords) ARRAY LONGINT(arTableID;0) ARRAY LONGINT(arFieldID;0) ARRAY TEXT(arLogOp;0) ARRAY TEXT(arQueOp;0) ARRAY TEXT(arValues;0) ARRAY STRING (0;<>arPrintRequests;0) Repeat `Display a dialog that let the user specify his criteria UserSelectInvoices ` Perform the query specified by the user $errCode := OP Multi query (<>vConnectID;2;arFileID;arFieldID;arLoglOp;arQueOp;arValues;vRecords) ` First get a unique name in the form : <>InvoicesToPrint0001 , <>InvoicesToPrint0002 ... $selectionName := "<>InvoicesToPrint" + String (Size of array (<>arPrintRequest)+1;"0000") `Append an entry to the print requests array INSERT ELEMENT (<>arPrintRequest;Size of array (<>arPrintRequest)+1;1) ` Move [Invoices] current selection into an Interprocess named selection using OP Cut instead of OP Copy ` in order to empty the current selection saving memory on the server $errCode := OP Cut named selection (<>vConnectID;2;$selectionName) <>arPrintRequest{Size of array (<>arPrintRequest)} := $selectionName Until (UserClickedPrintAndQuit=1) ...
This is a possible implementation of the BackgroundPrinter method.
` Command BackgroundPrinter Prints in the background the invoices ` designated by the <>arPrintRequest array. Print occur from the bottom. ` process is launched at startup and remains in the background waiting for requests While (True) ` loop will end on exit If (Size of array (<>arPrintRequest)=0) `If no print request available go to sleep for 10 secs DELAY PROCESS (Current process;60*10) Else ` Get the name of the selection $SelectionName := <>arPrintRequest{1} ` Remove it from the queue DELETE ELEMENT (<>arPrintRequest;1;1) ` Move the named selection at bottom of request queue to the current selection ` since named selection was created with a OP Cut calling OP Use will clear the named selection $errCode:= OP Use named selection (<>vConnectID;2;$SelectionName) If ($errCode=0) ` Count records in current selection $errCode := OP records in selection (<>vConnectID;2;vRecords) For ($i;1;vRecords) $errCode := OP Goto selected record (<>VconnectID;2;$i) PrintOneInvoice (<>vConnectID) End for End if End if End while
See Also
OP Clear named selection, OP Copy named selection, OP Single query, OP Use named selection.