调用 cl_salv_bs_runtime_info=>get_data_ref() 时类型不匹配

Type mismatch when calling cl_salv_bs_runtime_info=>get_data_ref()

我在这里找到了一个解决方案并尝试应用。

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

SUBMIT ('RM07MLBS')
AND RETURN.


DATA: lt_outtab TYPE STANDARD TABLE OF alv_t_t2.
FIELD-SYMBOLS: <lt_outtab> like lt_outtab.
DATA lo_data TYPE REF TO data.

TRY.
    " get data from SALV model"&nbsp;
    cl_salv_bs_runtime_info=>get_data_ref(
          IMPORTING
            r_data = lo_data
    ).
    ASSIGN lo_data->* to <lt_outtab>.
    BREAK-POINT.

  CATCH cx_salv_bs_sc_runtime_info.
ENDTRY.

来源:http://zevolving.com/2015/07/salv-table-22-get-data-directly-after-submit/

但这不起作用。我在这一行中收到类型不匹配错误:

ASSIGN lo_data->* to <lt_outtab>.

有什么问题吗?

有没有办法做到这一点?在运行时我不知道要调用哪个报告。

我的总体目标是获得 XML 或 JSON 格式的报告。

我在您的代码中添加了动态 table、行和组件以创建工作示例。

REPORT zmky_catch_report.

DATA: lo_data        TYPE REF TO data,
      lr_structdescr TYPE REF TO cl_abap_structdescr,
      lr_tabledescr  TYPE REF TO cl_abap_tabledescr,
      ls_component   TYPE abap_compdescr .
FIELD-SYMBOLS: <fs_table> TYPE table,
               <fs_line>  TYPE any,
               <fs_field> TYPE any.

" Let know the model
cl_salv_bs_runtime_info=>set(
 EXPORTING
   display  = abap_false
   metadata = abap_false
   data     = abap_true
).


SUBMIT ('RM07MLBS')
  AND RETURN.

TRY.
    " get data from SALV model
    cl_salv_bs_runtime_info=>get_data_ref(
          IMPORTING
            r_data = lo_data
    ).
    lr_tabledescr ?= cl_abap_tabledescr=>describe_by_data_ref( lo_data ).
    lr_structdescr ?= lr_tabledescr->get_table_line_type( ).

* Table header
    WRITE 'ROWNUM     '.
    LOOP AT lr_structdescr->components INTO ls_component.
      WRITE ls_component-name.
    ENDLOOP.
    ULINE.

* Lines
    ASSIGN lo_data->* TO <fs_table>.
    LOOP AT <fs_table> ASSIGNING <fs_line>.
      WRITE sy-tabix.
      LOOP AT lr_structdescr->components INTO ls_component.
        ASSIGN COMPONENT ls_component-name OF STRUCTURE <fs_line> TO <fs_field>.
        WRITE <fs_field>.
      ENDLOOP.
      WRITE /.
    ENDLOOP.

  CATCH cx_salv_bs_sc_runtime_info.
ENDTRY.

在用户 mkysoft 的回答的帮助下,这是可行的解决方案,它以 json 格式导出数据:

FUNCTION /Z_FOO/CALL_REPORT_XML.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  EXPORTING
*"     VALUE(EV_RESULT_JSON) TYPE  STRING
*"----------------------------------------------------------------------

DATA: lo_data        TYPE REF TO data.

" Let know the model
cl_salv_bs_runtime_info=>set(
 EXPORTING
   display  = abap_false
   metadata = abap_false
   data     = abap_true
).


SUBMIT ('RM07MLBS')
   WITH WERKS = '0557'
  AND RETURN.


" get data from SALV model
cl_salv_bs_runtime_info=>get_data_ref(
      IMPORTING
        r_data = lo_data
).

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( ).

ENDFUNCTION.

这帮助我完成了它:https://blogs.sap.com/2011/07/07/gain-programmatic-access-to-data-of-sapgui-alv-reports/