Skip to Content

Custom sort & filter logic within SALV (CL_SALV_TABLE)

Jun 02, 2017 at 09:52 PM


avatar image


I have a requirement where I would like to apply custom sort & filter logic within a custom report that's using SALV classes (CL_SALV_TABLE). I checked the SALV standard sort (CL_SALV_SORTS & filter (CL_SALV_FILTERS) classes but do not see any provision for this.

Currently, I have built a solution using a convoluted approach by utilizing BEFORE_SALV_FUNCTION & AFTER_SALV_FUNCTION events and was wondering if there was any better way.

Would it be possible to have the filter button trigger ADDED_FUNCTION / USER_COMMAND event so I could get the filtered conditions user has entered and apply sort and/or filter via custom code?

Appreciate your responses.



10 |10000 characters needed characters left characters exceeded

Could you explain why you say filter and sort cannot be done programmatically? ("do not see any provision for this")

You mentioned the right classes, and you just have to use some of their methods (ADD_SORT, ADD_FILTER, or whatever you want).

If you want to add a behavior to a standard button/function, you need to use BEFORE_SALV_FUNCTION or AFTER_SALV_FUNCTION, depending on what you want to use.


Thanks for your response.

What I meant was that I myself cannot completely code the SORT & FILTER logic without the standard logic intervention. I want the SORT & FILTER pop-up & columns selection but want to be able to perform the actions through my code. I want the filter & sort trigger a user command and not itself perform any action.

With the two events, for FILTER, I am having an issue where user would see the manipulated filter condition on next selection of FILTER which I wanted to avoid and so looking for any alternative or better option.

* Please Login or Register to Answer, Follow or Comment.

1 Answer

Sandra Rossi Jun 04, 2017 at 11:14 AM

So, if you "want the filter & sort trigger a user command and not itself perform any action." then you must remove the standard functions, and define your own buttons with same icons as the standard buttons, but with CUSTOM function codes (ZFILTER and ZSORT for instance).

Edit 4 hours later: it's possible to prevent a standard function code from doing its job in event BEFORE_SALV_FUNCTION, by calling SET_FUNCTION( space ).

Show 5 Share
10 |10000 characters needed characters left characters exceeded

If I create custom function codes, then wouldn't I also need to develop my own popup window for column selection and filter value?


It seems that I missed something, again.

So, your question is to manipulate the filter after the user has entered values?

What doesn't work in event AFTER_SALV_FUNCTION, can't you modify the filter programmatically ?


Yes, I would like to manipulate the filter values but at the same time when user selects to filter again I would like to present him with the filter values that he had initially set. With the two events, I am not able to reset the filter values before the filter pop-up window pops up and see the manipulated values instead.


The filter popup is displayed between the 2 events BEFORE_SALV_FUNCTION and AFTER_SALV_FUNCTION. So, you can only do something during the event BEFORE_SALV_FUNCTION.

Unfortunately, any change of the filter done during the before event is not transferred to the popup.

The only workaround I can think of is to display the popup yourself, i.e. using the function module LVC_FILTER (there are already some existing code in the forum).

You'll have to call alv_grid->SET_FUNCTION( space ) at the end of the before event to deactivate the standard processing of the filter (which you did yourself).


Thanks.. the FM LVC_FILTER was helpful.