Sorting by Columns
You are able to change the sequence of data records according to specific rules by sorting the ALV output. You specify which column includes the value that is to be sorted alphabetically or numerically, determining the sequence of all rows.
You are able to specify up to nine columns that can be used to sort the ALV output.
Data records have the same value in a sorted column for a control level. If this value changes in regard to the next data record, it is called a control level change.
You have various options to highlight a control level change.
The sort settings for a column are represented by an object of type CL_SALV_SORT. The total of all the sort objects is represented by an object of type CL_SALV_SORTS.
You are able to make calculations using the values of numeric columns. By default all values of a column are used for this. If you need intermediate results in addition to the overall result of the calculation, the rows that contain the subvalues of an intermediate result need to be next to each other: They sort the ALV output. The sort is then a prerequisite for ALV being able to determine and display intermediate results.
You are able to make the following settings for sorting:
· Get sort objects
· Create and delete sort objects
· Set sort direction
· Set column sequence of sorting
· Forbid changes
· Highlight control level change
For all of the following functions, this is valid:
Display type ALV Tool |
Classic ABAP list |
Full screen |
In the Container |
Simple, two-dimensional table |
Yes |
Yes |
Yes |
Hierarchical-sequential list |
Yes |
|
|
Tree structure |
|
No |
No |
In every main ALV class where sorting is possible, the GET_SORTS method exists. This method returns the sort objects for all columns in the ALV output (class CL_SALV_SORTS). Using this object with the methods GET or GET_SORT you get the sort object for the desired column.
Methods
Function |
Class |
Method |
Get SORTS object |
CL_SALV_TABLE CL_SALV_HIERSEQ_TABLE |
GET_SORTS |
Get all sort objects |
CL_SALV_SORTS |
GET |
Get all sort objects for a hierarchy level |
CL_SALV_HIERSEQ_LEVEL |
GET_SORTS |
Get a specific sort object |
CL_SALV_SORTS |
GET_SORT |
Check whether a column is sorted (a sort object exists) |
IS_SORT_DEFINED |
You are able to create a maximum of one sort object for a column You are able to sort the ALV output using up to nine columns.
You are able to delete sort objects either individually or all at once.
Methods
Function |
Class |
Method |
Create sort object |
CL_SALV_SORTS |
ADD_SORT |
Delete individual sort object |
REMOVE_SORT |
|
Delete all sort objects |
CLEAR |

If you assign a new data table with a new structure to your ALV output, all aggregation objects will be deleted automatically.
For each individual sort object, you are able to determine whether you want to sort the column ascending (for example a, b, c) or descending (for example c, b, a): You set the sort direction.
Methods
Function |
Class |
Method |
Set sort Direction |
CL_SALV_SORTS |
ADD_SORT (Parameter SEQUENCE) |
CL_SALV_SORT |
SET_SEQUENCE |
|
Get sort direction |
CL_SALV_SORT |
GET_SEQUENCE |
If you sort the ALV output by multiple columns, the result changes depending on the sequence of columns that is used to sort.
By default, the columns are sorted in the sequence in which you generated your sort objects. You are able to change this sequence.
Methods
Function |
Class |
Method |
Change column sequence of sorting |
CL_SALV_SORTS |
ADD_SORT (Parameter POSITION) |
SET_POSITION |
By default, the user can change sort settings that you have specified using the application. However, you are able to expressly forbid this.
Methods
Function |
Class |
Method |
Forbid changes to sort object |
CL_SALV_SORTS |
ADD_SORT |
CL_SALV_SORT |
SET_OBLIGATORY |
|
Check whether user is able to make changes to the sort object |
CL_SALV_SORT |
IS_OBLIGATORY |
If a value changes in a sorted column between two data records, this is called a control level change. You are able to highlight the control level change in two ways:
· You separate the group levels with a horizontal line.
· You start a new page for each control level.
· You have activated grouping of the ALV output.
Methods
Function |
Class |
Method |
Activate grouping of the ALV output |
CL_SALV_SORTS |
SET_GROUP_ACTIVE |
Check whether grouping of the ALV output has been activated. |
IS_GROUP_ACTIVE |
|
Set display of control level change |
ADD_SORT (Parameter GROUP) |
|
CL_SALV_SORT |
SET_GROUP |
|
Get display of the control level change |
GET_GROUP |