Skip to Content
author's profile photo Former Member
Former Member

Accessing filtered data from ALV from batch mode


I am trying to access the filtered data from an ALV when running in background (batch) mode.

If I use SET_TABLE_FOR_FIRST_DISPLAY, the correct content on the ALV is sent to the spool but the program immediately exits after the call.

If I use REUSE_ALV_GRID_DISPLAY, the correct content on the ALV is sent to the spool and I could continue the logic in the program but I could not find a way to get the filtered entries. I have 9 entries, 8 are filtered, 1 is displayed but the table still has 9 entries and no other table or object is giving me info on the entries really displayed.

Have you ever encountered this situation?

If so, any solution available?

Thanks in advance,


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Dec 13, 2017 at 10:25 PM

    Sorry to redirect you to another SAP technology, but you could also try SALV, because Matthew proposed a code to retrieve the current filters and apply them to the table, here:

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member


      Thanks for your answer but since we require cell coloring and editable fields, SALV is not an option although color and edit is not really an issue in batch mode.

      I usually use OO technology but had to go to old FM technology in order to try to gain control in batch mode. If I could gain control after return from SET_TABLE_FOR_FIRST_DISPLAY, this would be the best option as I could use

      GET_FILTERED_ENTRIES which works in foreground.

      Otherwise I would like to find a way to query the ALV for filtering information after the call to REUSE_ALV_GRID_DISPLAY like REUSE_ALV_GRID_LAYOUT_INFO_GET which I could get to return any info.


      Alain Cyr.

  • Posted on Dec 14, 2017 at 07:19 PM

    I did a test by adapting the standard demo program BCALV_TEST_GRID_PRINT (use of CL_GUI_ALV_GRID), the control goes back after the CALL SCREEN in case you run the program in background. If you "wrap" the CALL SCREEN with calls to methods SET, GET_DATA_REF and GET_METADATA of class CL_SALV_BS_RUNTIME_INFO, you may retrieve both the internal table (not filtered) and the filters. You could then develop the logic of filtering yourself the lines of the internal table based on the information coming from the filters, with the same logic as Matthew with CL_SALV_TABLE ("big" adaptation needed of course). Note that you may find many discussions about CL_SALV_BS_RUNTIME_INFO throughout the web.

        EXPORTING display  = abap_false
                  metadata = abap_true
                  data     = abap_true ).
      DATA: lr_alv_table TYPE REF TO data,
            ls_metadata  TYPE cl_salv_bs_runtime_info=>s_type_metadata.
          cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_alv_table ).
          ls_metadata = cl_salv_bs_runtime_info=>get_metadata( ).
        CATCH cx_salv_bs_sc_runtime_info.
          " TODO
      cl_salv_bs_runtime_info=>clear_all( ).
    Add a comment
    10|10000 characters needed characters exceeded

    • Solution for filtering easily, with function module LVC_FILTER_APPLY:

        DATA: ls_filter             TYPE lvc_s_filt,
              lt_grouplevels        TYPE  lvc_t_grpl,
              i_ignoring_case       TYPE  char01,
              lt_filter_index       TYPE  lvc_t_fidx,
              lt_grouplevels_filter TYPE  lvc_t_grpl.
              <alv_table>           TYPE STANDARD TABLE,
              <index>               TYPE i.
        IF ls_metadata-t_filter IS NOT INITIAL.
          ASSIGN lr_alv_table->* TO <alv_table>.
          READ TABLE ls_metadata-t_filter INTO ls_filter INDEX 1.
              it_fieldcatalog        = ls_metadata-t_fcat
              it_filter              = ls_metadata-t_filter
              it_grouplevels         = lt_grouplevels
              i_tabname              = ls_filter-tabname
              i_ignoring_case        = i_ignoring_case
              et_filter_index        = lt_filter_index
              et_grouplevels_filter  = lt_grouplevels_filter
              it_data                = <alv_table>.
          SORT lt_filter_index BY table_line DESCENDING. " IMPORTANT FOR SAFE DELETING FROM THE END !
          LOOP AT lt_filter_index ASSIGNING <index>.
            DELETE <alv_table> INDEX <index>.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.