Sort method - SDT Collection

Official Content
This documentation is valid for:

Sorts the elements of an SDT collection variable. It also sorts a variable based on a simple data type that is a collection.

Syntax

&SDTCollectionVble.Sort("[ColumnListString]")     |     &VbleThatIsCollection.Sort()

Where:
ColumnListString
    List of SDT elements to sort in a string separated by a comma. By default ascending order is set, use [] or () to set descending order.


Samples

1) Suppose the following SDT collection variable:

SDT_Collection
  SDT_Item
    Id
    Number

To order ascending by Id:

&SDT_Sort.Sort("Id")

To order descending by Id:

&SDT_Sort.Sort("[Id]")

To order ascending by Id and descending by Number:

&SDT_Sort.Sort("Id,[Number]")

To order descending by Id and ascending by Number:

&SDT_Sort.Sort("(Id),Number")

 

2) Consider the &CustomerNameCollection variable based on the Character data type.

To order ascending the collection of customer names:

&CustomerNameCollection.Sort()

 

Scope

Objects Procedure object, Transaction object, Web Panel object
Languages .NET, .NET Core, Java
   

Considerations

The C# generators use the method ArrayList.Sort from the .Net framework. It compares two String objects by evaluating the numeric values of the individual Unicode characters of the strings using the CompareOrdinal method.

The Java Generator uses the standard String API to compare elements; it compares them lexicographically. The comparison is based on the Unicode value of each character in the strings.

All implement the Quicksort algorithm; equal elements do not preserve order.

See also

Structured Data Type Methods
Structured Data Type