Easy way to write data via a deep entity in OData - SAP Community
Easy way to write data via a deep entity in OData - SAP Community
m
m
Products and Technology Groups Partners Topics Events What's New Get Start
u
ni
t
y
SAP Community Products and Technology Technology Technology Blogs by Members
Easy way to write data via a deep entity in OData
kallolathome
Active Participant
2022 Feb 23 8:43 AM
19 Kudos 86,876
Introduction
I have seen many tutorials based on OData but I really found them complex for
beginners.
So, I am writing this blog post for quick easy reference. This is the 2nd blog post in the
series.
For the first post please check the Easy way to read data via a deep entity in OData.
Solution
Please follow the steps:
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 1/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 2/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 3/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
5. Create Association
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 4/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
8. Click on the Direct Type Entry button. Then, create the deep structure &
activate.
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 5/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
1 *--------------------------------------------------------
2 ------------*
3 * Deep Structure
4 *--------------------------------------------------------
5 ------------*
6 TYPES: BEGIN OF ty_deep_entity,
vbeln TYPE vbeln_va, "Sales
7 Document
8 erdat TYPE erdat, "Date on
which the record was created
9 erzet TYPE erzet, "Entry time
10 ernam TYPE ernam, "Name of
Person who Created the Object
11 vkorg TYPE vkorg, "Sales
Organization
12 * Navigation property name should be used otherwise empty
13 records will be shown
headertoitem TYPE TABLE OF
ts_sales_item_data WITH DEFAULT KEY,
END OF ty_deep_entity.
*--------------------------------------------------------
------------*
N.B:
The navigation property name should be used in case of a deep entity like shown in
the image above otherwise, empty records will be returned.
Do not regenerate the service before taking the backup as it will delete all the
custom structures.
Just redefine the basic methods: *GET_ENTITY & *GET_ENTITYSET of the entities
for easy troubleshooting. No need to write any code within the methods. The
$expand keyword will call only the GET_EXPANDED_ENTITYSET method.
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 6/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 7/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
METHOD
/iwbep/if_mgw_appl_srv_runtime~create_deep_entity.
37 CATCH cx_root.
38 "Error during insert
39 ENDTRY.
40 ENDIF.
ENDIF.
CATCH /iwbep/cx_mgw_tech_exception.
"Do Nothing[
ENDTRY.
ENDMETHOD.
N.B: Here, the OPEN SQL statement is used to insert/update entries in the
database tables. It's better to use FMs/Methods for the same.
11. Input: Go to the HTTP Request section then enter your JSON/XML file & select the
radio button POST & execute.
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 9/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
1 {
2 "Vbeln" : "0000032183",
3 "Erdat" : "\/Date(1481760000000)\/",
4 "Erzet" : "TEST0000001",
5 "Ernam" : "Kallol",
6 "Vkorg" : "1710",
7 "HeaderToItem" : [
8 {
9 "Vbeln" : "0000032183",
10 "Posnr" : "000010",
11 "Matnr" : "MZ-FG-M550",
12 "Arktx" : "M550 BIKE",
13 "Posar" : ""
14 },
15 {
16 "Vbeln" : "0000032183",
17 "Posnr" : "000020",
18 "Matnr" : "LMO-PRD-M121",
19 "Arktx" : "1ortable DVD Player PDP-121",
20 "Posar" : ""
21 },
22 {
23 "Vbeln" : "0000032183",
24 "Posnr" : "000030",
25 "Matnr" : "MZ-FG-C950",
26 "Arktx" : "C950 BIKE",
27 "Posar" : ""
28 }
29 ]
30 }
12. Output
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 10/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
That's it.
N.B: This is not a proper way to update the database tables. Please use FMs/Methods for
the same otherwise there will be discrepancies. This blog post is only for showing how
the insert happens via a deep entity. You can manipulate the code according to your
requirements.
If I have missed something, please feel free to add it in the comment section so that, this
post can be useful to others.
Tags:
8 Comments
swamy1
Explorer
2022 Jun 03 4:44 AM
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 11/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
0 Kudos
HI kallolathome,
we are creatingl create deep entity with ref to your post we are getting: 'csrf token
validation failed' message how to overcome this.
bhaskar_chakraborty
Discoverer
2022 Nov 09 9:10 AM
0 Kudos
Just came accross your question today, probably bit too late for you.
But to use Create Deep Entity you first need to call the Get Method of the root entity and
pass the below parameter in Request Header.
x-csrf-token = fetch
You will get the value of xcrsf token in Response header. Then call the create deep entity
passing the xcsrf token in the request header which you earlier received. This should
solve your problem.
x-csrf-token = fnZX7zSr3JBG4oAB1uYrUg== => the value is just for egxample. This will
mostprobably be valid for 30 min depending on your system config.
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 12/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
eduardo_luiz_nunes_ribeir
Explorer
2022 Dec 28 12:23 AM
0 Kudos
A few years ago, if I updated the sales order tables like that, I would get fired.
Hey! I think I'll try to earn money playing video games and chatting!
RohitSingh
Explorer
2023 Jan 14 7:21 AM
0 Kudos
Is there any way to bind multiple Deep Entity structures on different Entity within same
SEGW project MPC_EXT-DEFINE method?
Thanks in advance.
malirahul
Member
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 13/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
2023 Apr 18 2:01 PM
0 Kudos
I got an error when I processed the same steps as mentioned by you. Please help me to
solve the below attach screenshot error.
kyo_choi2
Participant
2023 May 15 1:43 PM
0 Kudos
Excellent blog!!!
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 14/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
kapilmahire14
Explorer
2023 May 24 12:58 PM
0 Kudos
I followed all the above steps but thing is that when i Redefine the DEFINE method of
the ZCL_ZGW_PRACTICE006_MPC_EXT then my entityset data is not visible
@Gateway client.
Please suggest
DaddyBear
Discoverer
2024 May 29 3:50 PM
0 Kudos
Hi kapilmahire14.
So I built a DDIC structure with identifical properties, than removed DEFINE methods but
also custom types in MPC_EXT.
Bad news, impossible to submit the nested payload. It causes errors. Basically, only data
compatible with the URI entityset are accepted. The rest causes parsing issues.
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 15/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
I am seriously wondering if complex REST webservice from OData and ABAP is possible.
If anyone reads this and his a clue to propose, it might make my day for years !!!
Comment
ABAP 7.4 2 ABAP API 1 ABAP CDS VIEW 2 ABAP CDS Views 10
ABAP CDS Views - BW Extraction 3 ABAP CDS Views - CDC (Change Data Capture) 2
ABAP DDIC CDS view 1 ABAP Development 8 ABAP Environment & RAP 2
ABAP Platform Trial 2 ABAP Programming 5 ABAP Push Channels 1 ABAP RAP 2
ABAP String functions 1 abap technical 1 ABAP test cokpit 1 abap to xml 1
abapGit 1 absl 2 Access data from datasphere to ADF Azure Data Factory 2
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 16/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
Related Content
Use SAP CAP SAPUI5 Smart Filter to Show Value Help that are not Associated
Entitites
in Technology Blogs by Members yesterday
Problem with request body mapper and how to write the code
in Technology Q&A Friday
https://community.sap.com/t5/technology-blogs-by-members/easy-way-to-write-data-via-a-deep-entity-in-odata/ba-p/13539510 17/18
10/8/24, 3:07 PM Easy way to write data via a deep entity in OData - SAP Community
former_member200339
Participant
Follow