‎2020 Dec 15 5:28 PM
I'm trying to deserialize a JSON with a variable sequential name:
{
"Records" : {
"0" : { },
"1" : {
"documentType" : "Organization",
"status" : "published",
"selectAttributes" : [ "SystemID", "Name", "TimeCreated" ],
"filterExpressions" : [ {
"name" : "createdDateFrom",
"field" : "TimeCreated",
"op" : ">=",
"defaultValue" : "2017-11-05T01:01:59Z"
}, {
"name" : "createdDateTo",
"field" : "TimeCreated",
"op" : "<=",
"defaultValue" : "2017-11-06T01:01:59Z"
} ],
"viewTemplateName" : "RfxItemSummaryFactSystemView",
"type" : "custom"
},
"2" : {
"documentType" : "DynamicFormDocument_CaixaContract",
"status" : "published",
"selectAttributes" : [ "LoadCreateTime", "LoadUpdateTime", "ParentAgreement", "DFormId", "DetailLineNumber", "SourceSystem", "AclId", "FlexTypeId", "cus_ExistecesidedatosalPr" ],
"filterExpressions" : [ {
"name" : "updatedDateFrom",
"field" : "TimeCreated",
"op" : ">=",
"defaultValue" : "2017-11-05T01:01:59Z"
}, {
"name" : "updatedDateTo",
"field" : "TimeCreated",
"op" : "<=",
"defaultValue" : "2017-11-06T01:01:59Z"
} ],
"viewTemplateName" : "test1",
"type" : "custom"
}
}
}
TYPES:
BEGIN OF ts_filter_expression,
name TYPE string,
field TYPE string,
op TYPE string,
default_value TYPE string,
END OF ts_filter_expression,
tt_filter_expressions TYPE STANDARD TABLE OF ts_filter_expression WITH EMPTY KEY.
TYPES:
BEGIN OF ts_view_template,
view_template_name TYPE string,
type TYPE string,
status TYPE string,
document_type TYPE string,
select_attributes TYPE STANDARD TABLE OF string WITH EMPTY KEY,
filter_expresions TYPE tt_filter_expressions,
END OF ts_view_template,
tt_view_templates TYPE STANDARD TABLE OF ts_view_template WITH EMPTY KEY.
DATA:
BEGIN OF data,
records TYPE tt_view_templates,
END OF data.
/ui2/cl_json=>deserialize(
EXPORTING
json = json
assoc_arrays = abap_true
assoc_arrays_opt = abap_true
CHANGING
data = data ).
How I can map the sequential field content to the table?
‎2020 Dec 27 10:49 AM
Hi Jaime ,
Instead of using strict types, You can use the below code to generate a dynamic object with content. Later you can use directly or convert it to your table type. I can use the generate method at SAP_UI 754. Maybe earlier not released.
DATA : lo_data TYPE REF TO data.
DATA: lv_json TYPE string.
lv_json = '{ "0": {}, "1": { "documentType": "Organization" }, "2": { "documentType": "Trial" } } '.
lo_data = /ui2/cl_json=>generate( json = lv_json ).
ASSIGN lo_data TO FIELD-SYMBOL(<lo_data>).
‎2020 Dec 29 10:34 AM