2

I found a way to export a hierarchical ALV with the help of this question. Unfortunately I don't know in advanced if the report uses hierarchical ALV or not.

If I apply the code of above answer to the report RFSKPL00, then I get an exception in cl_salv_bs_runtime_info=>get_data() here:

  if t_data_line is requested.
    import t_data_line to t_data_line from memory id cl_salv_bs_runtime_info=>c_memid_data_line.
    if sy-subrc ne 0.
      raise exception type cx_salv_bs_sc_runtime_info  <=========
        exporting
          textid = 'ERROR'.
    endif.
  endif.

How can I check in ABAP if a report uses hierarchical ALV or not?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
guettli
  • 25,042
  • 81
  • 346
  • 663
  • 1
    Just catch the exception, roughly: DATA lx_... TYPE REF TO CX_SALV_BS_SC_RUNTIME_INFO. TRY. ...method call... CATCH CX_SALV_BS_SC_RUNTIME_INFO INTO lx_... ENDTRY. – József Szikszai Nov 06 '18 at 13:05
  • @JozsefSzikszai your comment looks more like a working answer, it would benefit other people if you convert it into an answer (same thing in the other question) – Sandra Rossi Nov 06 '18 at 14:53
  • @JozsefSzikszai yes, catching "CX_SALV_BS_SC_RUNTIME_INFO" would work. But this would catch a lot of other errors which have other root causes. It would be great if I could find an "if statement" which checks this particular case only. – guettli Nov 06 '18 at 16:16
  • not a big deal to do first a `get_data` to get `t_data` and `t_data_line` (in case it's a hierarchical-sequential list), if it has an error try `get_data` to get `t_data` only (in case it's a classic ALV, it should work), and a failure again means that it's an unknown cause. – Sandra Rossi Nov 07 '18 at 07:39

3 Answers3

3

You can use TRY / CATCH / ENDTRY to prevent dumps based on catchable class based exceptions:

DATA lx_runtime_info TYPE REF TO cx_salv_bs_sc_runtime_info.

TRY.
    cl_salv_bs_runtime_info=>get_data(
      IMPORTING
        t_data      = <lt_data>
        t_data_line = <lt_data_line>
           ).
  CATCH cx_salv_bs_sc_runtime_info INTO lx_runtime_info.
      DATA(lv_result) = lx_runtime_info->if_message~get_text( ).
      DATA(lv_result_long) = lx_runtime_info->if_message~get_longtext( ).
ENDTRY.

(ST22 will always tell you which exception class you have to use.)

As all exception classes are subclasses (sub-subclasses, sub-sub-subclasses, etc.) of CX_ROOT, so you can use the methods get_text and get_longtext to get more information (implemented through interface if_message) about the problem.

József Szikszai
  • 4,791
  • 3
  • 14
  • 24
3

To determine whether the ALV is a classic ALV or a hierarchical-sequential list :

IF cl_salv_bs_runtime_info=>get( )-structure_line IS INITIAL.
  "---------------------
  " classic ALV
  "---------------------
  cl_salv_bs_runtime_info=>get_data_ref(
    IMPORTING r_data = DATA(lr_data) ).
ELSE.
  "---------------------
  " hierarchical-sequential list 
  "---------------------
  cl_salv_bs_runtime_info=>get_data_ref(
    IMPORTING r_data      = lr_data
              r_data_line = DATA(lr_data_line) ).
ENDIF.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
2

I wanted the same information and the answer by Sandra didn't help me/didn't work, because the parameters just wouldn't fill. But cl_salv_bs_runtime_info has another function that solved my problem, get_metadata. It has a parameter is_hierseq that gets filled as expected.

DATA: lr_data            TYPE REF TO data,
      lr_data_line       TYPE REF TO data.
FIELD-SYMBOLS: <lt_data>      TYPE ANY TABLE,
               <lt_data_line> TYPE ANY TABLE.
" initialising runtime analysis
cl_salv_bs_runtime_info=>set( EXPORTING display  = abap_false
                                        metadata = abap_true
                                        data     = abap_true ).
* ALV grid / hierarchical output:
CALL TRANSACTION 'MB51'.

* Testing output mode using metadata
DATA(runtime_metadata) = cl_salv_bs_runtime_info=>get_metadata( ).

IF runtime_metadata-is_hierseq IS INITIAL.
  cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data_descr = DATA(lr_data_descr) ).

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

  cl_salv_bs_runtime_info=>get_data( IMPORTING t_data = <lt_data> ).
ELSE. " hierarchical
  cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data_descr      = 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> ).
ENDIF.

In the case of a simple SALV grid <lt_data> var contains the output, and in the case of a hierarchical ALV list the result will be in <lt_data_line> instead.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Legxis
  • 886
  • 7
  • 19