RTI_Sets function

RTI_SETS is a function that performs union, intersection and difference of delimited sets of row data. The function has 9 calling modes that allow it to create, add data to, intersect, union, difference, extract data from, and clear sets. The parameters for each calling mode are specific to the calling mode.

result = RTI_Sets( code, param1, param2, param3 )

The function has the following parameters:

ParameterDescription
codeThe possible codes to pass to the RTI_SETS function are:

Value (IDX Equates) - Description
1 (INIT_SET$) - Initializes a set returning a set handle.
2 (ADD_TO_SET$) - Adds data to an existing set returning an error code.
3 (UNION_SET$) - Creates a union of two sets returning a set handle.
4 (INTERSECT_SETS$) - Creates a results set of intersecting values from two sets returning a set handle.
5 (DIFFERENCE_SETS$) - Creates a results set of differing values from two sets returning a set handle.
6 (RESET_EXTRACT$) - Resets the extract parameters.
7 (EXTRACT_FROM_SET$) - Extracts the row data from a set returning an error code.
Returns 1 if more data exists in the set, 0 if all data has been extracted, or an error code (a negative integer). Parameter1 is the handle. A variable is passed in param2; it is filled with data by Set_Lib on "no error". If desired, the 3rd parameter specifies the delimiter to use between result values.

8 (SET_INFO$) - Reports data about a set.
9 (CLEAR_SET$) - Destroys the set and removes the handle from storage.
param1The parameters are based on the code selected. The first parameter for each code is outlined below.

Code - Param Value: Description
1 - A set of data.
2 - A set of data.
3 - A handle to a set: The handle of the 1st set to be used in the union.
4 - A handle to a set: The handle of the 1st set to be used in the intersection.
5 - A handle to a set: The handle of the 1st set to be used in the comparison.
6 - A handle to a set.
7 - A handle to a set: The handle of the set to be extracted.
8 - A handle to a set.
9 - A handle to a set: The handle to be removed.
param2The parameters are based on the code selected. The second parameter for each code is outlined below.

Code - Param Value: Description
1 - 0 (zero): The parameter should always be zero. If a non-zero value is passed to RTI_SETS for INIT, then a handle will not be created.
2 - A handle to a set: The parameter should be the HANDLE of the set to which data should be added.
3 - A handle to a set: The handle of the 2nd set to be used in the union.
4 - A handle to a set: The handle of the 2nd set to be used in the intersection.
5 - A handle to a set: The handle of the 2nd set to be used in the comparison.
6 - The reset specification.
7 - <Output> Variable: The operation returns the data in this parameter, if the operation was successful.
8 - <Output> Variable: Returns the count of all rows in set.
9 - NA
param3The parameters are based on the code selected. The first parameter for each code is outlined below.

Code - Param Value: Description
1 - Delimiter: The value of the delimiter used to separate the data in param1.
2 - NA
3 - NA
4 - NA
5 - NA
6 - A handle to a set.
7 - (Optional) Delimiter: The value of the delimiter to use to separate the data returned in param2.
8 - <Output> Variable: The count of index rows in the set.
9 - NA
CodeReturn Value
1<Integer>
A positive integer is returned if the operation was successful and a new set was created. The positive integer is the new set's Handle.
A negative integer is an error code.
20 (zero) if successful
< 0 (less than zero) if unsuccessful
3<Integer>
A positive integer is returned if the operation was successful and a new set was created. The positive integer is the new set's Handle.
A negative integer is an error code.
4<Integer>
A positive integer is returned if the operation was successful and a new set was created. The positive integer is the new set's Handle.
A negative integer is an error code.
5<Integer>
A positive integer is returned if the operation was successful and a new set was created. The positive integer is the new set's Handle.
A negative integer is an error code.
60 (zero) if successful
< 0 (less than zero) if unsuccessful
7<Integer>
0 (zero) is returned if all data has been extracted from the set.
1 is returned if there is more data to be extracted from the set.
A negative integer is an error code.
8<Output> The count of index rows in the set.
90 (zero). Always.

Always call the CLEAR_SET$ method when finished using a set. Clearing a set releases the memory it was using.

Note: When calling the DIFFERENCE_SETS$ method, the second set is "subtracted" from the first set. The difference of the two sets is formed by the elements that are present in the first set, but not in the second one. The elements copied by the function come always from the first range, in the same order.

For more information on set operations, see this discussion.

The Examples below use the following equate values from IDX.SETS.EQU:

Equ INIT_SET$           To  1          ;* Initializes a set returning a
Equ ADD_TO_SET$         To  2          ;* Adds data to an existing set.  Returns
Equ UNION_SETS$         To  3          ;* Performs the union of two sets
Equ INTERSECT_SETS$     To  4          ;* Performs the intersection of two
Equ DIFFERENCE_SETS$    To  5          ;* Performs the difference of two
Equ RESET_EXTRACT$      To  6          ;* Sets the extract parameters (restart
Equ EXTRACT_FROM_SET$   To  7          ;* Extracts row data from a set.  Returns
Equ SET_INFO$           To  8          ;* Reports data about a set.
Equ CLEAR_SET$          To  9          ;* Clears a set_handle from the library's

Initialize A Set

     * Get a unique list of products for a selected list of orders
     
     
     Declare Function rti_Sets
     $Insert IDX_SETS.EQU
     $Insert logical
     
     result =  null$
     
     * Initialize the set
     spec = IS_UNIQUE$ + IS_SORTED$
     items = ""
     hSet =  RTI_SETS( INIT_SET$, items, spec)
     If hset < 1 Then
          err = 'Unable to initialize RTI_SETS':@vm:'Please run the OpenInsight Client Install on this Machine'
          status = false$
          Call Msg(@window, err)
     End
     
     * Add the multivalues from all of the selected records
     done = false$
     Loop
     Readnext id Else done = true$
     Until done        
         items = Xlate('ORDERS', id, 'PRODUCTS', 'X')
         Convert @vm To @fm In items  ; * Lists need to be @fm delimited
         If items != "" then
            unused = RTI_SETS( ADD_TO_SET$, items, hSet)
         end
     repeat
     
     * load the distinct list of items in result
     ret = RTI_SETS( EXTRACT_FROM_SET$,  hSet, result)
     
     * release the memory
     ret = RTI_SETS( CLEAR_SET$, hSet)

     
Return result
     /*
     * Given two lists OLDLIST and NEWLIST, where NEWLIST comprises OLDLIST with some new items added and some existing items deleted,
     * find which items were added to NEWLIST, and which items were removed

     * Approach
     * Use the diff operation
     * Diff(oldList,newList) returns the items remaining in oldList after removing items which are in newList
     */

     Declare Function rti_Sets
     $Insert IDX_SETS.EQU
     $Insert logical

     * Make some test data
     oldList = 'A,B,C,D,E,F,G'
     newList = 'A,C,E,I,J,K,L'
     Convert ',' To @vm In oldList
     Convert ',' To @vm In newList
     
     * Initialize the sets for vm delimited data
     spec = IS_UNIQUE$ + IS_SORTED$
     delimiter = @vm
     hOld=  RTI_SETS( INIT_SET$, oldList, spec ,delimiter)
     hNew=  RTI_SETS( INIT_SET$, newList,  spec,delimiter)

     * To find the new items, use diff(NEWLIST, OLDLIST). 
     * The result is a set containing items which are only in NEWLIST, so the added items
     hAdded = RTI_SETS( DIFFERENCE_SETS$, hNew, hOld)

     * get the values from the added set
     addedItems = ""
     stat = RTI_SETS( EXTRACT_FROM_SET$, hAdded,  addedItems)


     * to find the deleted items, use diff(OLDLIST,NEWLIST).
     * The result is a set containing items which are only in OLDLIST, so the deleted items
     hRemoved = RTI_SETS( DIFFERENCE_SETS$, hOld,hNew)

     * get the values from the removed set
     removedItems = ""
     stat = RTI_SETS( EXTRACT_FROM_SET$, hRemoved, removedItems)
     
     * Release the memory used by each of the sets
     stat = RTI_SETS( CLEAR_SET$, hOld)
     stat = RTI_SETS( CLEAR_SET$, hNew)
     stat = RTI_SETS( CLEAR_SET$, hAdded)
     stat = RTI_SETS( CLEAR_SET$, hRemoved)

     result = addedItems:@fm:removedItems
  • guides/programming/programmers_reference_manual/rti_sets.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1