on 2024 Oct 14 2:37 PM
Hi *.
I am just working on nested dynamic structures as output of a JSON deserializsation.
At the moment I don't know how to retrieve the data from this nested dynamic structure as I don't see how to get down to the lowest level of the structure. Perhaps you have an idea?
Is start with lo_json_data as output of a deserialization method defined as type ref to data.
lo_json_data type ref to data.
field-symbols: <data> type any,
<objects> type any.
assign lo_json_data->* to <data>.
I can assign the reference of lo_json_data to a field-symbol <data> of type any to just have a look on the data structure.
As I know the structure of the JSON-File
{
"objects":[
{
"object":{
"properties":{
"CbaseTypeId":{
"id":"CbaseTypeId",
"type":"id",
"cardinality":"single",
"value":"Cdocument"
},
"%CobjectTypeId":{
"id":"%CobjectTypeId!,
...
"%CcontentStreamDataLength":{
"id":"%CcontentStreamDataLength",
"type":"integer",
"cardinality":"single",
"value":47336
}
}
},
"pathSegment":"data"
}
],
"hasMoreItems":false
}
I can also define the (hopefully) corresponding ABAP based structure to be read bottom up:
types:
begin of ty_table_line,
tline type string,
end of ty_table_line.
types:
begin of ty_basetype,
id type string,
type type string,
cardinality type string,
value type standard table of table_line with empty key,
end of ty_basetype .
types:
begin of ty_property,
propertyname type string,
property type standard table of ty_basetype with empty key,
end of ty_property .
types:
begin of ty_object,
properties type standard table of ty_property with empty key,
end of ty_object .
types:
begin of ty_objects,
object type standard table of ty_object with empty key,
pathsegment type string,
end of ty_objects .
types:
begin of ty_table,
objects type standard table of ty_objects with empty key,
hasmoreitems(1),
end of ty_table .
From the deserialization-Method I get lo_json_data as a deep structure.
The debugger shows me:
I assign it to <data>. with assign lo_json_data->* to <data>.
To show the structure of <data> I see the first level of the JSON-structure "OBJECTS"
When clicking on "OBJECTS" I get the second deep structure level "OBJECT":
The deep structure OBJECT again contains the deep structure PROPERTIES:
And the table PROPERTIES contains a undefined number of "basetypes"
<DATA>-OBJECTS[1]-OBJECT-PROPERTIES
Every basetype is structured with an ID, TYPE, CARDINALITY and a VALUE-Table,
like the basetype %CSECONDARYOBJECTTYPEIDS as example.
<DATA>-OBJECTS[1]-OBJECT-PROPERTIES-%CSECONDARYOBJECTTYPEIDS
The VALUE can contain sometimes two ore more values:
<DATA>-OBJECTS[1]-OBJECT-PROPERTIES-%CSECONDARYOBJECTTYPEIDS-VALUE
I get stuck iterating to the bottom of the deep structures even though I know the structure is always the same.
<DATA>-OBJECTS[1]-OBJECT-PROPERTIES
Any hints or ideas?
Request clarification before answering.
You are looking for a bunch of loops, I think:
DATA:
lt_data TYPE ty_table.
FIELD-SYMBOLS:
<objects> TYPE ty_objects,
<object> TYPE ty_object,
<property> TYPE ty_property,
<basetype> TYPE ty_basetype,
<line> TYPE table_line. "ty_table_line.
LOOP AT lt_data-objects ASSIGNING <objects>.
LOOP AT <objects>-object ASSIGNING <object>.
LOOP AT <object>-properties ASSIGNING <property>.
LOOP AT <property>-property ASSIGNING <basetype>.
LOOP AT <basetype>-value ASSIGNING <line>.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
You will replace lt_data with <data> in your example.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
29 | |
9 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.