2017 Dec 13 7:08 PM
Hi,
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,
Alain.
Hi,
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,
Alain.
2017 Dec 13 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:
https://wiki.scn.sap.com/wiki/display/Snippets/Get+set+of+filtered+values+from+CL_SALV_TABLE
2017 Dec 14 1:52 PM
Sandra,
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.
Thanks,
Alain Cyr.
2017 Dec 14 7: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.
cl_salv_bs_runtime_info=>set(
EXPORTING display = abap_false
metadata = abap_true
data = abap_true ).
CALL SCREEN 100. " <== method SET_TABLE_FOR_FIRST_DISPLAY of CL_GUI_ALV_GRID
DATA: lr_alv_table TYPE REF TO data,
ls_metadata TYPE cl_salv_bs_runtime_info=>s_type_metadata.
TRY.
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
ENDTRY.
cl_salv_bs_runtime_info=>clear_all( ).
2017 Dec 14 7:33 PM
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.
FIELD-SYMBOLS:
<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.
CALL FUNCTION 'LVC_FILTER_APPLY'
EXPORTING
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
IMPORTING
et_filter_index = lt_filter_index
et_grouplevels_filter = lt_grouplevels_filter
TABLES
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>.
ENDLOOP.
ENDIF.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |