Multi-deep insert in SAPGateway(SEGW Approach)
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.
- e.g.
Input to the service:
Output from the service:
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.
Properties are:
Header:
Item1:
Item1_1:
Item1_2:
Item2:
Item2_1:
*************************************************************************************************************************************************************
Step2. Create entity sets HeaderSet, item1Set, item2Set,item1_1Set,item1_2Set,item2_1Set.
*************************************************************************************************************************************************************
Step3: Create Associations between entity types:
1. Header – item1
2. Header – item2
3. Item1–Item1.1
4. Item1–item1.2
5. Item2–Item2.1
Navigation properties get created automatically under entity type: header , Item1 and Item2
*************************************************************************************************************************************************************
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,
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.
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
Save and Activate.
Step 10: Form the URL.
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.
Read the data sent by the user through request payload into structure ls_headeritem.
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.
Nice one Anjor. Very Helpful 🙂
Very helpful indeed Anjor. Great Work !! Thumbs Up !! 🙂
very helpful..!! 🙂 good..!!
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
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
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...
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.
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)
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