logo
Powered by QM on a Rpi server
Home
About OpenQM
Sales and Downloads
Help and Support
About
Login

KnowledgeBase 00085: Sorting Dynamic Arrays

Last updated: 22 Jul 2016
Applies to: All versions
Search  
Top level index       Full Index Search Tips
Previous article     Next article

This article was originally published as a Tip of the Week.

There is frequently a need to sort a list of items that is held in a dynamic array. The !SORT() subroutine provides this functionality.


The !SORT() Subroutine

The subroutine is called as
   CALL !SORT(in.list, out.list, sort.rule) 
where
in.list The dynamic array to be sorted. Any mark character (or a mix) may be used to separate items. This variable is unchanged on return unless it is also out.list
out.list The variable to received the field mark delimited result.
sort.rule Defines how the sort is to be performed and is any consistent combination of the following letters:
  • A  Sort into ascending order (default)
  • C  Case insensitive sort
  • D  Sort into descenidng order
  • L  Sort as left aligned values (default)
  • N  Ignore null elements
  • R  Sort as right aligned values
  • U  Return unique items. Multiple occurrences of an item are replaced by just one item

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.


Related Articles

None.



Please tell us if this article was helpful
Very     Slightly     Not at all
Comments
Email (optional)