Dear Charles,
There is no restriction on the sort criteria. See the last statement of my code. You can sort on any field or set of fields. Just ensure that the variable <v_sorted> is set to 1 (as in the penultimate line). That 1 ensures that the system doesn't attempt the default sort after your code has executed.