1

I want to export the report RM07MLBS (tcode mb52). If I call this report via the SAP-GUI it has 18 columns, and if I call it with the following code, it returns only maktx, werks, matkl, matnr, name1, mtart columns:

cl_salv_bs_runtime_info=>set(
 EXPORTING
   display  = abap_false
   metadata = abap_false
   data     = abap_true
).

SUBMIT (IV_REPORT_NAME)
   WITH SELECTION-TABLE selection_table
  AND RETURN.

DATA: lo_data TYPE REF TO data.

cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lo_data ).

IF lo_data IS NOT BOUND.
  ev_result_json = '[]'.
  EXIT.
ENDIF.

field-SYMBOLS <lv_data> type any table.
ASSIGN lo_data->* TO <lv_data>.
ev_result_json = /ui2/cl_json=>serialize( data = <lv_data> pretty_name = /ui2/cl_json=>pretty_mode-low_case ).

cl_salv_bs_runtime_info=>clear_all( ).

How to get all columns?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
guettli
  • 25,042
  • 81
  • 346
  • 663
  • 3
    Starting the executable program instead of the transaction code may behave differently. If you execute the program without the SALV export mode, doesn't it display 6 columns? If so, the question is not about SALV, but the way you start the program. It may be tricky to know the reason why it behaves differently (debug often needed), and to make it work is also another challenge. – Sandra Rossi Nov 05 '18 at 14:36
  • 5
    MB52 display a hierarchical ALV (FM REUSE_ALV_HIERSEQ_LIST_DISPLAY), which uses two internal tables: header and bestand (see program RM07MLBS Line #2652 in EHP8 SP9). When you run the report data is displayed from both of these internal tables (you can click on Change Layout and see Header and Position). It looks like when you try to catch the internal table (cl_salv_bs_runtime_info=>get_data_ref...), it brings back the header table. May be you can try to use the r_data_line parameter of the method above as well and see what happens. – József Szikszai Nov 05 '18 at 14:47
  • 1
    @JozsefSzikszai thank you very much. You gave me the right direction. To support other new comers like me, which have the same issue, I will create an answer to my question below. – guettli Nov 06 '18 at 10:32
  • @guettli No problem... :) – József Szikszai Nov 06 '18 at 10:57
  • @JozsefSzikszai thank you for your hints. Unfortunately I face the next issue now: https://stackoverflow.com/questions/53172303/abap-check-if-report-uses-hierarchical-alv-or-not – guettli Nov 06 '18 at 12:54
  • @guettli: added a fast/short answer – József Szikszai Nov 06 '18 at 13:07

1 Answers1

3

User JozsefSzikszai gave me the needed hint to solve this.

This way I can read all columns from hierarchical ALV

SUBMIT (IV_REPORT_NAME)
   WITH SELECTION-TABLE selection_table
  AND RETURN.

FIELD-SYMBOLS <lt_data>             TYPE ANY TABLE.
FIELD-SYMBOLS <lt_data_line>        TYPE ANY TABLE.

DATA          lr_data               TYPE REF TO data.
DATA          lr_data_line          TYPE REF TO data.

cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data_descr      = DATA(lr_data_descr)
                                                 r_data_line_descr = DATA(lr_data_line_descr) ).

CREATE DATA lr_data         TYPE HANDLE lr_data_descr.
CREATE DATA lr_data_line    TYPE HANDLE lr_data_line_descr.
ASSIGN lr_data->*           TO <lt_data>.
ASSIGN lr_data_line->*      TO <lt_data_line>.

cl_salv_bs_runtime_info=>get_data(
  IMPORTING
    t_data      = <lt_data>
    t_data_line = <lt_data_line>
       ).

IF <lt_data> IS INITIAL.
  ev_result_json = '[]'.
  EXIT.
ENDIF.

ev_result_json = /ui2/cl_json=>serialize( data = <lt_data_line> pretty_name = /ui2/cl_json=>pretty_mode-low_case ).
cl_salv_bs_runtime_info=>clear_all( ).

ENDFUNCTION.

Feedback and hints how to improve this are welcome.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
guettli
  • 25,042
  • 81
  • 346
  • 663
  • 1
    Your code works, but it can be greatly simplified by only using the 2 other parameters `R_DATA` and `R_DATA_LINE` of method `GET_DATA_REF` and you get rid of all the lines which use the RTTI classes (including the two RTTI parameters, the two lines with `CREATE DATA` and the line of calling the method `GET_DATA`) – Sandra Rossi Nov 10 '18 at 17:27