In this section: |
How to: |
The STACK SORT command enables you to sort the contents of a stack in ascending or descending order based on the values in one or more columns.
The syntax for the STACK SORT command is
STACK SORT stackname BY [HIGHEST] column [BY [HIGHEST] column ...] [;]
where:
Specifies the stack to be sorted. The stack name cannot be subscripted with a row range in order to sort only part of the stack.
If specified, sorts the stack in descending order. If not specified, the stack is sorted in ascending order.
Is a stack column name or a computed field value. At least one column name must be specified. The column must exist in the specified stack.
Terminates the command. Although the semicolon is optional, it is recommended that you include it to allow for flexible syntax and better processing. For more information about the benefits of including the semicolon, see Terminating a Command's Syntax.
The following sorts the Emp stack using the values in the stack column Emp_ID:
STACK SORT Emp BY Emp_ID;
The following sorts the Emp stack so that the employees with the highest Salary are placed first in the stack:
STACK SORT Emp BY HIGHEST Salary;
The next example sorts the stack by Department. Within Department, the rows are ordered by highest Salary:
STACK SORT Emp BY Department BY HIGHEST Salary;
How to: |
You can sort data in a stack without considering case by using the CASE_INSENSITIVE parameter.
To sort data in a stack and ignore case-sensitivity:
STACK SORT stackname BY [HIGHEST] column [BY [HIGHEST] column ...] [using CASE_INSENSITIVE] [;]
perform prep_CASE_INSENSITIVE
For example:
MAINTAIN MODULE IMPORT (mntuws) $$Declarations CASE Top PERFORM prep_CASE_INSENSITIVE; COMPUTE STK(1).NAME/A10="GEORGE"; STK(2).NAME="Bernard"; STK(3).NAME="Shaw"; . . . STACK SORT STK BY NAME using CASE_INSENSITIVE; . . .
Note: For a back-end procedure without a Top case, the perform prep_CASE_INSENSITIVE command is not required.
When using MNTCON MATCH_CASE ON, the case of the code must be the same as it appears above.