Check if Report uses hierarchical ALV or not

2019-08-26 05:20发布

问题:

I found a way to export a hierarchical ALV like this: ABAP: Report via GUI has 18 columns, via RFC 6 (hierarchical ALV)

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 (via abap code) if a report uses hierarchical ALV or not?

回答1:

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.



回答2:

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.


标签: abap