Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom sort & filter logic within SALV (CL_SALV_TABLE)

gadde_shrinivas
Explorer
0 Kudos

Hi,

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.

Thanks,

Shrinivas

8 REPLIES 8

Sandra_Rossi
Active Contributor
0 Kudos

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.

gadde_shrinivas
Explorer
0 Kudos

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.

Sandra_Rossi
Active Contributor

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 ).

0 Kudos

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

0 Kudos

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).

0 Kudos

Thanks.. the FM LVC_FILTER was helpful.