Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
SyambabuAllu
Contributor

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



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

Entity Type - ItemO

Entity Type - ItemT

Entity Sets -  HeaderSet,ItemOSet,ItemTSet



Create Associations given below


Association-1 -  Header_ItemO (Without key fields mapping)

Association-2 -  Header_ItemT (Without key fields mapping)



Create Navigation given below


Navigation-1 -  HeadItemO

Navigation-2 -  HeadItemT



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.

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.

Build Types for Deep Entity

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


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




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_entity-id.
ls_general_data
-name1 = lr_deep_entity-name.
ls_general_data
-name2 = lr_deep_entity-name2.

********Collect  itemO fields
LOOP AT lr_deep_entity-headitemo 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_entity-headitemt 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_entity
-id = ls_general_data-id.
er_deep_entity
-name = ls_general_data-name1.
 
ENDMETHOD
.



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



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>

Before executing method read_entry_data values in lr_deep_entity is initial


After executing method read_entry_data values in lr_deep_entity is not initial



Now RFC Will receive the three structure values



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




      *************************** :smile: :smile:   Your Done !!! **************************


      Appreciate your suggestions and comments.

160 Comments
Labels in this area