Skip to Content

Step by Step development for CREATE_DEEP_ENTITY operation

This blog I will explain creation of SAP NW GW OData service which will implement  Create Deep Entity operation.


SAP documentation for deep understanding.


Deep Insert – SAP NetWeaver Gateway – SAP Library


Create Custom RFC  given below Structures.


Structure-1 – Header

Structure-2 – ItemO

Structure-3 – ItemT


1-rfc-sig.PNG21-st-head.PNG2-str-head.PNG22-st-itmt.PNG


Create Project in SEGW

Create three entity types and Entity Sets


Entity Type-1- Header    

Entity Type-2- ItemO

Entity Type-3- ItemT


Entity Set-1- HeaderSet

Entity Set-2- ItemOSet

Entity Set-3- ItemTSet



Entity Type – Header

segw-1.PNG

Entity Type – ItemO

segw-1-itemo.PNG

Entity Type – ItemT

segw-2-itemt.PNG

Entity Sets –  HeaderSet,ItemOSet,ItemTSet

segw-eneitysets.PNG



Create Associations given below


Association-1 –  Header_ItemO (Without key fields mapping)

Association-2 –  Header_ItemT (Without key fields mapping)


asso-1-2.PNG


Create Navigation given below


Navigation-1 –  HeadItemO

Navigation-2 –  HeadItemT


novg-1-2-.PNG


Now let’s generate runtime artifacts. Click on generate runtime objects button. It will display

popup . Keep the default class names as-is and click on enter button.

Once generation is successful, you will get 4 classes. 2 for Data provider and 2 for Model provider.

serv-reg.PNG

Once registration done successfully .Goto Gateway Client ( call transaction /IWFND/GW_CLIENT to open SAP NW Gateway client)

Append $metatda to base service URL and press execute button. If everything is fine then you will HTTP

Response as below. Metadata provides information such as Entity type, key property, properties and Entity Set

name and also check service document append ?$format=xml.

metadata.PNGservice doc.PNG

Build Types for Deep Entity

build-deep-str.PNGbuild-deep-str2.PNG

Code Snippet


*———————————————————————-*
*       CLASS ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT DEFINITION
*———————————————————————-*
*
*———————————————————————-*
CLASS zcl_zproj_gr_multideep_mpc_ext DEFINITION
PUBLIC
INHERITING FROM zcl_zproj_gr_multideep_mpc
CREATE PUBLIC .

PUBLIC SECTION.

TYPES :
BEGIN OF ts_deep_entity,
id TYPE char10,
name
TYPE char30,
name2
TYPE char30,
headitemo
TYPE STANDARD TABLE OF ts_itemo WITH DEFAULT KEY,
headitemt
TYPE STANDARD TABLE OF ts_itemt WITH DEFAULT KEY,
END OF ts_deep_entity.

METHODS define
REDEFINITION .

Redefine the DEFINE method of Extended Model Provider class ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT

red-mpc.PNG


Code Snippet


METHOD define.
super
->define( ).
DATA:
lo_annotation    
TYPE REF TO /iwbep/if_mgw_odata_annotation,
lo_entity_type   
TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_complex_type  
TYPE REF TO /iwbep/if_mgw_odata_cmplx_type,
lo_property      
TYPE REF TO /iwbep/if_mgw_odata_property,
lo_entity_set    
TYPE REF TO /iwbep/if_mgw_odata_entity_set.

***********************************************************************************************************************************
*   ENTITY – Deep Entity
***********************************************************************************************************************************

lo_entity_type = model->get_entity_type( iv_entity_name = ‘Header’ ). “#EC NOTEXT

lo_entity_type->bind_structure( iv_structure_name  = ‘ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT=>TS_DEEP_ENTITY’ ). “#EC NOTEXT

ENDMETHOD.


Now we have create one custom method (CUSTOME_CREATE_DEEP_ENTITY) in class ZCL_ZPROJ_GR_MULTIDEEP_DPC_EXT



CUSTOM-MET-1.PNGCUST-2-SIGN.PNG


IV_ENTITY_NAME                         Importing            Type      STRING

IV_ENTITY_SET_NAME                 Importing            Type      STRING

IV_SOURCE_NAME                       Importing            Type      STRING

IT_KEY_TAB                                   Importing            Type      /IWBEP/T_MGW_NAME_VALUE_PAIR

IT_NAVIGATION_PATH                Importing            Type      /IWBEP/T_MGW_NAVIGATION_PATH

IO_EXPAND                                   Importing            Type Ref To        /IWBEP/IF_MGW_ODATA_EXPAND

IO_TECH_REQUEST_CONTEXT    Importing            Type Ref To        /IWBEP/IF_MGW_REQ_ENTITY_C

IO_DATA_PROVIDER                    Importing            Type Ref To        /IWBEP/IF_MGW_ENTRY_PROVIDER

ER_DEEP_ENTITY                           Exporting             Type      ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT=>TS_DEEP_ENTITY


/IWBEP/CX_MGW_BUSI_EXCEPTION

/IWBEP/CX_MGW_TECH_EXCEPTION

Code Snippet

METHOD custome_create_deep_entity.

 
DATA: lr_deep_entity TYPE zcl_zproj_gr_multideep_mpc_ext=>ts_deep_entity,
lt_itemo
TYPE zcl_zproj_gr_multideep_mpc=>tt_itemo,
lt_itemt
TYPE zcl_zproj_gr_multideep_mpc=>tt_itemt,
ls_itemo
TYPE zcl_zproj_gr_multideep_mpc=>ts_itemo,
ls_itemt
TYPE zcl_zproj_gr_multideep_mpc=>ts_itemt.

DATA : ls_general_data TYPE zstr1_header,
lt_itemo_data
TYPE STANDARD TABLE OF zstr1_itemo,
ls_itemo_data
TYPE  zstr1_itemo,
lt_itemt_data
TYPE STANDARD TABLE OF zstr1_itemt,
ls_itemt_data
TYPE  zstr1_itemt.

FIELD-SYMBOLS: <ls_itemo> TYPE zcl_zproj_gr_multideep_mpc=>ts_itemo,
<ls_itemt>
TYPE zcl_zproj_gr_multideep_mpc=>ts_itemt.
 
*  Transform data into the internal structure

io_data_provider->read_entry_data(
IMPORTING
es_data
= lr_deep_entity ).
 
**********Collect the header fields here
ls_general_data
id = lr_deep_entityid.
ls_general_data
name1 = lr_deep_entityname.
ls_general_data
name2 = lr_deep_entityname2.

********Collect  itemO fields
LOOP AT lr_deep_entityheaditemo ASSIGNING <ls_itemo>.
CLEAR  ls_itemo_data.
ls_itemo_data
id = <ls_itemo>ido.
ls_itemo_data
name = <ls_itemo>nameo.
APPEND  ls_itemo_data TO lt_itemo_data.
ENDLOOP.

*******Collect itemT fields
LOOP AT lr_deep_entityheaditemt ASSIGNING <ls_itemt>.
CLEAR  ls_itemt_data.
ls_itemt_data
id = <ls_itemt>idt.
ls_itemt_data
name = <ls_itemt>namet.
APPEND  ls_itemt_data TO lt_itemt_data.
ENDLOOP.
 
********Call RFC
 
CALL FUNCTION ‘ZDEEP_RFC’
EXPORTING
ls_header
= ls_general_data
TABLES
lt_itemo 
= lt_itemo_data
lt_itemt 
= lt_itemt_data.

er_deep_entityid = ls_general_dataid.
er_deep_entity
name = ls_general_dataname1.
 
ENDMETHOD.



Now we have to Redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY


red-createdeep.PNG


Code Snippet



METHOD /iwbep/if_mgw_appl_srv_runtime~create_deep_entity.

DATA custome_create_deep_entity TYPE zcl_zproj_gr_multideep_mpc_ext=>ts_deep_entity.

CASE iv_entity_set_name.
*————————————————————————-*
*             EntitySet –  HeaderSet
*————————————————————————-*
WHEN ‘HeaderSet’.
*       Call the entity set generated method
*      TRY.

CALL METHOD me->custome_create_deep_entity
EXPORTING
iv_entity_name         
= iv_entity_name
iv_entity_set_name     
= iv_entity_set_name
iv_source_name         
= iv_source_name
it_key_tab             
= it_key_tab
it_navigation_path     
= it_navigation_path
io_expand              
= io_expand
io_tech_request_context
= io_tech_request_context

          io_data_provider        = io_data_provider
IMPORTING
er_deep_entity         
= custome_create_deep_entity.

copy_data_to_ref(
EXPORTING
is_data
= custome_create_deep_entity
CHANGING
cr_data
= er_deep_entity
).
ENDCASE.
ENDMETHOD.


Coding Part done!!!….Let’s move to Testing



Testing


  • Select HTTP method as POST
  • Place the Request URI : /sap/opu/odata/sap/ZPROJ_GR_MULTIDEEP_SRV/HeaderSet
  • Place the External Break point at METHOD CUSTOME_CREATE_DEEP_ENTITY
  • Execute the Service (F8/Execute)


Request Payload

<?xml version=“1.0” encoding=“UTF-8”?>
<atom:entry
xmlns:atom=
http://www.w3.org/2005/Atom
xmlns:d=
http://schemas.microsoft.com/ado/2007/08/dataservices
xmlns:m=
http://schemas.microsoft.com/ado/2007/08/dataservices/metadata>
<atom:content type=
“application/xml”>
<m:properties>
<d:Id>100</d:Id>
<d:Name>Test</d:Name>
<d:Name2>Test Header2</d:Name2>
</m:properties>
</atom:content>
<atom:link
rel=
http://schemas.microsoft.com/ado/2007/08/dataservices/related/HeadItemO
type=
“application/atom+xml;type=feed”
title=
“ZPROJ_GR_MULTIDEEP_SRV.Header_ItemO”>
<m:inline>
<atom:feed>
<atom:entry>
<atom:content type=
“application/xml”>
<m:properties>
<d:IdO>10</d:IdO>
<d:NameO>Test Item11</d:NameO>
</m:properties>
</atom:content>
</atom:entry>
<atom:entry>
<atom:content type=
“application/xml”>
<m:properties>
<d:IdO>20</d:IdO>
<d:NameO>Test Item12</d:NameO>
</m:properties>
</atom:content>
</atom:entry>
</atom:feed>
</m:inline>
</atom:link>
<atom:link
rel=
http://schemas.microsoft.com/ado/2007/08/dataservices/related/HeadItemT
type=
“application/atom+xml;type=feed”
title=
“ZPROJ_GR_MULTIDEEP_SRV.Header_ItemT”>
<m:inline>
<atom:feed>
<atom:entry>
<atom:content type=
“application/xml”>
<m:properties>
<d:IdT>10</d:IdT>
<d:NameT>Test Item21</d:NameT>
</m:properties>
</atom:content>
</atom:entry>
<atom:entry>
<atom:content type=
“application/xml”
>
<m:properties>
<d:IdT>20</d:IdT>
<d:NameT>Test Item22</d:NameT>
</m:properties>
</atom:content>
</atom:entry>
</atom:feed>
</m:inline>
</atom:link>
</atom:entry>

test-1.PNGbreak-1-testing.PNG

Before executing method read_entry_data values in lr_deep_entity is initial

brk-2-bfr.PNGbrk-2-bfr2.PNG


After executing method read_entry_data values in lr_deep_entity is not initial


aft-brk-1.PNGaft--brk-2.PNG


Now RFC Will receive the three structure values


rfc1.PNG


Once come out from the debugger …record will be created in Backend.


succs.PNG



      *************************** 🙂 🙂   Your Done !!! **************************


      Appreciate your suggestions and comments.

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