Skip to Content

Hi everyone,

Below example shows how to pass multiple nested tables as input to odata/gateway service using SEGW approach.

We have  6 tables.


1.      Header (Fields: ID, Name, Message_text)

    • Item1 (Fields: ID, Name1, Address)
      • Item 1.1 (Fields: ID, Name, State, Country)
      • Item 1.2 (Fields: Fname, Mname, LName)
    • Item2 (Fields: ID, Name, City)
      • Item2.1 (Fields: ID,Name,Pincode,Street)


Item1 and item2 are inline to Header table.

Item1.1 and item 1.2 are inline to item1 table.

Item 2.1 is inline to item 2 table

In multi deep insert, we should be able to pass multiple line items in item1 , item 1.1 , item 1.2, item 2 and  item2.1 along with the data in header structure.

  1. e.g.

Input to the service:

   

/wp-content/uploads/2014/10/oo_575143.png


Output from the service:


Input.png


Value of Message_text in header structure is changed to
Test1.


Steps to achieve the above scenario:

Step1. Create 6 entity types Header, Item1 and item2,Item1_1,Item1_2,Item2_1.

                  

Entitytypes.png      /wp-content/uploads/2014/10/entity_types_2_574623.png

Properties are:

Header:

/wp-content/uploads/2014/10/header_574624.png

Item1:

/wp-content/uploads/2014/10/item1_574625.png

Item1_1:

/wp-content/uploads/2014/10/item1_1_574626.png

Item1_2:

/wp-content/uploads/2014/10/item1_2_574627.png

Item2:

/wp-content/uploads/2014/10/item2_574628.png

Item2_1:

/wp-content/uploads/2014/10/item2_1_574629.png

*************************************************************************************************************************************************************

Step2. Create entity sets HeaderSet, item1Set, item2Set,item1_1Set,item1_2Set,item2_1Set.

/wp-content/uploads/2014/10/entity_sets_574630.png

*************************************************************************************************************************************************************

Step3: Create Associations between entity types:


1. Header – item1

2. Header – item2

3. Item1–Item1.1

4. Item1–item1.2

5. Item2–Item2.1

Associations.png

      

Navigation properties get created automatically under entity type: header , Item1 and Item2

/wp-content/uploads/2014/10/navigation_header_574632.png  /wp-content/uploads/2014/10/navigation_item1_574633.png      /wp-content/uploads/2014/10/navigation_item2_574634.png

*************************************************************************************************************************************************************

Step4: Save and Check for any error.

Step5: Generate Runtime classes and Services

Step6: Register Service in gateway hub.

Step7: Go to DPC_Ext class in ABAP Workbench.

Step8: Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET –

This method is redefined to get Request payload of Multi deep insert.

Step9: Inside GET_EXPANDED_ENTITYSET,

/wp-content/uploads/2014/10/code1_574635.png

ITEM1TOITEM1_1 and ITEM1TOITEM1_2 are names of navigation properties for table item1


ITEM2TOITEM2_1 IS navigation property for table item2


HEADERITEM1 and HEADERITEM2 are navigation properties for table header

Insert data in the Structures.

Code2.png

Add 3 entries in table et_expanded_tech_clause to specify to framework that there are  inline entities to the base entity(values to be inserted are Navigation properties).(Absence of this code will hit the get_expanded_entityset method 6 times for all the entities created.


Insert data in the respective structures and tables(header,item1 and item2,item1.1,item1.2,item2.1) and Append that data in the final


Copy_data_to_ref.png

Save and Activate.

Step 10: Form the URL.

URL.PNG

HTTP method : GET

Execute (F8).

******************************************************************************************************************************************************

Step11: Use the response from the above request to create request payload of Multi Deep Insert.

(Remove feed tag below first line and end feed tag)

Step12: Once Request payload is generated, redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY

Inside /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY,

Declare the output structure.

/wp-content/uploads/2014/10/output_structure_574640.png

Read the data sent by the user through request payload into structure ls_headeritem.

/wp-content/uploads/2014/10/ls_headeritem_574641.png

Change the message_text of Header structure .

ls_headeritem-message_text = ‘Test1’.

Call Copy_data_to_ref and pass ls_header_item as structure.

Step 13: Form the URL.

URL:

/sap/opu/odata/sap/ZGW_CREATEDEEP_66883_SRV/headerSet


Method: POST.

Execute (F8).

This way we can implement such scenarios.

Thanks,

Anjor Wagle.





To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. Cesar Felce

    Hi Anjor,

    Thanks for this blog, i have a doubt in Step 11.

    “Step11: Use the response from the above request to create request payload of Multi Deep Insert.

    (Remove feed tag below first line and end feed tag)”

    I don’t see any image below.

    I only use header/item navigation property but i’m receiving an error:

    “The server is refusing to process the request because the entity has a unsupported format”

    The Service is calling the /IWCOR/IF_DS_PROC_ENTITY_SET~CREATE_ENTITY instead and not the CREATE_DEEP_ENTITY.

    My request URI is: /sap/opu/odata/sap/ZSD_CREATE_SO_SRV/SalesOrderCollection and is because I don’t now what to remove in step 11.

    “Remove feed tag below first line and end feed tag”

    Any help?

    Kind Regards,

    César

    (0) 
    1. Cesar Felce

      Hi Anjor,

      I figure it out..

      In Step 11, you can’t use the request payload of the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET you have to redefine the /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY and then use this one for the POST.

      Thanks for the blog again!

      Kind Regards,

      César

      (0) 
  2. Diego Valencia

    Hi Anjor,

    Excellent port! Thank a lot.

    I have a problem when reading the payload I can get header and first level entity (item1) but item1_1 inline is empty. I’ve already checked the names of navigation properties, everything is ok, and I also tried by reading item1/item1_1 data and it works.  Any help would be appretiated, I’m really stucked here…

    (0) 
  3. Pratyush Pal

    Hi It is working for XML format but not working for Json format.

    Getting error “Error while Parsing an XML Stream”

    But the same is worink fine with XML format.

    (0) 
  4. Inderpal Singh Bhangoo

    How will we use the POST method for deep entity if we have multiple level of associations.

    /sap/opu/odata/SAP/ZCREATE_SALES_ORDER/SOHeaderSet?$expand=NavToItem,NavToHTexts,NavToItem/NavToSllines,NavToItem/NavToTexts

    It is giving error:

    The Data Services Request contains SystemQueryOptions that are not allowed for this Request Type

    The same link works for GET but not for POST.

    The association is linked as :

    1. Header to Item.   (NavToItem)

    2. Header to Header Texts. (,NavToHTexts)

    3. Item to Schedule Lines. (,NavToItem/NavToSllines)

    4. Item to Item Texts (NavToItem/NavToTexts)

    (0) 
    1. Rahul Gaikwad

      During create there is no need to pass query string parameters. Just call with /sap/opu/odata/SAP/ZCREATE_SALES_ORDER/SOHeaderSet and pass all the required entries and feed with xml and use  io_data_provider->read_entry_data to read the actual feed

      (0) 

Leave a Reply