Hi people,
in a sample report I fetch some records from table MARA and want to serialize them:
TYPES: BEGIN OF ty_result,
matnr TYPE matnr,
mtart TYPE mtart,
matkl TYPE matkl,
END OF ty_result.
DATA lt_result TYPE TABLE OF ty_result.
SELECT matnr, mtart, matkl FROM mara
INTO CORRESPONDING FIELDS OF TABLE @lt_result UP TO 5 ROWS.
DATA(lo_writer) = cl_sxml_string_writer=>create( if_sxml=>co_xt_json ).
CALL TRANSFORMATION id
SOURCE records = lt_result
RESULT XML lo_writer.
DATA(lv_json_hex) = lo_writer->get_output( ).
DATA(lv_json_string) = cl_abap_codepage=>convert_from( lv_json_hex ).
NEW-LINE.
BREAK-POINT.
I am using CALL TRANSFORMATION to seralize the internal table lt_result into JSON.
The corresponding result looks as follows:
{
"RECORDS": [
{
"MATNR": "PD-MAT1",
"MTART": "FERT",
"MATKL": ""
},
{
"MATNR": "STANDARD",
"MTART": "FERT",
"MATKL": ""
},
{
"MATNR": "ZQFH_TEST",
"MTART": "ROH",
"MATKL": ""
},
{
"MATNR": "ZZTESTJW",
"MTART": "HAWA",
"MATKL": "01"
},
{
"MATNR": "JW01",
"MTART": "DIEN",
"MATKL": "01"
}
]
}
When dealing with many many datasets this JSON format is not efficient, since it contains many overhead. In particular, I want to get rid of the column names and only retrieve the actual values of each record. I would appreciate if my JSON contains one a record level a JSON array that covers all the record's values.
Anyone who knows how to accomplish this?
Thanks!
Marco