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.
Redefine GET_EXPANDED_ENTITYSET as explained in the attached snapshot.
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.
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.
In normal expansion scenario with $EXPAND, the gateway framework would first call SOHeaderSet and then the corresponding SOItemSet.
Excellent blog and thank you
Can you please provide the structure of ZSO_S_HEADER and ZSO_IT_ITEM.
ZSO_TT_ITEM is table type of ZSO_S_ITEM.
Great write up.. .!!
Happy learning and Keep Sharing ||
Thanks for sharing a wonderful example.I tried this example i am getting only the item data,header fields showing empty data like this
can u help me Please to complete this scenario.
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.
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.
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.
DATA: BEGIN 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.
Thanks for you response Please provide the example what you tried for GET_EXPANDED_ENTITYSET Please.
I was referring to this link
Please see how they have declared the Output structure in GET_EXPANDED_ENTITYSET
Was of great help... thanks...
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?
Nice Blog..I Achieved it successfully after trying many number of times..Thank you
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?
Nice blog, please also explain how to bind expanded entitysets with different drop down boxs