Search code examples
dynamicabapalv

Type mismatch when calling cl_salv_bs_runtime_info=>get_data_ref()


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.

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?

Is there a way to do this generic? At runtime I don't know which report is to be called.

My overall goal is to get the report in XML or JSON format.


Solution

  • 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/