!SORT() |
![]() ![]() ![]() |
The !SORT() subroutine sorts the elements of a dynamic array according to a specified sorting rule.
Format
CALL !SORT(in.list, out.list, sort.rule)
where
Invalid or conflicting sort.rule elements are ignored.
The !SORT() subroutine sorts elements of in.list into the order defined by sort.rule, returning the sorted list in out.list. The value of in.list is not changed unless it refers to the same variable as out.list.
Right aligned sorts should normally be used when sorting numeric data.
Example
CUSTOMER.LIST = "" SELECT INVOICES LOOP READNEXT ID ELSE EXIT READ INVOICE.REC FROM INVOICES, ID THEN CUSTOMER.LIST<-1> = INVOICE.REC<CUSTOMER.NAME> END REPEAT CALL !SORT(CUSTOMER.LIST, CUSTOMER.LIST, "AU")
The above program fragment reads all the records from the INVOICE file and builds a list of customer names. This is then sorted, removing duplicates.
This approach will be faster than using LOCATE and INS to build a sorted list unless there are a very large number of duplicates. |