2023 May 09 5:53 AM
Hi,
I have the below JSON format which needs to passed to Purchase Order API:
{
"CompanyCode": " ",
"PurchaseOrderType": " ",
"Supplier": " ",
"Language": " ",
"PurchasingOrganization": " ",
"PurchasingGroup": " ",
"DocumentCurrency": " ",
"to_PurchaseOrderItem": {
"results": [
{
"PurchaseOrderItem": " ",
"Plant": " ",
"OrderQuantity": " ",
"PurchaseOrderQuantityUnit": " ",
"OrderPriceUnit": " ",
"NetPriceAmount": " ",
"NetPriceQuantity": " ",
"Material": " ",
"ManufacturerMaterial": " ",
"ProductType": " "
}
]
}
}
I have a log table in SAP ECC system with the following fileds :
REGION NAME
SUPPLIERCONTACTID
LINE NUMBER
REGION NAME
ORDERQUANTITY
UNIT PRICE
And, I need to map the region name to Company code,
suppliercontactid to supplier
line number to purchaseorderitem
region name to plant
orderquantity to OrderQuantity
UnitPrice to NetPriceAmount
to the above json from the database table.
Could you please any one let me know how can I achieve this in ABAP?
2023 May 09 6:14 AM
Perform first some search on methods such as /ui2/cl_json=>serialize. There are already many threads, tutorials and blogs in the forum.
2023 May 09 6:49 AM
Hi Raymond, I have posted my question after going through many blogs. I didn't see the relavent blog to my question. My mapping was not working and not converted to the expected JSON format. Hence reaching out.
Kind regards
Ramesh
2023 May 09 8:02 AM
Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.
If you want to target someone, if this person has posted an Answer, use the button COMMENT, if this person is the Original Poster of the question he/she will be automatically informed, otherwise copy/paste their hyperlinked name (e.g. yourself: rmasetty80) so that the person receives a warning (NB: @ doesn't work/but typing this character will suggest hyperlinked names).
2023 May 09 8:04 AM
Also, post your code concerning /ui2/cl_json=>serialize so that you can understand what you did wrong...
NB: you can edit your question via Actions > Edit.
2023 May 09 12:23 PM
Hi, Here is the code : TYPES: BEGIN OF ty_purchase_order_item_results,
PurchaseOrderItem TYPE string,This program is producing the below JSON format :
[
{
"companycode": "ECG",
"purchaseordertype": "ZMX",
"supplier": "348",
"language": "EN",
"purchasingorganization": "PO02",
"purchasinggroup": "PGP",
"documentcurrency": "AUD",
"toPurchaseorderitem": {
"results": {
"purchaseorderitem": "1",
"plant": "ECG",
"orderquantity": "1.0000000",
"purchaseorderquantityunit": "EA",
"orderpriceunit": "EA",
"netpriceamount": "15000.0000",
"netpricequantity": "1",
"material": "TG11",
"manufacturermaterial": "TG11",
"producttype": "1"
}
}
}
]
But the expected format :
{
"CompanyCode": " ",
"PurchaseOrderType": " ",
"Supplier": " ",
"Language": " ",
"PurchasingOrganization": " ",
"PurchasingGroup": " ",
"DocumentCurrency": " ",
"to_PurchaseOrderItem": {
"results": [
{
"PurchaseOrderItem": " ",
"Plant": " ",
"OrderQuantity": " ",
"PurchaseOrderQuantityUnit": " ",
"OrderPriceUnit": " ",
"NetPriceAmount": " ",
"NetPriceQuantity": " ",
"Material": " ",
"ManufacturerMaterial": " ",
"ProductType": " "
}
]
}
}
The system produced JSON format is different from the expected format. First difference : starting and ending with square brackets ([ ]). This is to be removed. As per the expectation, Results are expecting in array format. Could any one please help me on this?
Thanks in advance.
2023 May 09 12:54 PM
Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.
To edit your question, use Actions > Edit.
Thank you.
2023 May 10 12:11 AM
Hi, Here is the code : TYPES: BEGIN OF ty_purchase_order_item_results,
PurchaseOrderItem TYPE string,This program is producing the below JSON format :
[
{
"companycode": "ECG",
"purchaseordertype": "ZMX",
"supplier": "348",
"language": "EN",
"purchasingorganization": "PO02",
"purchasinggroup": "PGP",
"documentcurrency": "AUD",
"toPurchaseorderitem": {
"results": {
"purchaseorderitem": "1",
"plant": "ECG",
"orderquantity": "1.0000000",
"purchaseorderquantityunit": "EA",
"orderpriceunit": "EA",
"netpriceamount": "15000.0000",
"netpricequantity": "1",
"material": "TG11",
"manufacturermaterial": "TG11",
"producttype": "1"
}
}
}
]
But the expected format :
{
"CompanyCode": " ",
"PurchaseOrderType": " ",
"Supplier": " ",
"Language": " ",
"PurchasingOrganization": " ",
"PurchasingGroup": " ",
"DocumentCurrency": " ",
"to_PurchaseOrderItem": {
"results": [
{
"PurchaseOrderItem": " ",
"Plant": " ",
"OrderQuantity": " ",
"PurchaseOrderQuantityUnit": " ",
"OrderPriceUnit": " ",
"NetPriceAmount": " ",
"NetPriceQuantity": " ",
"Material": " ",
"ManufacturerMaterial": " ",
"ProductType": " "
}
]
}
}
The system produced JSON format is different from the expected format. First difference : starting and ending with square brackets ([ ]). This is to be removed. As per the expectation, Results are expecting in array format. Could any one please help me on this?
Thanks in advance.
2025 Feb 17 6:55 PM