4
votes

Is there an easy way of retrieving the ALV data that is displayed when there are also filters used on that ALV?

The ALV used is an object of CL_GUI_ALV_GRID. When showing it to the user, there is a filter placed on it by default. The user also has a button that processes the data in the ALV. How can I make sure the process only works with the data that is displayed, even if the user places his own filters on the ALV?

e.g: An ALV gets created from an itab that has 10 rows, but because there is also a filter passed on the ALV, only 8 rows are showing. When pressing a button, I only want to work with the 8 rows currently showing to the user.

I have tried finding a function module for this purpose but I can only find a FM which works with the selected rows in an ALV.

EDIT: Further, there is a method called get_filtered_entries, but it only retrieves those entries that are NOT displayed. Using this will be quite time-consuming to make the translation to displayed entries. get_filtered_entries

Thanks in advance.

1

1 Answers

5
votes

GET_FILTERED_ENTRIES returns a table of excluded row indices. You just have to skip those in your processing.

" Copy original table
DATA(lit_buffer) = it_out[]. 

" Get excluded rows
o_grid->get_filtered_entries(
  IMPORTING
    et_filtered_entries = DATA(lit_index)
).

" Reverse order to keep correct indizes; thnx futu
SORT lit_index DESCENDING.

" Remove excluded rows from buffer
LOOP AT lit_index ASSIGNING FIELD-SYMBOL(<index>).
  DELETE lit_buffer INDEX <index>.
ENDLOOP.

EDIT: I debugged cl_gui_alv_grid a little and it doesn't seems like that a filtered version of the original table exists at all. The lines get filtered, sorted, grouped and immediately transferred into a table of cells. Looks like it is nearly impossible to get the displayed rows without a performance drawback.