Skip to Content
Author's profile photo Former Member

How to implement multi-level create deep

This blog will explain how to implement multi-level create deep.

Prerequisite, please make sure you are familiar with create deep implementation via Gateway:

Step by Step development for CREATE_DEEP_ENTITY operation

For multi-level create deep, we assume this following scenario:

Scenario.PNG

Here, FirstSon & SecondSon are the first-level deep of father, FirstGrandSon is the first-level of FirstSon but second-level of Father.

Then How to implement this create-deep scenario?

1. Create entities/associations in SEGW which map to this relationship.

     Four entities are created: Father/FirstSon/SecondSon/FirstGrandson; Each entity has three properties: Key/Property1/Property2

     Three associations are created: “Father to FirstSon” & “Father to SecondSon” & “FirstSon to FirstGrandSon”

Data Model.PNG

2. Generate and register the ODate Service.

     I assume you are familiar with these general Gateway steps 🙂 .

3. Implement  create_deep_entity method.

     First create the multi-level deep structure which can holds the nested data from input; Then use  io_data_provider to get the input.

     Here I just write simple code snippet, as long as we can get nested data in the runtime.

Code.PNG

4. Test in RestClient

     I used to try to test the multi-level create deep in our traditional GW client and using XML format as payload. Nested data can be transferred into our create_deep_entity method, but the position of the nested data in second level is wrong. Thus, I strongly suggested to use JSON format as payload. Since our GW Client doesn’t have a good support json fromat. I recommend to use the RestClient. (In RestClient you have to first get CSRF token and then post)

    

Payload:

{

    “Key”: “Father-Key”,

    “Property1”: “Father-Property-1”,

    “Property2”: “Father-Property-2”,

    “FirstSon”: [

        {

            “Key”: “FirstSon-Key-1”,

            “Property1”: “Firstson-Property-1”,

            “Property2”: “Firstson-Property-2”,

            “FirstGrandson”: [

                {

                    “Key”: “GrandSon-Key-1”,

                    “Property1”: “GrandSon-Property-1”,

                    “Property2”: “GrandSon-Property-2”

                }

            ]

        },

        {

            “Key”: “FirstSon-Key-2”,

            “Property1”: “Firstson-Property-3”,

            “Property2”: “Firstson-Property-4”,

            “FirstGrandson”: [

                {

                    “Key”: “GrandSon-Key-2”,

                    “Property1”: “GrandSon-Property-3”,

                    “Property2”: “GrandSon-Property-4”

                },

                {

                    “Key”: “GrandSon-Key-3”,

                    “Property1”: “GrandSon-Property-5”,

                    “Property2”: “GrandSon-Property-6”

                }

            ]

        }

    ],

    “SecondSon”: [

        {

            “Key”: “SecondSon-Key-1”,

            “Property1”: “SecondSon-Property-1”,

            “Property2”: “SecondSon-Property-2”

        },

        {

            “Key”: “SecondSon-Key-2”,

            “Property1”: “SecondSon-Property-3”,

            “Property2”: “SecondSon-Property-4”

        },

        {

            “Key”: “SecondSon-Key-3”,

            “Property1”: “SecondSon-Property-5”,

            “Property2”: “SecondSon-Property-6”

        }

    ]

}

5. Check if the multi-level nested data is mapping to the right position in our runtime.

   

Father-level data:

Father.PNG

Son-level data (deep to father):

FirstSon.PNG Second.PNG

Grandson-level data (deep to FirstSon):

     FirstSon[1] has one entry; FristSon[2] has two entry; as payload expected.

Grandson1.PNG Grandson2.PNG

Now we get the multi-level nested data in the right position, then we can do anything we want in following 🙂 .



Hope it helps!

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Giridharan Somaskandan
      Giridharan Somaskandan

      nice blog Yis

      Author's profile photo Vishal Hingole
      Vishal Hingole

      Nice Bolg.. 🙂

      Author's profile photo Former Member
      Former Member

      Nice Blog, Thanks for sharing.

      Author's profile photo Avinash Kasha
      Avinash Kasha

      HI,

      When i tried above steps i did get below error:

      Method 'FATHERSET_GET_ENTITYSET' not implemented in data provider class

      URI: /sap/opu/odata/SAP/ZPOC_152_C_SRV/FatherSet

      Author's profile photo Prakash Mani
      Prakash Mani

      I think you have used Get method, use POST .

      Author's profile photo Vishnu Kothuru
      Vishnu Kothuru

      Clear n Crisp Explanation, Thanks 🙂