0

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.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
guettli
  • 25,042
  • 81
  • 346
  • 663
  • "more high level data", can you explain? – Sandra Rossi Aug 02 '18 at 06:57
  • @SandraRossi with "high level data format2 I mean for example CSV, json, XML, yaml, proto-buf. – guettli Aug 02 '18 at 07:00
  • 1
    And "report" meaning an "itab", right? – Florian Aug 02 '18 at 09:09
  • ALV has native [Export to spreadsheet](https://i.stack.imgur.com/DNtol.png) function where you can find both SAP XLM format and Excel XML. Also you can use [Save to local file](http://help.innowera.net/PR2008/2.00/index.htm?how-to-save-alv-grid-output-to-a-excellocal-file.htm) functionality which allows exporting to tab-delimited file, which is easily convertible to CSV. – Suncatcher Aug 02 '18 at 10:35
  • @Suncatcher this needs to be executed in ABAP. I updated the question. – guettli Aug 02 '18 at 10:48
  • There isn't a function to do this, you have to code yourself. Only exists function to convert LIST/SPOOL to PDF/HTML/TEXT – I.B.N. Aug 02 '18 at 11:49
  • 1
    Okay, so it's an ALV output. The actual trend is to intercept the output table before the ABAP list is displayed, by using the class `CL_SALV_BS_RUNTIME_INFO` (before and after your `SUBMIT`). Search for more info. – Sandra Rossi Aug 03 '18 at 05:12

2 Answers2

1

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) was already answered to you in your question.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • You say "the final step of the solution (conversion of result table to JSON) was already answered to you in your question". I can't follow you. The other question is different. The other question is about a database query. The above question is about a list output. AFAIK the answers of the other question can't be applied here, since the input data type is different. – guettli Aug 08 '18 at 09:15
  • Data input doesn't matter. Both SUBMIT snippet and database query result to internal table which conversion to JSON is trivial. – Suncatcher Aug 08 '18 at 09:22
1

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

guettli
  • 25,042
  • 81
  • 346
  • 663