How to convert internal table of type LISTZEILE into JSON or XML?


Keywords:sap 


Question: 

I have a requirement where in I have to expose Standard SAP reports to Gateway services.

So I have utilized INST_EXECUTE_REPORT function module and output of the above FM with 'RM06ELLB' as input is as follows: enter image description here

enter image description here

The above image displays as in the gateway output.

Is there any way that I can convert the above ZEILE fields into a formatted json or xml structure like this:

 "zeile" : { "Material" : "100-120" , "Plant" : "1000" }

1 Answer: 

The field of ZEILE looks like containing a formatted text. You can parse the line using ABAP SPLIT operator and put the parsed data into a structure. You can use the next static method after that:

  /ui2/cl_json=>serialize(
    exporting
      data        = lt_data
      pretty_name = /ui2/cl_json=>pretty_mode-camel_case
    receiving
      r_json      = lf_json
  ).