cancel
Showing results for 
Search instead for 
Did you mean: 

to write json code in abap

11-06-2021 5:15 AM
Abhishekachar Explorer
3511 views 5 comments
0 Likes
SAP Managed Tags
Subscribe

Hello SAP guru's

i got a requirement sap-odoo integration, that api should be called during invoice save and pdf generated in both sap and odoo, they have given json format and functional specification like below.. i don't know how to write code json code in the program im stuck after loop statement, don't know what code i have to write.. json format and functional specification is given below

Please find below the JSON formats for SAP - Odoo Communication:

Input format from SAP to Odoo:

{

"SAP Invoice Number": [

{

"OrderRef": "401301234",

"OrderUID" : "BB12345",

"SKU": "FMS72003600M02528",

"QTY": 30,

"UOM": "NOS",

},

{

"OrderRef": "401301234",

"OrderUID" : "BB12346",

"SKU": "FMS72003600M04528",

"QTY": 10,

"UOM": "NOS",

},

.....

.....

]

}

Return from Odoo to SAP:

{

"SAP_Invoice": <Sent above>,

"STATUS": <success or error>,

"MSG": <Error message in case of error, URL of the invoice PDF in case of success>

}

0 Likes

Accepted Solutions (0)

Answers (3)

Answers (3)

retired_member
Product and Topic Expert
Product and Topic Expert

The basics about handling JSON in ABAP are described here:

https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_json.htm

There are also additional libraries or APIs available.

Make yourself clear what you want and then check out what kind of transformation or parsing/rendering you can use

0 Likes

ABAP to JSON usage example:

DATA: lt_flight TYPE STANDARD TABLE OF sflight,

lrf_descr TYPE REF TO cl_abap_typedescr,

lv_json TYPE string.

SELECT * FROM sflight INTO TABLE lt_flight.

* serialize table lt_flight into JSON, skipping initial fields and converting ABAP field names into camelCase

lv_json =/ui2/cl_json=>serialize( data = lt_flight compress = abap_true pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).

WRITE / lv_json.

CLEAR lt_flight.

* deserialize JSON string json into internal table lt_flight doing camelCase to ABAP like field name mapping

/ui2/cl_json=>deserialize(EXPORTING json = lv_json pretty_name =/ui2/cl_json=>pretty_mode-camel_case CHANGING data = lt_flight ).

* serialize ABAP object into JSON string

lrf_descr = cl_abap_typedescr=>describe_by_data( lt_flight ).

lv_json =/ui2/cl_json=>serialize( lrf_descr ).

WRITE / lv_json.

ThorstenHoefer
Active Contributor
0 Likes

Class /ui2/cl_json is a simple way to convert json to abap and vice versa.

pcsv_srinivas
Explorer
0 Likes

can you please paste a example code for abap oo