检查报告是否使用分层ALV

时间:2018-11-06 12:52:38

标签: abap

我找到了一种导出分层ALV的方法,例如:ABAP: Report via GUI has 18 columns, via RFC 6 (hierarchical ALV)

不幸的是,我不知道该报告是否使用分层ALV。

如果我将上述答案的代码应用于报告RFSKPL00,那么我在cl_salv_bs_runtime_info=>get_data()中会遇到异常:

  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.

我如何(通过abap代码)检查报表是否使用分层ALV?

3 个答案:

答案 0 :(得分:3)

您可以使用TRY / CATCH / ENDTRY来防止基于可捕获的基于类的异常的转储:

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总是会告诉您必须使用哪个异常类。)

由于所有异常类都是CX_ROOT的子类(子子类,子子子类等),因此可以使用get_text和get_longtext方法获取有关该问题的更多信息(通过接口if_message实现)。

答案 1 :(得分:2)

要确定ALV是经典ALV还是分层顺序列表:

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.

答案 2 :(得分:1)

我想要相同的信息,Sandra的回答对我/也没有帮助,因为参数无法填写。但是cl_salv_bs_runtime_info还有另一个解决我问题的功能get_metadata。它有一个参数is_hierseq,可以按预期填充。

DATA: runtime_metadata   TYPE cl_salv_bs_runtime_info=>s_type_metadata,
      lr_data_descr      TYPE REF TO cl_abap_datadescr,
      lr_data_line_descr TYPE REF TO cl_abap_datadescr,
      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 ). 

***** Calling reports in different ways:

*** calling using SUBMIT:

* ALV grid output:
*SUBMIT bcalv_grid_07 AND RETURN.

* hierarchical output:
*SUBMIT SALV_DEMO_HIERSEQ_SIMPLE AND RETURN.

*** calling using CALL TRANSACTION:

* ALV grid / hierarchical output:
CALL TRANSACTION 'MB51'.

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

IF runtime_metadata-is_hierseq IS INITIAL.

* ALV Grid / SALV
  cl_salv_bs_runtime_info=>get_data_ref( IMPORTING 
                                           r_data_descr = 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 = 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.

对于ALV / SALV,<lt_data>将包含输出,对于分层列表,则将为<lt_data_line>