PeopleCode | Sorting a rowset
A. Get in Line
This is a fairly straightforward piece of code to handle a fairly straightforward requirement, however it does tend to cause confusion and generate a few questions. This is possibly due to the way in which the sort fields must be specified for the method.
For the purposes of the ‘Sort’, it does not matter whether we are trying to sort a temporary rowset in memory, or a rowset included on a page. Assuming the rowset has already been defined in the code, the ‘Sort’ method will then sort the rowset based on each of the fields specified. Each sort field must be entered in a pair combination: (1) the name of the field and (2) whether the sort is in ascending (‘A’) or descending (‘D’) order.
Here’s an example of a rowset that we wish to sort on two fields, the first in ascending order and the second in descending order:
&level1RS.Sort(FIELD_NAME_1, "A", FIELD_NAME_2, "D");
If you like, you can also specify the record name as part of the field name:
&level1RS.Sort(RECORD_NAME.FIELD_NAME_1, "A", RECORD_NAME.FIELD_NAME_2, "D");
See Also:
Tip 002: Basic Rowset Processing