cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve data from a fieldymbol nested of deep structures

Georg-Stefan
Explorer
0 Kudos
305

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:

GeorgStefan_0-1728910537355.png

I  assign it to <data>. with  assign lo_json_data->to <data>.

GeorgStefan_0-1728911155742.png

To show the structure of <data> I see the first level of the JSON-structure "OBJECTS"

GeorgStefan_1-1728911222558.png

When clicking on "OBJECTS" I get the second deep structure level "OBJECT":

GeorgStefan_2-1728911319511.png

The deep structure OBJECT again contains the deep structure PROPERTIES:

GeorgStefan_3-1728911388453.png

And the table PROPERTIES contains a undefined number of "basetypes" 

<DATA>-OBJECTS[1]-OBJECT-PROPERTIES

GeorgStefan_4-1728911447589.png

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

GeorgStefan_5-1728911548546.png

The VALUE can contain sometimes two ore more values:

<DATA>-OBJECTS[1]-OBJECT-PROPERTIES-%CSECONDARYOBJECTTYPEIDS-VALUE

GeorgStefan_6-1728911626935.png

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?

View Entire Topic
juan_suros
Contributor
0 Kudos

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.

Georg-Stefan
Explorer
0 Kudos
Hi Juan, thank you very much for your hint. I will try whether this might help and keep you up to date.
Georg-Stefan
Explorer
Thank you again Juan. With your hint I could solve the problem: