
You can 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.
control level
Data records that 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 filter settings for a column are represented by an object of type CL_SALV_SORT. The total of all the filter 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. If you need to calculate intermediate results in addition to the overall result, the rows that contain the subvalues of an intermediate result must be next to each other; you sort the list. You sort the ALV output. The sort is then a prerequisite for ALV being able to determine and display interim results.
You can make the following settings for sorting:
Get Sort Objects
Create and Delete Sort Objects
Specify sort direction
Set Column Sequence of Sorting
Forbid Changes
Highlight Control Level Change
For all of the following functions, this is valid:
|
ALV Tool |
Display type |
Function available |
|
Simple, two-dimensional table |
Classic ABAP List |
Yes |
|
Fullscreen |
Yes |
|
|
In the Container |
Yes |
|
|
Hierarchical-sequential list |
Classic ABAP List |
Yes |
|
Tree Structure |
Fullscreen |
No |
|
In the Container |
No |
Get Sort Objects
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.
|
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 |
Create and Delete Sort Objects
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.
|
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.
Specify sort direction
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. You determine the sort direction.
|
Function |
Class |
Method |
|
Specify sort direction |
CL_SALV_SORTS |
ADD_SORT (Parameter SEQUENCE) |
|
CL_SALV_SORT |
SET_SEQUENCE |
|
|
Get sort direction |
CL_SALV_SORT |
GET_SEQUENCE |
Set Column Sequence of Sorting
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 can change this sequence.
|
Function |
Class |
Method |
|
Change column sequence of sorting |
CL_SALV_SORTS |
ADD_SORT (Parameter POSITION) |
|
SET_POSITION |
Forbid Changes
By default, the user can change sort settings that you have specified using the application. However, you are able to expressly forbid this.
|
Function |
Class |
Method |
|
Forbid changes to sort object |
CL_SALV_SORTS |
ADD_SORT (Parameter OBLIGATORY) |
|
CL_SALV_SORT |
SET_OBLIGATORY |
|
|
Check whether user is able to make changes to the sort object |
CL_SALV_SORT |
IS_OBLIGATORY |
Highlight Control Level Change
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.
Prerequisites
You have activated grouping of the ALV output.
|
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 |