guettli
guettli

Reputation: 27855

Capture any standard report to JSON or XML?

I know that I can use LIST_TO_ASCI to convert a report to ASCII, but I would like to have a more high level data format like JSON, XML, CSV.

Is there a way to get something that is easier to handle then ASCII?

Here is the report I'd like to convert:

enter image description here

The conversion needs to be executed in ABAP on a result which was executed like this:

SUBMIT <REPORT_NAME> ... EXPORTING LIST TO MEMORY AND RETURN.

Upvotes: 1

Views: 842

Answers (2)

Suncatcher
Suncatcher

Reputation: 10621

You can get access to SUBMIT list in memory like this:

call function 'LIST_FROM_MEMORY'
  TABLES
   listobject       = t_list
  EXCEPTIONS
   not_found        = 1
   others           = 2.

if sy-subrc <> 0.
  message 'Unable to get list from memory' type 'E'.
endif.

call function 'WRITE_LIST'
  TABLES
   listobject       = t_list
  EXCEPTIONS
   EMPTY_LIST       = 1
   OTHERS           = 2
        .
 if sy-subrc <> 0.
  message 'Unable to write list' type 'E'.
 endif.

And the final step of the solution (conversion of result table to JSON).

Upvotes: 0

guettli
guettli

Reputation: 27855

I found a solution here: http://zevolving.com/2015/07/salv-table-22-get-data-directly-after-submit/

This is the code:

DATA: lt_outtab TYPE STANDARD TABLE OF alv_t_t2.
FIELD-SYMBOLS: <lt_outtab> like lt_outtab.
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 salv_demo_table_simple
  AND RETURN.

TRY.
    " get data from SALV model
    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.

Big thanks to Sandra Rossi, she gave me the hint to cx_salv_bs_sc_runtime_info.

Related answer: https://stackoverflow.com/a/52834118/633961

Upvotes: 2

Related Questions