MERGELIST()

MERGELIST()

Top  Previous  Next

 

The MERGELIST() function combines two field mark delimited sorted lists, returning the intersection, union or difference as a result list.

 

 

Format

 

MERGELIST(list1, list2, modes)

 

where

 

list1, list2are the two lists to be combined.

 

modesidentifies the operation to be performed and the manner in which the lists are sorted.

 

 

The MERGELIST() function provides an efficient way to merge two field mark delimited sorted lists. It is intended for use with lists of record ids such as select lists but can combine other lists where the elements are no more than 255 characters.

 

The modes argument must be one of the following token that are defined in the SYSCOM KEYS.H include record:

ML$INTERReturn a list of items in both list1 and list2.
ML$UNIONReturn a list of items in either list1 and list2 but not duplicating items in both lists
ML$DIFFReturn a list of items in list1 but not in list2.

 

In addition, one of the following tokens may be added to the modes value to indicate how the data in list1 and list2 is sorted:

SRT$LEFTA simple left aligned sort (default).
SRT$RIGHTA simple right aligned sort, sorting integer numeric values as numbers.
SRT$COMPOUNDA compound sort.
SRT$RIGHT.FLOATA right aligned sort, sorting both integer and floating point values as numbers.

 

For more information on the different sort modes, see the SORT() function. Note that the sort mode tokens identify how the data in list1 and list2 is sorted and also how the result list will be sorted. The result of using MERGELIST() where the input lists are not sorted in the manner specified is indeterminate.

 

 

Example

 

SELECTINDEXV 'CUSTNO', CUSTOMER FROM ORDERS.F TO CUST.ORDERS

SELECTINDEXV 'MONTH', ORDER.MONTH FROM ORDERS.F TO MONTHLY.ORDERS

JULY.ORDERS = MERGELIST(CUST.ORDERS, MONTHLY.ORDERS, ML$INTER)

 

The above example extracts data from two indices; one for all orders placed by a specific customer, the other for all orders placed in a specific month. It then uses MERGELIST() to combine these to give a list of all orders placed by that customer in the given month.