2

I am trying to implement deep insert for the multiple tables by doing the associations and navigation. I can able to post the data with parent and subparent values but i am facing the issue with fetching the values for sub parent children.

this is my payload how it looks like.

{
    "d": {
        "Gjahr": "2019",
        "INVTODATE": [{
            "Iblnr": " ",
            "Zldat": "2019-12-16T00:00:00"
        }],
        "INVTOITEM": [{
            "Material": "254620",
            "Item": "1",
            "EntryQnt": "200",
            "EntryUomIso": "EA",
            "ITEMTOSERIALS": [{
                "Item": "1",
                "Serialno": [{
                    "Serialno": "233"
                }, {
                    "Serialno": "233"
                }]
            }]
        }]
    }
}

in the above payload, "ITEMTOSERIALS" is the children for the "INVTOITEM" subparent. Here I could able to get the posted values till sub parent(deep insert).

This is the code which I am using to fetch the deep insert values

 CASE lv_entityset_name.
      WHEN 'INVENTORYSet'.
        io_data_provider->read_entry_data( IMPORTING es_data = ls_deep ).
        ls_inventory-iblnr = ls_deep-iblnr.
        ls_inventory-gjahr = ls_deep-gjahr.
        LOOP AT ls_deep-INVTODATE INTO ls_date.
         ls_dates-zldat = ls_date-zldat.
        ENDLOOP.

        LOOP AT ls_deep-INVTOITEM INTO ls_item.
         IF ls_item-entry_qnt EQ 0.
            ls_item-zero_count = 'X'.
            ELSE.
           ls_item-entry_qnt = ls_item-entry_qnt.
           ENDIF.
          MOVE-CORRESPONDING ls_item TO ls_items.
          APPEND ls_items TO lt_items.
          ENDLOOP.


LOOP AT ls_deep-ITEMTOSERIALS INTO ls_serials.
  MOVE-CORRESPONDING ls_serials TO ls_serials1.
  APPEND ls_serials1 TO lt_serials.
  ENDLOOP.

Is there any solution to fetch the sub parent children values? or Is there anything I need add it in Association?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 3
    There is an answer [here](https://answers.sap.com/questions/12935491/how-to-read-the-deep-insert-values-for-sub-parent.html) – Sandra Rossi Dec 19 '19 at 15:02

1 Answers1

0

It's not an answer to this particular scenario (at least not in abap), but rather a generic answer about consuming odata services and retrieving data from navigation properties. At least this is the answer I was looking for when I first found this question, when looking for the same info to use in SAPUI5 app.

When you call an odata service you call it at base level by default and it will not retrieve anything from navigation properties (I hear it can be used adaptively in Odata 4, but I haven't personally tested it). To retrieve data from navigation (association) you need to use expand parameter in ODATA service call to get it to retrieve the navigation result.

expand is a generic odata parameter that is added to service call, but its implementation varies in different frameworks. Abap might use a specific function/method to achieve this while SAPUI5 actually allows you to use uses generic parameters.

What you need to look for is how to implement expand parameter in whatever framework/language you are using to call the service.


Few examples:

Let's say your service returns Orders which have an id, some other fields on the same level and a navigation property ( or association) to items. When you read order by id, your service call will look something like Orders( id EQ 12345 ) and the actual data you retrieve will be:

Order: { id: 12345,
         //otherFields
       }

To retrieve data from navigation properties of the service (let's say items) you need to use expand parameter with the service call, to make the service call look like Orders( id EQ 12345)?$expand=items which will now return items too.

    Order: { id: 12345,
         //otherFields
         items: [{<item data>},{<item data>}....]
       }

If you need more than one deep structures expanded you simply specify them all $expand=items,BusinessPartner and if you need to go into even deeper layers you only specify the deepeset layer $expand=BusinessPartner/Address (will return business partner structure and an address structure within business partner structure.

You can combine the latter 2 if you need to: $expand=items,BusinessPartner/Address.

Zero
  • 1,562
  • 1
  • 13
  • 29