Skip to Content
0
Feb 26, 2021 at 10:06 PM

ABAP TO JSON

86 Views Last edit Feb 26, 2021 at 11:41 PM 2 rev

Hi

I want to create a JSON file from ABAP in the below format.

{

"Transactionid": "FA163E0XXXXXXXXXXXXXXXXXXXD7A7",

"AggregationLevelFieldsString": "LOCID,PERIODID4,RESID,CAPASUPPLY",

"NavUNIPA2021": [

{

"LOCID": "0003",

"PERIODID4": "2019 CW29",

"RESID": "0003 Subassembly",

"CAPASUPPLY": "9831"

}

]

}

I tried the following code:

json_req-keyfigure = 'CONSENSUSDEMANDQTY'.
json_req-keyfiguredate = '2021/02/25'.
json_req-product = 'E6603GA0'.
json_req-customer = '54000'.
json_req-location = '5450'.

*Create JSON body
DATA lr_json_serializer TYPE REF TO cl_trex_json_serializer.
CREATE OBJECT lr_json_serializer EXPORTING data = json_req.
lr_json_serializer->serialize( ).
DATA(lv_body) = lr_json_serializer->get_data( ).

but this does only create a simple JSON and not a nested JSON. Please let me know how to do it.

Thanks,

Ashok