ABAP Type mismatch using cl_salv_bs_runtime_info=>get_data_ref()

社会主义新天地 提交于 2019-12-24 23:50:21

问题


I found a solution here which I try to apply.

 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.


return.

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

But this does not work. I get a type mismatch error in this line:

ASSIGN lo_data->* to <lt_outtab>.

What could be wrong?

Update: is there a way to do this generic? At runtime I don't know which report gets called. The above code is just an example.

Update2: My overall goal is to get the report in XML (or json) format.


回答1:


I added dynamic table, line and component to your code for creating working example.

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.



回答2:


With the help of the answer of user mkysoft, this is the working solution, which exports the data in json format:

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.

This helped me to get it done: https://blogs.sap.com/2011/07/07/gain-programmatic-access-to-data-of-sapgui-alv-reports/



来源:https://stackoverflow.com/questions/52824740/abap-type-mismatch-using-cl-salv-bs-runtime-info-get-data-ref

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!