Skip to Content
Author's profile photo Kanwardeep Singh Gill

Expand Parent Child Entities in a Single Expansion – GET_EXPANDED_ENTITYSET

Working on first gateway project and being asked to expand the parent child entities linked with Navigation Property with a single expansion or RFC call requires quite a bit of self learning. However, when explored the internet, I could not find blogs/links which explained in detail how to use Expansion Method of the Gateway to expand both Parent and Child Entity in a single RFC call, rather than making call first to parent entity and then to the child using $EXPAND parameter in the Odata Service Link.

This scenario is more appropriate for Gateway Hub scenario where in GW(GW_CORE, I_BEP and IW_FND) and ECC are separate systems. An RFC call is made from GW to ECC each time data is requested from UI. Therefore, if the user needs to fetch the Parent Child data using $EXPAND, the gateway framework will first call the entity set for the Parent(SOHeaderSet) and then the entity set for Children(SOItemSet). This results in 2 RFC call to fetch the required data.

In this blog, we will learn how we can reduce 2 RFC calls to a single RFC call and expand both the Parent and Child Entities in a single Odata Service Call.

In order to implement this, we will re define ‘GET_EXPANDED_ENTITYSET’ Method of the Data Provider Class.

In this example, we will use 2 entities Sales Order Header(SOHeader) and Sales Order Item(SOItem). Both are linked to each other with a navigation property SOHeaderToItem.

Entities.PNG

SOHeader.PNG

SOItem.PNG

Association.PNG

Navigation.PNG

Redefine GET_EXPANDED_ENTITYSET as explained in the attached snapshot.

GET_EXPANDED_ENTITYSET.PNG

The catch here is that, we have to tell the GW framework that we have expanded both the Header and Item entities in a single entity set call and no need to call the child entity set to fetch the the Sales Order Items. We can do this using parameter ET_EXPANDED_TECH_CLAUSES of GET_EXPANDED_ENTITYSET. Append the Navigation Property Name(SOHEADERTOITEM) in this exporting parameter, which will tell the gate way framework that the child entity has already been expanded and there is no need to call the child entity set.

An important point to not here is that the structure of the output entity set should have a field with Name same as Navigation Property Name(SOHEADERTOITEM). This field has to be a Table Type to support Header and Item relationship structure. Check structure below.

Structure.PNG

When you will call the Odata Service from the Client with $EXPAND, only the Header Entity Set will be called and no call is made to the Item Entity Set.

https://<Host Server:Port>/sap/opu/odata/sap/ZEXPAND_PARENT_CHILD_SRV/SOHeaderSet?$expand=SOHeaderToItem

In normal expansion scenario with $EXPAND, the gateway framework would first call SOHeaderSet and then the corresponding SOItemSet.

Thanks!!!!

Assigned Tags

      15 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Timothy Muchena
      Timothy Muchena

      Hi

      Excellent blog and thank you

      Can you please provide the structure of ZSO_S_HEADER and ZSO_IT_ITEM.

      Kind regards

      Author's profile photo Kanwardeep Singh Gill
      Kanwardeep Singh Gill
      Blog Post Author

      Hi Tim,

      ZSO_S_HEADER.PNG

          ZSO_S_ITEM.PNG

         

         ZSO_TT_ITEM is table type of ZSO_S_ITEM.

      Thanks!!!!

      Author's profile photo Vikas Madaan
      Vikas Madaan

      Too Good.

      Author's profile photo Former Member
      Former Member

      Great write up.. .!!

      Happy learning and Keep Sharing ||

      Author's profile photo chitti babu
      chitti babu

      Hi Gill,

          Thanks for sharing a wonderful example.I tried this example i am getting only the item data,header fields showing empty data like this

      "Vbeln": "",

                      "Auart": "",

                      "Vkorg": "",

                      "Vtweg": "",

                      "SOHeaderToItem": {

                          "results": [

      can u help me Please to complete this scenario.

      Thanks&Regards

      chitti babu

      Author's profile photo Kanwardeep Singh Gill
      Kanwardeep Singh Gill
      Blog Post Author

      HI Chitti,

      Kindly put  a break point in the GET_EXPANDED_ENTITYSET method of the DPC extension class and debug through Gateway Client /IWFND/GW_CLIENT to ensure that you are populating the header data properly.

      I don't see any reason why header data should not be populated in the output, if the item data is getting populated.

      If the data is populated properly, kindly share the code which you have written to support expanded entity set and I'll look into it.

      Thanks!!!!

      Author's profile photo Kanwardeep Singh Gill
      Kanwardeep Singh Gill
      Blog Post Author

      Hi Chitti,

      If you have declared output structure ZSO_S_HEADERTOITEM as explained in this blog, there should not be any problem in populating and retrieving the data from the Odata Call.

      I would request you just not to copy the coding, but to follow the concept here.

      Thanks!!!

      Author's profile photo Arshad Ansary
      Arshad Ansary

      Hi Chitti,

      I also had the same issue but the problem lies with the way you delcare you output structure

      Make sure that the header structure is .INCLUDE  and not a separate structure name  like below.

      DATABEGIN OF t_orderitems.

        INCLUDE    TYPE  zcl_ztest_fw_expand_mpc_ext=>ts_salesorderitem.

        DATA: itemtoproduct TYPE  zcl_ztest_fw_expand_mpc_ext=>ts_product,

              END OF t_orderitems.

      Regards

      Arshad

      Author's profile photo chitti babu
      chitti babu

      Hi Ansary,

          Thanks for you response Please provide the example what you tried for GET_EXPANDED_ENTITYSET Please.

      Thanks&Regards

      chitti

      Author's profile photo Arshad Ansary
      Arshad Ansary

      Hi Chitti,

      I was referring to this link

      http://scn.sap.com/community/gateway/blog/2014/09/24/lets-code-associationnavigation-and-data-provider-expand-in-odata-service

      Please see how they have declared the Output structure in  GET_EXPANDED_ENTITYSET

      Regards

      Arshad

      Author's profile photo Pavan Golesar
      Pavan Golesar

      Was of great help... thanks...

      Regards,

      Pavan Golesar

      Author's profile photo Anju Jha
      Anju Jha

      Thanks Gill. This is nice blog. I have implemented gateway service for purchase order data in a similar way . While displaying output header data come after line item data.

      Is there any way to display header information before Line items?

      <title type="text">PoHeaderSet('4590092041')</title>

      <updated>2015-02-24T11:01:48Z</updated>

      <category term="Y_VRS_PO_SRV.PoHeader" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

      <link href="PoHeaderSet('4590092041')" rel="self" title="PoHeader" />

      - <link href="PoHeaderSet('4590092041')/PoLineitmSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PoLineitmSet" type="application/atom+xml;type=feed" title="PoLineitmSet">

      - <m:inline>

      - <feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="http://fssde1.target.com:8000/sap/opu/odata/sap/Y_VRS_PO_SRV/">

      <title type="text">PoLineitmSet</title>

      <updated>2015-02-24T11:01:48Z</updated>

      - <author>

      <name />

      </author>

      <link href="PoHeaderSet('4590092041')/PoLineitmSet" rel="self" title="PoLineitmSet" />

      - <entry>

      <title type="text">PoLineitmSet('4590092041')</title>

      <updated>2015-02-24T11:01:48Z</updated>

      <category term="Y_VRS_PO_SRV.PoLineitm" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

      <link href="PoLineitmSet('4590092041')" rel="self" title="PoLineitm" />

      - <content type="application/xml">

      - <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

      <d:LEbeln>4590092041</d:LEbeln>

      <d:LEbelp>00010</d:LEbelp>

      <d:LLoekz />

      <d:LAedat>2015-02-23T00:00:00</d:LAedat>

      <d:LTxz01>Supplies</d:LTxz01>

      <d:LBukrs>1001</d:LBukrs>

      <d:LWerks>0003</d:LWerks>

      <d:LMatkl>312117ZZ</d:LMatkl>

      <d:LIdnlf />

      <d:LMenge>6.000</d:LMenge>

      <d:LEindt>2015-02-28T00:00:00</d:LEindt>

      <d:LMeins>EA</d:LMeins>

      <d:LBprme>EA</d:LBprme>

      <d:LNetpr>15.00</d:LNetpr>

      <d:LNetwr>90.00</d:LNetwr>

      <d:LBrtwr>90.00</d:LBrtwr>

      <d:LMwskz>S1</d:LMwskz>

      <d:LErekz />

      <d:LAdrn2>457882</d:LAdrn2>

      <d:LSakto>7050270</d:LSakto>

      <d:LKostl>26100003</d:LKostl>

      <d:LPrctr>3</d:LPrctr>

      <d:LPspnr>00000000</d:LPspnr>

      <d:LPosid />

      <d:LStreet>5537 W BROADWAY AVE</d:LStreet>

      <d:LCity>CRYSTAL</d:LCity>

      <d:LCountry>US</d:LCountry>

      <d:LRegion>MN</d:LRegion>

      </m:properties>

      </content>

      </entry>

      - <entry>

      <title type="text">PoLineitmSet('4590092041')</title>

      <updated>2015-02-24T11:01:48Z</updated>

      <category term="Y_VRS_PO_SRV.PoLineitm" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

      <link href="PoLineitmSet('4590092041')" rel="self" title="PoLineitm" />

      - <content type="application/xml">

      - <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

      <d:LEbeln>4590092041</d:LEbeln>

      <d:LEbelp>00020</d:LEbelp>

      <d:LLoekz />

      <d:LAedat>2015-02-23T00:00:00</d:LAedat>

      <d:LTxz01>Supplies</d:LTxz01>

      <d:LBukrs>1001</d:LBukrs>

      <d:LWerks>0004</d:LWerks>

      <d:LMatkl>312117ZZ</d:LMatkl>

      <d:LIdnlf />

      <d:LMenge>3.000</d:LMenge>

      <d:LEindt>2015-02-28T00:00:00</d:LEindt>

      <d:LMeins>EA</d:LMeins>

      <d:LBprme>EA</d:LBprme>

      <d:LNetpr>15.00</d:LNetpr>

      <d:LNetwr>45.00</d:LNetwr>

      <d:LBrtwr>45.00</d:LBrtwr>

      <d:LMwskz>S1</d:LMwskz>

      <d:LErekz />

      <d:LAdrn2>457883</d:LAdrn2>

      <d:LSakto>7050270</d:LSakto>

      <d:LKostl>26100004</d:LKostl>

      <d:LPrctr>4</d:LPrctr>

      <d:LPspnr>00000000</d:LPspnr>

      <d:LPosid />

      <d:LStreet>ler Trunk Hwy</d:LStreet>

      <d:LCity>Duluth</d:LCity>

      <d:LCountry>US</d:LCountry>

      <d:LRegion>MN</d:LRegion>

      </m:properties>

      </content>

      </entry>

      - <entry>

      <title type="text">PoLineitmSet('4590092041')</title>

      <updated>2015-02-24T11:01:48Z</updated>

      <category term="Y_VRS_PO_SRV.PoLineitm" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

      <link href="PoLineitmSet('4590092041')" rel="self" title="PoLineitm" />

      - <content type="application/xml">

      - <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

      <d:LEbeln>4590092041</d:LEbeln>

      <d:LEbelp>00030</d:LEbelp>

      <d:LLoekz />

      <d:LAedat>2015-02-23T00:00:00</d:LAedat>

      <d:LTxz01>Supplies</d:LTxz01>

      <d:LBukrs>1001</d:LBukrs>

      <d:LWerks>0005</d:LWerks>

      <d:LMatkl>312117ZZ</d:LMatkl>

      <d:LIdnlf />

      <d:LMenge>4.000</d:LMenge>

      <d:LEindt>2015-02-28T00:00:00</d:LEindt>

      <d:LMeins>EA</d:LMeins>

      <d:LBprme>EA</d:LBprme>

      <d:LNetpr>15.00</d:LNetpr>

      <d:LNetwr>60.00</d:LNetwr>

      <d:LBrtwr>60.00</d:LBrtwr>

      <d:LMwskz>S1</d:LMwskz>

      <d:LErekz />

      <d:LAdrn2>457884</d:LAdrn2>

      <d:LSakto>7050270</d:LSakto>

      <d:LKostl>26100005</d:LKostl>

      <d:LPrctr>5</d:LPrctr>

      <d:LPspnr>00000000</d:LPspnr>

      <d:LPosid />

      <d:LStreet>2555 W 79th St</d:LStreet>

      <d:LCity>BLOOMINGTON</d:LCity>

      <d:LCountry>US</d:LCountry>

      <d:LRegion>MN</d:LRegion>

      </m:properties>

      </content>

      </entry>

      - <entry>

      <title type="text">PoLineitmSet('4590092041')</title>

      <updated>2015-02-24T11:01:48Z</updated>

      <category term="Y_VRS_PO_SRV.PoLineitm" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

      <link href="PoLineitmSet('4590092041')" rel="self" title="PoLineitm" />

      - <content type="application/xml">

      - <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

      <d:LEbeln>4590092041</d:LEbeln>

      <d:LEbelp>00040</d:LEbelp>

      <d:LLoekz />

      <d:LAedat>2015-02-23T00:00:00</d:LAedat>

      <d:LTxz01>Supplies</d:LTxz01>

      <d:LBukrs>1001</d:LBukrs>

      <d:LWerks>0012</d:LWerks>

      <d:LMatkl>312117ZZ</d:LMatkl>

      <d:LIdnlf />

      <d:LMenge>2.000</d:LMenge>

      <d:LEindt>2015-02-28T00:00:00</d:LEindt>

      <d:LMeins>EA</d:LMeins>

      <d:LBprme>EA</d:LBprme>

      <d:LNetpr>15.00</d:LNetpr>

      <d:LNetwr>30.00</d:LNetwr>

      <d:LBrtwr>30.00</d:LBrtwr>

      <d:LMwskz>S1</d:LMwskz>

      <d:LErekz />

      <d:LAdrn2>457885</d:LAdrn2>

      <d:LSakto>7050270</d:LSakto>

      <d:LKostl>26100012</d:LKostl>

      <d:LPrctr>12</d:LPrctr>

      <d:LPspnr>00000000</d:LPspnr>

      <d:LPosid />

      <d:LStreet>12275 Saint Charles Rock Rd</d:LStreet>

      <d:LCity>Bridgeton</d:LCity>

      <d:LCountry>US</d:LCountry>

      <d:LRegion>MO</d:LRegion>

      </m:properties>

      </content>

      </entry>

      </feed>

      </m:inline>

      </link>

      - <content type="application/xml">

      - <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

      <d:HEbeln>4590092041</d:HEbeln>

      <d:HBukrs>1001</d:HBukrs>

      <d:HBsart>ZB</d:HBsart>

      <d:HAedat>2014-12-18T00:00:00</d:HAedat>

      <d:HErnam>CSVA01</d:HErnam>

      <d:HLifnr>6255</d:HLifnr>

      <d:HEkorg>1001</d:HEkorg>

      <d:HEkgrp>100</d:HEkgrp>

      <d:HWaers>USD</d:HWaers>

      <d:HBedat>2014-12-18T00:00:00</d:HBedat>

      <d:HKonnr />

      <d:HFrgrl />

      <d:HName1>SAM MORRAY DESIGN LIMITED</d:HName1>

      <d:Timestamp />

      <d:Doctypestr />

      <d:Maxpos />

      <d:Vendorstr />

      <d:HChngtimestamp>20150223151511</d:HChngtimestamp>

      <d:HJobtimestamp>20150224050148</d:HJobtimestamp>

      <d:Sitestr />

      </m:properties>

      </content>

      </entry>

      - <entry>

      Thanks,
      Anju
      Author's profile photo Rohan Sriram
      Rohan Sriram

      Nice Blog..I Achieved it successfully after trying many number of times..Thank you

      Author's profile photo David Raven
      David Raven

      Hi,

      My rfc is more simple and still do not success calling it from gateway.

      Lets say I have a field id in import and a table in tables. The rfc return data in table using the id field. How can I fetch the table?

      Do I have to use the expand mode?

       

      Thank you,

       

      Regards.

      Author's profile photo Adnan Maqbool
      Adnan Maqbool

      Nice blog, please also explain how to bind expanded entitysets with different drop down boxs