cancel
Showing results for 
Search instead for 
Did you mean: 

Convert internal table data to Json

vikash_pathak
Participant
0 Kudos

Hi ,

I have to convert internal table data to JSON, but i have option only either low case or upper case but i have to send json in mix case somewhere it is in small case somewhere in capital ,'

used below code for conversion

 /ui2/cl_json=>serialize(
exporting
data = lwa "li_supplier "lt_scarr1 "Data to serialize
pretty_name = /ui2/cl_json=>pretty_mode-camel_case "low_case "Pretty print property names
receiving
r_json = lv_json ).

sample as below

{ "Supplier": "SPP", "SupplierSite": "Riyadh", "InvoiceAmount": 5000, "InvoiceCurrency": "SAR", "InvoiceNumber": "20220909", "BusinessUnit": "SAMPLE", "InvoiceDate": "2022-03-09", "InvoiceType": "Standard", "PaymentTerms": "Immediate", "PaymentMethodCode": "CHECK", "Description": "TEST", "PayAloneFlag": "Y","invoiceDff":[{ "apInvRefNo": "20220725", "__FLEX_Context": "", "__FLEX_Context_DisplayValue": "", "party": "TEST", "claimtype": "TEST", "startdate": null, "enddate": null, "citizenname1": "TEST", "citizenname2": "/ TEST", "instrumentno": "314004004010", "buildingspace": "109.2", "price": "3500", "year": "1439"}],"attachments":[{"Type":"File","FileName":"هTEST.pdf "}],"invoiceLines":[{"LineNumber": 1,"LineType":"Item","Description":"Lease","LineAmount":"6000","AccountingDate":"2022-03-09","DistributionSet":"TEST"}],"invoiceInstallments":[{"InstallmentNumber": 1,"DueDate":"2022-03-09","GrossAmount": 4000,"PaymentMethodCode":"Check","RemitToSupplier":"TEST","RemittanceMessageOne":"Test"}]}

Accepted Solutions (1)

Accepted Solutions (1)

mimanchi
Explorer

hi

Instead, you can use the parameter name_mappings for the desired function.

DATA: BEGIN OF ls_header,
cancflag VALUE 'X',
orndocnr TYPE belnr_d VALUE '100000001',
END OF ls_header.

DATA: lv_json TYPE string.
TYPES: BEGIN OF name_mapping,
abap TYPE abap_compname,
json TYPE string,
END OF name_mapping.
DATA: lw_name_mapping TYPE name_mapping,
name_mappings TYPE HASHED TABLE OF name_mapping WITH UNIQUE KEY abap,
lt_name_mappings LIKE name_mappings.

lw_name_mapping-abap = 'CANCFLAG'.
lw_name_mapping-json = 'CancFlag'.
INSERT lw_name_mapping INTO TABLE lt_name_mappings.
lw_name_mapping-abap = 'ORNDOCNR'.
lw_name_mapping-json = '__OrndOcnr'.
INSERT lw_name_mapping INTO TABLE lt_name_mappings.

/ui2/cl_json=>serialize(
EXPORTING
data = ls_header "li_supplier "lt_scarr1 "Data to serialize
pretty_name = /ui2/cl_json=>pretty_mode-camel_case "low_case "Pretty print property names
name_mappings = lt_name_mappings
RECEIVING
r_json = lv_json ).
BREAK-POINT .
{"CancFlag":"X","__OrndOcnr":"100000001"}

Answers (2)

Answers (2)

mimanchi
Explorer
0 Kudos

A simple, but not so good, way to define a structure or table is to add '_', such as '_invoice_currency'.

raymond_giuseppi
Active Contributor
0 Kudos

Did you try other modes than camel_case which is not low_case as it allows values such as AddressLine; Try modes such as none, low_case, extended, user, user_low_case?