‎2023 Jan 18 1:46 PM
hello experts,
I currently have a json output where I should map abap deep structure field names to the expected json output.
ex: /XYZ/V_CRNCY -> VCRNCY. I'm currently using a REPLACE ALL REGEX to remove the /XYZ/ from each field but I think there should be a way to do this using the /ui2/cl_json class attributes.
In addition, I should return the values of each deep structure in a results array, remove client field from output and format dates so that there are no dashes where the data type is DATS
ex: "STRUCT_NAV": [
{
"MANDT": "200",
}
]
"STRUCT_NAV": {
"results": []
}
I've attached my structure and current json where I am attempting to use /ui2/cl_json class to serialize and output the json. I apologize if I haven't provided enough information and will be glad to provide more to receive some help.
‎2023 Jan 18 2:24 PM
Hello Gregory,
‎2023 Jan 18 1:48 PM
Thank you for visiting SAP Community to get answers to your questions.
As you're looking to get the most out of your community membership, please consider including a profile picture to increase user engagement & additional resources to your reference that can really benefit you:
I suggest you use the "Insert Code option for the question.
Profile https://developers.sap.com/tutorials/community-profile.html
Tips for Questions: https://community.sap.com/resources/questions-and-answers
Consider taking our Q&A tutorial at: https://developers.sap.com/tutorials/community-qa.html.
I hope you find this advice useful, and we're happy to have you as part of the SAP Community!
All the best,
Dedi
‎2023 Jan 18 2:24 PM
Hello Gregory,
‎2023 Jan 18 5:05 PM
Thanks for your reply Tomas.- I understand about the NAME_MAPPINGS. Since the field names won't change listing them all individually would be tedious at first but it would handle the situation without using REPLACE ALL REGEX which could potentially change future values as well.
- The client field is in the ABAP structure that tells us which system ID we're currently using. ex: "MANDT" : 200. The table being pulled from being PQRSTU for example. The json itab I use to feed into the ui2/cl_json serialize method is of the same type as the parent table so it has all the same fields. I've been trying to find a simple way to remove that field.
- Would I use TS_AS_ISO8601 = abap_true to modify the date value from 2021-03-01 -> 20210301 ? This didn't seem to apply the result I needed
"PQRSTU": [
{
"MANDT": "200",
"PNGUID": "",
"PNCNT": 1,
"PNTXCNT": 1,
"VERSN": 3,
TYPES: BEGIN OF ty_json,
XYZ_NAV TYPE /XYZ/GB_TT_PQRSTU,
END OF ty_json.
lt_json TYPE TABLE OF ty_json,
‎2023 Jan 19 8:54 AM
gregfranco
About MANDT field - I am still not sure what do you want to archieve. Remove MANDT field from ABAP structure to which you are deserializing JSON? Check example below, it works even if there is no MANDT field in ABAP structure.
About date + time, this works OK for me. No need to use TS parameter (you work with date, not timestamp).
TYPES: BEGIN OF ty_s_data,
date TYPE d,
time TYPE t,
END OF ty_s_data.
DATA: ls_data TYPE ty_s_data,
lv_act TYPE string.
lv_act = '{"MANDT":"200","DATE":"2016-07-08","TIME":"12:34:56"}'.
/ui2/cl_json=>deserialize( EXPORTING json = lv_act CHANGING data = ls_data ).