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.

To report this post you need to login first.

149 Comments

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

      1. Ramachandran Balakrishnan

        Syam,

        Hows your landscape setup ? is your SAP backend and Gateway in separate servers ? The reason am asking is I have a simillar scenario with multiple output tables for a rfc (backend) and trying to setup Service on Gateway. The way i see here, is that you have them coexist and so were able to bind the BAPI within the Gateway classess….

        (0) 
        1. Syam Babu Post author

          Hi Ramachandra,

          Landscape shoulbe as recommnded by SAP (SAP Backend and SAP GW System(frontend server)) within the Backend system we have to develop our custom development(ex:FM/Class-method) and implement the odata development also and register the GW service in Front-End server.

          Thanks,

          Syam

          (0) 
  1. Prabaharan Asokan

    Hi Shyam,

    Can we use this for one header and 2 item tables ? For example ,One sales order header table with 2 item tables like Sales Document: Item Data(VBAP) and Sales Document: Business Data/Sales district data,VBKD (structure of both the Item tables will be different).

    Please suggest.

    Your help is appreciated.

    Regards

    Prabaharan

    (0) 
    1. Syam Babu Post author

      Hi Prabaharan,

      Yes ..You can implement. 😎

      Let’s look into Sales Order BAPI : BAPI_SALESORDER_CREATEFROMDAT2 in this we have table parameters ITEM,PARTNER,SCHEDULES,CONDITIONS etc…..

      In GW you can create one entity for Header and create all above table parameters have individual entity types with navigation and association how i did in my blog.

      Thanks,

      Syam

      (0) 
      1. Prabaharan Asokan

        Syam,

        Good one.

        Is it also possible to use “GET_EXPANDED_ENTITITY_SET” like above scenario?

        i.e. sending one structure and “N” output tables to the response.

        Regards

        Prabaharan

        (0) 
        1. Syam Babu Post author

          Prabaharan,

          I haven’t tried any development using  GET_EXPANDED_ENTITITY_SET and GET_EXPANDED_ENTITITY till now.

          But there is solution for this 🙂

          Thanks,

          Syam

          (0) 
  2. Vijay Dudla

    Hi Syam,

    I have a question on how to call this externally from a javascript/java based application, i mean how to call this request with multiple tables.

    Thanks

    Vijay

    (0) 
  3. Hao Ran Ma

    Hi Syam,


    Very helpful with this document,thanks for your sharing..

    I do it step by step,when I run that was not enter the method that CREATE_DEEP_ENTITYSET. It always reminded me that Method ‘HEADERSET_CREATE_ENTITY’ not implemented in data provider class.So, could you give me some suggestion?I ‘ll appreciate very much!

    Regards,

    Tymon

    (0) 
    1. Ashwin Dutt R

      Hello Ran,

      Have you created association and navigation between the Header and Item entities ?

      Please check your payload once again.

      Call will go to Create_Deep_Entity method based on the association and navigation properties inside your payload.

      Could you please share the payload which you are using to fire POST? and also the association and navigation details ?

      Regards,

      Ashwin

      (0) 
      1. Hao Ran Ma

        Hello Ashwin,


        Thanks for your reply.

        I have created association and navigation between the Header and Item entities.

        My request payload is

        <?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:Name1>Test</d:Name1>

        <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=”ZGW_MA_MULDEEP_SRV.Header_ItemO”>

        <m:inline>

        <atom:feed>

        <atom:entry>

        <atom:content type=”application/xml”>

        <m:properties>

        <d:Id>10</d:Id>

        <d:Name>Test Item11</d:Name>

        </m:properties>

        </atom:content>

        </atom:entry>

        <atom:entry>

        <atom:content type=”application/xml”>

        <m:properties>

        <d:Id>20</d:Id>

        <d:Name>Test Item12</d:Name>

        </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=”ZGW_MA_MULDEEP_SRV.Header_ItemT”>

        <m:inline>

        <atom:feed>

        <atom:entry>

        <atom:content type=”application/xml”>

        <m:properties>

        <d:Id>10</d:Id>

        <d:Name>Test Item21</d:Name>

        </m:properties>

        </atom:content>

        </atom:entry>

        <atom:entry>

        <atom:content type=”application/xml”>

        <m:properties>

        <d:Id>20</d:Id>

        <d:Name>Test Item22</d:Name>

        </m:properties>

        </atom:content>

        </atom:entry>

        </atom:feed>

        </m:inline>

        </atom:link>

        </atom:entry>

        Regards,

        Tymon

        (0) 
        1. Ashwin Dutt R

          Hello Ran,

          Have used the same names as used in the blog in your project for the entities, properties and association & navigation ?

          If yes then you should be able to fire Create_Deep_Entity with the payload given in the blog.

          I assume that you have used the same names and based on that i am sharing the payload to check again.

          Using the below ones ->

          1. XML payload ->

          In the Header pass the below :

          Content-Type – application/atom+xml

          <?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>

          2. JSON Payload ->

          In the Header pass the below :

          Content-Type – application/json

          {

          “Id”:”01″,

          “Name”:”John”,

          “Name2″:”Bell”,

          HeadItemO“:[{“IdO”:”10″,”NameO”:”TestO1″},

          {“IdO”:”20″,”NameO”:”TestO2″}],

          HeadItemT“:[{“IdT”:”10″,”NameT”:”TestT1″},

          {“IdT”:”20″,”NameT”:”TestT2″}]

          }

          Please try with the above and put a Break Point inside Create_Deep_Entity Method.

          Please note that the names you use while creating the deep structure inside your DPC_EXT class of Create_Deep_Entity method should be same as the navigation properties defined in your SEGW Model.

          Regards,

          Ashwin

          (0) 
          1. Hao Ran Ma

            Hello Ashwin,


            thanks for your reply.

            I used this payload and failed again.

            I think it was problem of  my operation,so I’ll try it all over again and share something why was wrong.


            Best Regards

            Tymon

            (0) 
      2. Pavan Golesar

        Hello Ashwin Dutt R,

                                    Ashwin Dutt R wrote:

        Hello Ran,

        Have you created association and navigation between the Header and Item entities ?

        Please check your payload once again.

        Call will go to Create_Deep_Entity method based on the association and navigation properties inside your payload.

        Could you please share the payload which you are using to fire POST? and also the association and navigation details ?

        Regards,

        Ashwin

        can you please share how the call will hit the ‘create deep entity’.. can we use get_expanded_entity over here to get the same functionality..???

        Please correct me if I went wrong on any line……

        Regards,

        Pavan Golesar

        (0) 
        1. Syam Babu Post author

          Hello Pavan,

          As Ashwin Said it;s correct but here while performing Create deep entity operation you have to send it with payload inline item so automatically HTTP POST method will trigger in backend CREATE_DEEP_ENTITY method.

          Thanks,

          Syam

          (0) 
      3. mohit yadav

        Hello Ashwin,

        this is my payload .. i can’t find the problem in it. please help me out.


        SPAN {
        font-family: “Courier New”;
        font-size: 10pt;
        color: #000000;
        background: #FFFFFF;
        }
        .L1S33 {
        color: #009300;
        }
        {
        “DocType” “CC”,
        “DocCat” “F”,
        “CoCode” “0001”,
        “PurchOrg” “0001”,
        “PurGroup” “001”,
        “Vendor” “INC”,
        “PoNumber” “”,
        “CreatedBy” “APUHAN”,
        “Langu” “EN”,
        “POHdrToAddData” : [
        {
        “Pmnttrms” “0001”,
        “CreatedBy” “APUHAN”,
        “Currency” “EUR”
        }
        ],
        “POHdrToItem” : [
        {
        “PoNumber” “”,
        “PoItem” “” ,
        “Material” “Milk”,
        “PurMat” “Milk”,
        “MatGrp” “01”,
        “Plant” “ZZ01”,
        “Unit” “L”,
        “NetPrice” “100”,
        “PriceUnit” “1”
        },
        {
        “PoNumber” “”,
        “PoItem” “” ,
        “Material” “Curd”,
        “PurMat” “Curd”,
        “MatGrp” “01”,
        “Plant” “ZZ01”,
        “Unit” “L”,
        “NetPrice” “100”,
        “PriceUnit” “1”
        }
        ],
        “POHdrToItemSchd” : [
        {
        “PoItem” “” ,
        “DelivDate” “2017-03-03T00:00:00”,
        “Quantity” “100”
        },
        {
        “PoItem” “” ,
        “DelivDate” “2017-03-03T00:00:00”,
        “Quantity” “100”
        }
        ],
        “POReturnNav” : [
        {
        “Type” “q”,
        “Code” “we”,
        “Message” “are”,
        “LogNo” “the”,
        “LogMsgNo” “45673454”,
        “MessageV1” “real”,
        “MessageV2” “crazy”,
        “MessageV3” “guys”,
        “MessageV4” “here”
        }
        ]
        }

        (0) 
  4. Benedick Colasito

    Hi Syam,

         This is a very helpful blog. Really appreciate this.

         I did this step by step but having a problem in posting.

         The error was ” The Data Services Request contains SystemQueryOptions that are not allowed for this Request Type”

         Please help. Badly need this to work. 🙂

         Thank you

    (0) 
    1. Syam Babu Post author

      Hi Benedick,

      While testing your service which HTTP method you selected from gw client.

      You have to select POST method.

      thanks,

      Syam

      (0) 
      1. Benedick Colasito

        Hi Syam,

             i have selected the POST radio button. below is my sample uri

             /sap/opu/odata/SAP/Y_CREATE_DEEP_SRV/HeaderSet

             same error still exists. 🙁

        warmest regards,

        Benedick.

        (0) 
    2. Premnarayan Patidar

      hi Benedick,

      while posting you should not have query parameter in the request, which is what the error message says, just remove the query parameter, you have to pass the URL till collection name with payload, it should work.

      Thanks, Prem

      (0) 
  5. Benedick Colasito

    Hi Syam and Prem,

        This is the screenshot for my Simple Create Deep Entity, and thank you a lot for the response, hope you guys can help me. Tried with only 1 value for the item. I also added an external breakpoint at the custome but to no avail.

    error.PNG

    (0) 
    1. Vijay Vegesana

      Hi Benedick,

      The error screenshot has different payload and the Payload request is different. there is no comma in the screen shot right?

      Can you recheck again?

      We used below and it was working fine earlier, Can you compare both?

      {
      “PhoneNumber” : “405-595-9130”,

      “Nav2ReqProducts”:
      [{
      “ItemNo” : “0000000010”,
      “ProductId” : “M00692”,
      “Description” : “225/70R19.5 G XST4”,
      “WheelPos” : “01”,
      “TirePos” : “06”,
      “DeleteInd” : “”
      }]}

      Regards,

      Vijay Vegesana

      (0) 
  6. Syam Babu Post author

    Hi Benedick,

    Seems your JSON request payload is not parsing properly.

    So can you send me your request payload here..so that i can help you on the same.

    Thanks,

    Syam

    (0) 
  7. Benedick Colasito

    Hi Syam,

    Below is my json payload.

    {

    “PreqNo”:“0”,

    “HeadItems”:[

                 {“PreqNo”:“0”,

                  “PreqItem”:“10”,

                  “DocumentType”:“PR”,

                  “Material”:“YP21300002”,

                  “Plant”:“100”,

                  “Quantity”:“1.000”,

                  “DeliveryDate”:“02-25-2015”

                 }

                 ]

    }

    (0) 
  8. Varun Meka

    Hello Syam

    I have a requirement ,having a z fm(zservice) in ecc ,in zservice ,i am doing goods movement creation(using bapi) and also BAPI_PO_change for updating details in ekko and ekpo tables.

    zservice  fm having  import parameters like matnr,site etc and exporting as a structure et_return – in that msg type and message are there.

    can you pls tell me how to proceed on this.

    Thanks

    Vamsi

    (0) 
  9. IBM Lab for SAP Solutions

    Hi Syam,

    will you please help me,by letting me know “where I am going wrong?”

    I had followed your steps to get the data .I was successful to get only HEADER data.

    After executing method read_entry_data values in lr_deep_entity is  not initial but only the

    Header level fields are filled the ITEM level fields are not getting filled?


    Please help me on this,I was  trying this forthe past 3 days(recreating the service/structures..methods…) but in vain 🙁

    Thanks in advance

    Kelly

    (0) 
    1. Ashwin Dutt R

      Hello Kelly,

      That is because the names used for Item structures in defining the Deep Entity Structure in is not same as the names defined as the Navigation Properties in your GW model.

      Observe the below carefully ( Highlighted in Bold ) ->

      Navigation property Names in the GW model are :

      HeadItemO

      HeadItemT

      The Names used in the below to define Item structures should be same as the navigation property names.

      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.


      Maintain as above and this will resolve the issue.


      Regards,

      Ashwin

      (0) 
      1. Dave Price

        Thanks, I ran into this same problem — oddly, I was already using the Navigation name, so I debugged:

        io_data_provider->read_entry_data(

             IMPORTING

             es_data = ls_CPQW_DCR_DEEP_ENTITY )


        which calls method

                 /iwbep/cl_mgw_data_conv_util=>convert_entity_inbound(

                   exporting

                     io_expand_node      = mo_entity_descriptor

                     is_source_structure = <ls_source_structure>

                   changing

                     cs_target_structure = es_data ).

        which does this:


        *———————————————————————————-

        * 3. process subnodes (dependent entities)

        *———————————————————————————-

           io_expand_node->get_children( IMPORTING et_children = lt_children ).

           LOOP AT lt_children INTO ls_child.

             lv_abap_name = ls_childnode->/iwbep/if_mgw_tech_expand_node~get_nav_prop_name( ).

             ASSIGN COMPONENT lv_abap_name OF STRUCTURE is_source_structure TO <lv_source_comp>.

             IF sysubrc <> 0. CONTINUE. ENDIF.

             ASSIGN COMPONENT lv_abap_name OF STRUCTURE cs_target_structure TO <lv_target_comp>.

             IF sysubrc <> 0. CONTINUE. ENDIF.

             CASE ls_childnode->get_multiplicity( ).

        ——-

        the lv_abap_name it used was not the navigation name… it was the navigation ABAP name.  Hahaha.


        Thought I would share this in case anyone runs into a similar issue — you can either just look at the ABAP name in the Navigation properties, or debug looking at the above.

        (0) 
  10. Felix zhao

    Very nice and helpful!  Really appreciate this.

    and I have a question:

    Is it necessary to Redefine the DEFINE method of Extended Model Provider class ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT,

    what is the use?

    cause I comment out these code line,and it works fine too.

    thank you.

    (0) 
  11. Karthik Sridhar

    Hi Syam,

    Thank You for the very helpful blog,

    You have written as

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

    Where is the data getting stored in the backend???

    I don find any data trigerred in RFC.

    Please Help me with this…


    Thank You.

    (0) 
    1. Syam Babu Post author

      Hi Karthik,

      It means like while you’re using create Bapi it will create corresponding record in the table like SO/PO/WO etc…

      Thanks,

      Syam

      (0) 
      1. Karthik Sridhar

        Hi Syam,

        So the data uploaded from the payload referring this blog will not be stored anywhere in the backend?

        Header/itemo/itemt details from the payload are not saved?

        Thank You.

        (0) 
        1. Ekansh Saxena

          Hi Karthik,

          What happens to your payload data depends on your backend business logic. We have already discussed it earlier in your thread. Mostly the data you are passing to the backend is stored in DB tables. For example: if it is a PO, it would be stored in EKKO(for header) and EKPO(for items) tables. So it clearly depends on your use case, what is that entity that you are creating. It would definetly stored in some tables.

          Regards,
          Ekansh

          (0) 
  12. Sagar Goyal

    Hi Syam,

    Really Amazing content, helped me at lot.

    I am stuck at one place

    Everything seems to be working fine except    

    io_data_provider->read_entry_data(

         importing

         es_data = lr_deep_entity).

    I am getting a blank table here.
    please help me out

    Regards

    Sagar

    (0) 
    1. Andre Fischer

      Hi Sagar,

      are you sure that your request has the correct structure so that it is reckognized as a deep insert request by the Gateway framework?

      Please check Q14 in the FAQ:  Gateway Client document how to create such a request.

      Best Regards,

      Andre

      (0) 
      1. Sagar Goyal

        Hi,

        I have used the structure similar to that of the structure shown in the above tutorial,

        and in case of request payload, I have not created GET ENTITY or GET ENTITYSET, hence that option too cannot be implemented

        Regards

        Sagar

        (0) 
        1. Andre Fischer

          Hi Sagar,

          to be honest I would expect it as a prerequisite to implement GET_ENTITYSET and GET_ENTITY for each entity set that is part of a deep insert scenario.

          I know that it is not mandatory but also a service that offers a simple update without implementing read and query does not make sense in my point of view.

          Best Regards,

          Andre

          (0) 
    2. Ashwin Dutt R

      Hello Sagar,

      Check the below things :

      Names used for Item structures in defining the Deep Entity Structure needs to be same as the names defined as the Navigation Properties in your GW model.

      Observe the below carefully ( Highlighted in Bold ) ->

      Navigation property Names in the GW model are :

      HeadItemO

      HeadItemT

      The Names used in the below to define Item structures should be same as the navigation property names.

      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.


      Payload should also have the same names.


      Check again.


      Regards,

      Ashwin

      (0) 
        1. Sagar Goyal

          Hi Andrew,

          I am sending the data in 2 chunks to the UI and retrieving them as one Unit.

          I am trying to fetch form details from the UI, wherein there are multiple variables and one table.

          So, I have separate Service for that part

          Regards

          Sagar

          (0) 
            1. Sagar Goyal

              Inside the method, Read Entitty Data, there is a piece of code

              Call transformation id

              source xml my_raw_data

              result entity = es_data\

              I can see my input in my_raw_data

              but es_data is blank

              (0) 
              1. Sagar Goyal

                Hi Ashwin,

                I could find 3 places in the code where ITPOSTABLESET is to be written, and I have used them in all three places

                Regards

                Sagar

                (0) 
                1. Martin Reichenecker

                  Hi Sagar,

                  make sure that the “binding conversion” is set, when binding the structure to the entity in the redefintion of method  ZCL_<CLASS_NAME>_MPC_EXT->DEFINE.

                  Unbenannt.PNG

                  Additionally the name of the ABAP-field, which contains the child-elements later on in the head-structure  have to be the same as the name of the navigation name.

                  Unbenannt2.PNG

                  Kind regards,

                  Martin

                  (0) 
  13. Pavan Golesar

    Syam,

       

          Awesome work. ℹ ..!!

                   well Explained and Yes, I am prompt to say cool documentation 😎 ..

    Regards,

    Pavan Golesar

    (0) 
  14. Felix zhao

    Hi Syam,

    Very nice and helpful!  Really appreciate this.

    and I have a question:

    Is it necessary to Redefine the DEFINE method of Extended Model Provider class ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT,

    what is the use?

    Regards,

    felix.

    (0) 
  15. Nitesh Jain

    Hi Syam/Ashwin,

    Thanks for the blog.

    I am using the concepts to develop an OData service to post a Goods Receipt document with multiple items. However i am getting an error.

    Error details as in the Error log:

    <?xml version=”1.0″ encoding=”utf-8″ ?>

    <ERROR_CONTEXT>

    <ERROR_INFO>Deserialization of XML failed via transformation ‘ID’</ERROR_INFO>

    <_-IWFND_-CX_MGW_TECH_EXCEPTION>

    <RFC_FAILURE_MESSAGE />

    <TRANSFORMATION>ID</TRANSFORMATION>

    <ENTITY_NAME />

    <REMOTE_MESSAGE />

    <REMOTE_SYSTEM />

    <REMOTE_MESSAGE_TYPE />

    <SERVICE_IDENTIFIER />

    <METHOD />

    <FIELD_NAME />

    <FIELD_VALUE />

    <NAVIGATION_PROPERTY />

    </_-IWFND_-CX_MGW_TECH_EXCEPTION>

    <CX_XSLT_RUNTIME_ERROR>

    <S1 />

    <S2>unexpected end-of-file</S2>

    <I1>3000</I1>

    <I2>2</I2>

    <I3>1</I3>

    </CX_XSLT_RUNTIME_ERROR>

    <SERVICE_INFO>

    <NAMESPACE>/SAP/</NAMESPACE>

    <VERSION>0001</VERSION>

    <SERVICE_NAME>YNJGRMI</SERVICE_NAME>

    <REQUEST_DIRECTION>Consumer to Gateway</REQUEST_DIRECTION>

    <REQUEST_OPERATION>create</REQUEST_OPERATION>

    <AGENT>OData Channel Remote Connectiv</AGENT>

    <SYSTEM_ALIAS>LOCAL</SYSTEM_ALIAS>

    <DESTINATION>DCRCLNT785</DESTINATION>

    </SERVICE_INFO>

    …..

    </ERROR_CONTEXT>

    Service Details:

    Entity 1 – GRHeader

    GRHeader Entity.png

    Entity 2 – GRItem

    GRItem Entity.png

    Entity Sets – GRHeaders, GRItems

    Entity Sets.png

    Association – GRASS

    Association.png

    Key field mapping not done.


    Navigation

    Navigation.png

    Deep Entity declaration

    Deep Entity declaration.png

    Name used for Item structure in defining the Deep Entity Structure is the same as the name defined as the Navigation Properties in the GW model.


    Registered Service – YNJGRMI

    Registered Service.png

    URL used in Gateway client is with the Entity set GRHeaders

    /sap/opu/odata/sap/YNJGRMI/GRHeaders


    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:IDHdr>1</d:IDHdr>

    <d:PostingDate>2015-08-11T00:00:00</d:PostingDate>

    <d:EGrDoc></d:EGrDoc>

    <d:EGrDocYear></d:EGrDocYear>

    </m:properties>

    </atom:content>

    <atom:link

    rel=”http://schemas.microsoft.com/ado/2007/08/dataservices/related/GRNAV

    type=”application/atom+xml;type=feed”

    title=”YNJGRMI.GRASS”>

    <m:inline>

    <atom:feed>

    <atom:entry>

    <atom:content type=”application/xml”>

    <m:properties>

    <d:Purchaseorder>4510001233</d:Purchaseorder>

    <d:PoItem>00001</d:PoItem>

    <d:Quantity>1.000</d:Quantity>

    </m:properties>

    </atom:content>

    </atom:entry>

    <atom:entry>

    <atom:content type=”application/xml”>

    <m:properties>

    <d:Purchaseorder>4510001233</d:Purchaseorder>

    <d:PoItem>00002</d:PoItem>

    <d:Quantity>2.000</d:Quantity>

    </m:properties>

    </atom:content>

    </atom:entry>

    </atom:feed>

    </m:inline>

    </atom:link>

    </atom:entry>

    Call Stack as in Error log

    The CREATE_ENTITY method is being called and not CREATE_DEEP_ENTITY.

    Call Stack - Error.png

    Would be great if you’ll could help me resolve this issue.

    Thanks & Regards

    Nitesh

    (0) 
    1. Ashwin Dutt R

      Hello Nitesh,

      Hope each and every single step specified by Syam is followed by you while implementing this.

      Based on this,

      I would suggest to check the below things and try firing again.

      1. Mark Date field as ‘Nullable’ in SEGW ( Check Box to be Checked ), regenerate Run-Time objects and clear model cache in GW Hub via t-code /iwfnd/cache_cleanup.

      2. Inside Create_Deep_Entity method, in the deep entity declaration part, for Header Fields, use the names same as the one used in the SEGW used while defining the properties.

      In your case ABAP Fields in SEGW are different ( highlighted sections ) from the names used in deep structure declaration.

      Use correct data types. In deep declaration its string but in SEGW its string with restricted length.

      Goods_Receipt.png

      Deep+Entity+declaration.png

      Declare as below ->

      types:

      begin of ts_deep_entity,

      idhdr type char3,

      postingdate type dats,

      egrdoc type char10,

      egrdocyear type char4,

      grnav type standard table of ts_gritem with default key,

      end of ts_deep_entity.

      3. Use the below JSON payload.

      Add Header : Content-Type – application/json

      {

      “IDHdr”:”1″,

      “PostingDate”:”2015-08-11T00:00:00″,

      “EGrDoc”:””,

      “EGrDocYear”:””,

      “GRNAV”:[{“Purchaseorder”:”4510001233″,”PoItem”:”00001″,”Quantity”:”1.000″},{“Purchaseorder”:”4510001233″,”PoItem”:”00002″,”Quantity”:”2.000″}]

      }

      Please Check again firing the service and revert.

      Regards,

      Ashwin

      (0) 
      1. Nitesh Jain

        Hi Ashwin,

        Thanks for the prompt reply.

        Yes i have followed every step.

        I have changed the date field to nullable in the GRHeader entity.

        GRHeader Entityv1.png

        I have changed the deep entity declaration as you suggested. The TS_GRITEM structure used in the deep entity, was automatically generated for the GrItem entity had also declared the “RESTRICTED STRING” in entity as STRING in the Base MPC declaration . Therefore i created a new structure TS_NEW_GRITEM inline with the your suggestion and am now using it in the deep entity.

        Deep Entity declarationv1.png

        Then i regenerated the project, cleared the cache and fired the service with the JSON feed but the result was the same. Still getting the error.

        Error details:

        Error.png

        Let me know if you need any more info.

        Thanks & Regards

        Nitesh

        (0) 
            1. Ashwin Dutt R

              Ok Nitesh.


              can you undo-redefinition of Create_Entity method and check again ?

              Also can you change cardinality between Header and Item to 1 to N, re-generate objects, clear model cache and check again ?

              (0) 
              1. Nitesh Jain

                Hi Ashwin,

                I have redefined the Create_deep_entity method and not the create_entity method. The call stack suggests the call is not being directed to the create_deep_entity method.

                Changed the cardinality to 1 to N and retested but same error result.

                regards

                Nitesh

                (0) 
                1. Ashwin Dutt R

                  Hello Nitesh,

                  Everything looks fine but not sure why its not hitting Deep_Entity method.

                  Ok can u try this payload once and see ?

                  {

                  “IDHdr”:”1″,

                  “PostingDate”:null,

                  “EGrDoc”:””,

                  “EGrDocYear”:””,

                  “GRNAV”:[{“Purchaseorder”:”4510001233″,”PoItem”:”00001″,”Quantity”:”1.000″},{“Purchaseorder”:”4510001233″,”PoItem”:”00002″,”Quantity”:”2.000″}]

                  }

                  Regards,

                  Ashwin

                  (0) 
                      1. Nitesh Jain

                        Hi Ashwin,

                        The CREATE_DEEP_ENTITY method is not getting called as suggested by the call stack so not sure if the code below would help.

                        Code in CREATE_DEEP_ENTITY

                        DATA custom_create_deep_entity TYPE YCL_YNJ_MULTIITEM_GR_MPC=>ts_deep_entity.

                           CASE iv_entity_set_name.

                        *————————————————————————-*

                        *             EntitySet –  HeaderSet

                        *————————————————————————-*

                             when ‘GRHeader’.

                               CALL METHOD me->custom_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          = custom_create_deep_entity.

                               copy_data_to_ref(

                               EXPORTING

                               is_data = custom_create_deep_entity

                               CHANGING

                               cr_data = er_deep_entity

                               ).

                           ENDCASE.


                        Code in custom method (CUSTOM_CREATE_DEEP_ENTITY)

                        DATA: lr_deep_entity TYPE YCL_YNJ_MULTIITEM_GR_MPC=>TS_DEEP_ENTITY,

                                 lt_gritem TYPE YCL_YNJ_MULTIITEM_GR_MPC=>tt_gritem,

                                 ls_gritem TYPE YCL_YNJ_MULTIITEM_GR_MPC=>ts_gritem.

                        ** Data declaration for RFC to be added

                           FIELD-SYMBOLS: <ls_gritem> TYPE YCL_YNJ_MULTIITEM_GR_MPC=>ts_new_gritem.

                           DATA lv_rfc_name TYPE tfdirfuncname.

                           DATA lv_destination TYPE rfcdest.

                           DATA lv_subrc TYPE systsubrc.

                           DATA lv_exc_msg TYPE /iwbep/mgw_bop_rfc_excep_text.

                           DATA e_gr_doc TYPE YCL_YNJ_MULTIITEM_GR_MPC=>mblnr.

                           DATA e_gr_doc_year TYPE YCL_YNJ_MULTIITEM_GR_MPC=>mjahr.

                           DATA e_return TYPE YCL_YNJ_MULTIITEM_GR_MPC=>bapiret2.

                           DATA lt_rfc_gritem type standard table of YCL_YNJ_MULTIITEM_GR_MPC=>ts_rfc_gritem.

                           DATA ls_rfc_gritem type YCL_YNJ_MULTIITEM_GR_MPC=>ts_rfc_gritem.

                        *  Transform data into the internal structure

                           io_data_provider->read_entry_data( IMPORTING

                                                                es_data = lr_deep_entity ).

                        * Collect item details

                           loop at lr_deep_entitygrnav into <ls_gritem>.

                             clear ls_rfc_gritem.

                             ls_rfc_gritempurchaseorder = <ls_gritem>purchaseorder.

                             ls_rfc_gritempo_item = <ls_gritem>poitem.

                             ls_rfc_gritemquantity = <ls_gritem>quantity.

                             append ls_rfc_gritem to lt_rfc_gritem.

                           endloop.

                        *————————————————————-

                        *  Call RFC function module

                        *————————————————————-

                           lv_rfc_name = ‘Y_TD_POST_MULTI_ITEM_GR’.

                           lv_destination = ‘PD8CLNT285’.

                           CALL FUNCTION lv_rfc_name DESTINATION lv_destination

                             EXPORTING

                               i_posting_date        = lr_deep_entitypostingdate

                             IMPORTING

                               e_return              = e_return

                               e_gr_doc_year         = e_gr_doc_year

                               e_gr_doc              = e_gr_doc

                             TABLES

                               gr_doc_items          = lt_rfc_gritem

                             EXCEPTIONS

                               system_failure        = 1000  MESSAGE lv_exc_msg

                               communication_failure = 1001  MESSAGE lv_exc_msg

                               OTHERS                = 1002.

                           lv_subrc = sysubrc.

                           if sysubrc = 0.

                             er_deep_entityidhdr = ‘1’.

                             er_deep_entityEGRDOC = e_gr_doc.

                             er_deep_entityEGRDOCYEAR = e_gr_doc_year.

                           endif.


                        regards

                        Nitesh

                        (0) 
                        1. Nitesh Jain

                          Hi Ashwin,

                          Any luck in trying to figure out the issue.

                          I am not clear how the CREATE_DEEP_ENTITY method will be triggered by the POST.

                          regards

                          Nitesh

                          (0) 
                          1. Ashwin Dutt R

                            Hello Nitesh,

                            Everything looks fine but i am not sure why its not firing Deep Entity.

                            Can you try creating a new project altogether ?

                            There is no referential constraints defined between entities right ?

                            Regards,

                            Ashwin

                            (0) 
                            1. Nitesh Jain

                              Hi Ashwin,

                              Can you send me the call stack of a service calling the CREATE_DEEP_ENTITY method successfully using the above method?

                              regards

                              Nitesh

                              (0) 
                              1. Nitesh Jain

                                Hi Ashwin,

                                My issue got resolved after i made the Entity sets addressable.

                                Could successfully post the multi-item GRs.

                                Thanks for your help.

                                Is there a tool in Gateway to convert the OData REQUEST payload to a JSON request payload??

                                regards

                                Nitesh

                                (0) 
                                1. Andre Fischer

                                  Hi Nitesh,

                                  if you add $format=json to your request URI (e.g. …/myservice/myentityset?$format=json you will receive a JSON response.

                                  Using the SAP Gateway client you can use the “use as request” button to create a http request out of an http response.

                                  Best Regards,

                                  Andre

                                  (0) 
                                  1. Nitesh Jain

                                    Hi Andre,

                                    Thanks for the reply. My query was from the request perspective.

                                    If an external application wants to send a JSON Request to consume the Gateway service then what will be the content of the JSON request in the deep entity scenario?

                                    I need to give the external application developer the content of the JSON request to consume the Gateway service. I have the SAP OData request payload but unable to figure out how i convert that to a JSON Request payload which i can give to the external application developer.

                                    regards

                                    Nitesh

                                    (0) 
                                    1. janu m

                                      Hi Nitesh,

                                      it should be like

                                      {

                                           “d”:  {

                                               header entity properties,

                                      “Item”:[

                                      {

                                      item -1 entity details

                                      },

                                      {

                                      item – 2 entity details

                                      }

                                      ]

                                      }

                                               }

                                      (0) 
                                      1. Nitesh Jain

                                        Hi Janu,

                                        Was looking for a tool on the SAP Gateway to do this to eliminate errors in manual construction of JSON request payload.

                                        Anyways if u want to give it a shot.. What would be the JSON request payload for the following OData request payload? How to include the Navigations & Associations?

                                        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:IDHdr>1</d:IDHdr>

                                        <d:PostingDate>2015-08-11T00:00:00</d:PostingDate>

                                        <d:EGrDoc></d:EGrDoc>

                                        <d:EGrDocYear></d:EGrDocYear>

                                        </m:properties>

                                        </atom:content>

                                        <atom:link

                                        rel=”http://schemas.microsoft.com/ado/2007/08/dataservices/related/GRNAV

                                        type=”application/atom+xml;type=feed”

                                        title=”YNJGRMI.GRASS”>

                                        <m:inline>

                                        <atom:feed>

                                        <atom:entry>

                                        <atom:content type=”application/xml”>

                                        <m:properties>

                                        <d:Purchaseorder>4510001233</d:Purchaseorder>

                                        <d:PoItem>00001</d:PoItem>

                                        <d:Quantity>1.000</d:Quantity>

                                        </m:properties>

                                        </atom:content>

                                        </atom:entry>

                                        <atom:entry>

                                        <atom:content type=”application/xml”>

                                        <m:properties>

                                        <d:Purchaseorder>4510001233</d:Purchaseorder>

                                        <d:PoItem>00002</d:PoItem>

                                        <d:Quantity>2.000</d:Quantity>

                                        </m:properties>

                                        </atom:content>

                                        </atom:entry>

                                        </atom:feed>

                                        </m:inline>

                                        </atom:link>

                                        </atom:entry>

                                        regards

                                        Nitesh

                                        (0) 
                                        1. Ashwin Dutt R

                                          Hello Nitesh,

                                          We do not have any tool as such which will create request payload apart from using GW Client response as request.

                                          We can use GW response itself as request as Andre already suggested.

                                          You can also create your XMl and JSON manually as well.

                                          JSON for your XML Payload ->

                                          {

                                          “IDHdr”:”1″,

                                          “PostingDate”:”2015-08-11T00:00:00″,

                                          “EGrDoc”:””,

                                          “EGrDocYear”:””,

                                          “GRNAV”:[{“Purchaseorder”:”4510001233″,”PoItem”:”00001″,”Quantity”:”1.000″},

                                            {“Purchaseorder”:”4510001233″,”PoItem”:”00002″,”Quantity”:”2.000″}]

                                          }

                                          Regards,

                                          Ashwin

                                          (0) 
                                          1. Nitesh Jain

                                            Hi Ashwin,

                                            Do you have any sample code in Javascript to call an Gateway service and passing the deep entity data in JSON format?

                                            regards

                                            Nitesh

                                            (0) 
                                            1. mahendran N

                                              Hi.,

                                              u can try as below,

                                              data = {“IDHdr”:”1″,

                                              “PostingDate”:”2015-08-11T00:00:00″,

                                              “EGrDoc”:””,

                                              “EGrDocYear”:””,

                                              “GRNAV”:[{“Purchaseorder”:”4510001233″,”PoItem”:”00001″,”Quantity”:”1.000″},

                                                {“Purchaseorder”:”4510001233″,”PoItem”:”00002″,”Quantity”:”2.000″}]

                                              };

                                              oModel.create(‘/Trip_DataSet’, data, null,

                                                         function(response){

                                              });

                                              -Mahi

                                              (0) 
                                              1. Nitesh Jain

                                                Hi Mahi,

                                                Would need the following:

                                                1. Where/How do we give the service URL?

                                                2. Where/How do we give the logon credentials?

                                                3. Where/How do we give the Method: i.e. READ, POST, PUT, DELETE

                                                4. How do we pass the service URL, Logon credentials, Method & JSON payload together and call execute the OData service?

                                                regards

                                                Nitesh

                                                (0) 
                                                1. janu m

                                                  Hi Nitesh,

                                                  It should be something like this.

                                                  {

                                                       “d”:  {

                                                  “IDHdr”:”1″,

                                                  “PostingDate”:”2015-08-11T00:00:00″,

                                                  “EGrDoc”:””,

                                                  “EGrDocYear”:””,

                                                  it should be navigation property name —>”GRNAV”:[

                                                  {“Purchaseorder”:”4510001233″,”PoItem”:”00001″,”Quantity”:”1.000″},

                                                    {“Purchaseorder”:”4510001233″,”PoItem”:”00002″,”Quantity”:”2.000″}

                                                  ]

                                                  }

                                                  }

                                                  Regards

                                                  Janu m

                                                  (0) 
                                                2. Dave Price

                                                  1&2: you can do it this way:

                                                  http://user:pass@server.com:port/sap/opu/odata/SAP/service_SRV/method

                                                  3&4 depend on whether you’re using Gateway client (button) or browser add-on (POSTMAN or something like that) to do the POST

                                                  It is difficult but not impossible to build your JSON manually in the client or Notepad, but you might find it a lot easier in POSTMAN or some other browser add-on that handles POSTs.  These will typically also handle a CSRF token.

                                                  (0) 
                                                  1. Nitesh Jain

                                                    Dave,

                                                    In the real scenario the service will be consumed by an Android device and the CSRF token will need to be generated from the SAP system & passed with the POST request.

                                                    How to generate the CSRF token for the Deep entity scenario is something i am trying to figure out which we can pass with the POST request payload. FYI, using the chrome REST client for testing.

                                                    (0) 
                                  2. Nitesh Jain

                                    Hi Andre/Ashwin,

                                    Can we send ?$format=json with a POST method request payload?

                                    Getting the error ‘The Data Services Request contains SystemQueryOptions that are not allowed for this Request Type’.

                                    regards

                                    Nitesh

                                    (0) 
                                    1. Ashwin Dutt R

                                      Hi Nitesh,

                                      ?$format=json will be written in URL for GET Operations to get the response in JSON.


                                      We need to add a Header ‘Content-Type’ and value as ‘application/json’ when we send JSON payload.

                                      We need to add a Header ‘Accept’ and value as ‘application/json’ to get the response in JSON


                                      Regards,

                                      Ashwin

                                      (0) 
  16. janu m

    Hi,

    When I was trying the same I am getting error for Json object,

    {

    “Test” : “123”,

    “Items” : ->enittyset for items

    [{

    “Item” : “0010”

    }

    ]

    error is property Items is invalid. could you please helpme on this. I tried even through manually also in that I was getting data to Item level but header values are empty even though I am -passing data.

    Please helpme on this

    (0) 
    1. Syam Babu Post author

      Hi Janu,

      {

      “Test” : “123”,

      “Items” : ->enittyset for items

      [{

      “Item” : “0010”

      }

      ]

      error is property Items is invalid.

      Items is navigation property name or not?

      (0) 
      1. janu m

        Hi,

        It is the name of Entityset of Item, Not navigation prorperty name.when I am trying with navigation property of header, I am able to trigger breakpoint of deep entity but empty results are coming from read_entry_data method.

        (0) 
        1. Syam Babu Post author

          Ok..

           

          Please verify your deep structure are you mentioned internal
          table should be navigation property name or not.

          Thanks,

          Syam

          (0) 
          1. janu m

            Correct me.. I should create deep entity structure with navigation property name..is that right..if yes I tried..but not getting data from payload. 🙁

            (0) 
              1. janu m

                this is my deep entity structure in dpc extension class, now I am able to see data of item not of header.

                types:ts_data type standard table of zcl_test_association_mpc_ext=>ts_item.

                types:begin of ts_data,

                           include type zcl_test_association_mpc_ext=>ts_header.

                types:items type ts_item,

                     end of ts_data.

                (0) 
  17. Dave Price

    very helpful, thanks for sharing.

    At first I was confused because SEGW doesn’t generate CREATE_DEEP_ENTITY, but then I realized I’d missed the last step where we create that — apparently SAP provides but doesn’t implement that class.

    This example doesn’t do so, but you can get table output by just adding lines to the tables in the deep_entity object at the end of the custom method.  I actually eliminated almost all that custom method code and just let my RFC populate the custom type structure directly and vice-versa.

    Did anyone else run into the problem that Generate Objects removes their custom type from MPC_EXT?  I thought redefining the DEFINE method was going to fix that but apparently not.  I was able to fix this by just defining a Z structure in ECC and using that instead of pointing to the type in MPC_EXT, that seems to work fine.

    (0) 
  18. mahendran N

    Hi,

         Very helpful and thank you…

    I am facing one issue, 

    In my case, I didn’t create ‘custome_create_deep_entity‘  method instead of this i written my functionality inside the /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY method itself.

    Now my functionality is getting executed successfully, but same time am getting exception from CREATE_ENTITY_TYPE method.

    am getting below error response only. Anyone pls help me on the same.

    Error Info:

    2016-01-27 21:55:32.699485 The following problem occurred: HTTP request failed500,Internal Server Error,{“error”:{“code”:”/IWBEP/CM_MGW_RT/029″,”message”:{“lang”:”en”,”value”:”Transformation error on serialization.”},”innererror”:{“transactionid”:”9012C5E55F89F1DDBC5B000C29B0189C”,”timestamp”:”20160127162530.8840000″,”Error_Resolution”:{“SAP_Transaction”:”Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details”,”SAP_Note”:”See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)”},”errordetails”:[{“code”:”CX_XSLT_FORMAT_ERROR”,”message”:”Unexpected text for XML-ABAP transformation”,”propertyref”:””,”severity”:”error”,”target”:””},{“code”:”CX_ST_DESERIALIZATION_ERROR”,”message”:”An error occurred when deserializing in the simple transformation program /IWBEP/ST_ANY_DATA”,”propertyref”:””,”severity”:”error”,”target”:””},{“code”:”CX_SY_NO_HANDLER”,”message”:”An exception with the type CX_ST_DESERIALIZATION_ERROR occurred, but was neither handled locally, nor declared in a RAISING clause”,”propertyref”:””,”severity”:”error”,”target”:””},{“code”:”/IWBEP/CX_MGW_TECH_EXCEPTION”,”message”:”Transformation error on serialization”,”propertyref”:””,”severity”:”error”,”target”:””}]}}}

    -Mahi

    (0) 
    1. SUPRIO CHATTERJEE

      Hi Mahi,

      This seems to be problem with input XML data format.

      Please use Get method to fetch the data in the same format you use as an input.

      Do use as Request

      Change the values of the properties in XML structure.

      Execute  POST operation.

      Hopefully this will work.

      (0) 
      1. mahendran N

        Hi,

        Thanks for the reply, I found the issue and fixed. Issue was,

        custom_deep_entity type was mismatching with actual Entity type bcz of that Create_Entity_type method raised a exception.


        (0) 
  19. Vipin Kanchan

    Hi Syam Babu,

    Thanks for the detailed blog.

    We have followed the same steps to create a model which has 3 entity sets, one for Header, one for Item and one for item conditions.

    Our requirement is actually for a GET process which will take the Header and item data to simulate an order creation and return the Header, item data and condition data for the pricing.

    We have coded the Data provider extension class for the Method Create_Deep_entity so that it will take the Header and item data and do an order simulate and then get back the condition data as the response. (Our understanding is that to do a get call which required filtering in the form of tables we need to use a POST call since the Get call does not support the Body portion of the call and it is difficult to pass arrays in the header url itself).

    We are able to execute the call and pass the data from the 2 entity sets to the call. We are also getting the response for those 2 entity sets but for the 3rd entity set, we see the response from the BAPI in the data provider class and also at the end of the Create_DEEP_ENTITY. But when the response is populated in the Gateway client, we do not see the 3rd entity set but see only the data for the 2 entity sets that were passed in.

    Have you seen this type of issue and can you guide us on how to resolve this.

    Regards,

    VK

    (0) 
    1. Ashwin Dutt R

      Hello Vipin,

      You need to maintain the Navigation Property defined for the Pricing Data in the request payload along with Header & Items details so that response of GW will have Pricing Data.

      Sample JSON payload ->

      {

      “HeaderId”:”01″,

      “Item”:[{“IdO”:”10″,”NameO”:”TestO1″},

      {“IdO”:”20″,”NameO”:”TestO2″}],

      Pricing“:[{}]

      }

      Where Item and Pricing would be your Navigation Properties defined in your GW model.

      Regards,

      Ashwin

      (0) 
  20. Nitesh Jain

    Hi Andre/Ashwin,

    For external calls how do we generate the x-csrf-token for calling the POST method in this scenario?

    regards

    Nitesh

    (0) 
        1. Nitesh Jain

          Andre,

          For the normal scenario i have generated the x-csrf-token from the read operation.

          In the deep entity scenario trying to figure out how to implement the read operation to generate the x-csrf-token.. I implemented a dummy read operation on my header entity set of the deep entity scenario but it is not generating the x-csrf-token..

          Any ideas?

          regards

          Nitesh

          (0) 
          1. Nitesh Jain

            For some reason the x-csrf-token was not getting generated earlier now it is getting generated. Just implemented a simple entity read method for the Header entity set in the deep entity.

            From the service side hopefully all is done. However can confirm only after the challenge of consumption on the Javascript side is successfully done which seems to be a bit of a struggle at the moment.

            (0) 
  21. ADITI BHARGAVA

    hey,

    I’m trying to follow the steps given above such that

    Source Entity: Employee

    Associations: EmployeeToCompany , EmployeeToEducation.

    I’m getting this error:

    RFC Error: Function module “ZDEEP_RFC” not found.

    How should I resolve it?

    (0) 
  22. Ashish Gupta

    Nice blog,

    but why to create one additional method to create deep entity when we can do the whole work in the standard method provided in DPC_EXT and we can also declare the ts_deep_entity structure in standard method which is used at run time .

    (0) 
    1. Dave Price

      because CREATE_DEEP_ENTITY is generic to all “create deep entity” methods you might create in the project (as opposed to the specific entity you’re working with) —  you can code within the entity CASE statement rather than create a new method if you want, but when SAP generates the method calls from SEGW they create a new method, so it’s a bit more standard that way

      TS_DEEP_ENTITY is a data model, so it makes sense to put it in the data model class, but again I think that’s more for standardization than anything else

      (0) 
  23. Nitesh Jain

    Hi Andre/Ashwin,

    Using the CREATE_DEEP_ENTITY which calls an RFC for processing in the SAP ECC backend. The processing goes into error & returns an error message in the return parameter of the RFC. The exact error returned is getting logged in the Gateway Error log (can be seen using transaction /IWFND/ERROR_LOG) however it is not being returned in the Response. The response is returning a generic error “In the context of Data Services an unknown internal server error occurred”.

    My requirement is that the exact error message from the SAP ECC backend should be returned in the response load which can be then be used to be displayed display on the PDA device.

    Current error handling code being used

    *————————————————————-
    * Error and exception handling
    *————————————————————-
    IF lv_subrc <> 0.
    * Execute the RFC exception handling process
    me
    ->/iwbep/if_sb_dpc_comm_services~rfc_exception_handling(
    EXPORTING
    iv_subrc           
    = lv_subrc
    iv_exp_message_text
    = lv_exc_msg ).
    ENDIF.

    IF e_return IS NOT INITIAL.
    * Call RFC call exception handling
    me
    ->/iwbep/if_sb_dpc_comm_services~rfc_save_log(
    EXPORTING
    is_return     
    = e_return
    iv_entity_type
    = iv_entity_name
    it_key_tab    
    = it_key_tab ).
    ENDIF.

    * Call RFC commit work
    me
    ->/iwbep/if_sb_dpc_comm_services~commit_work(
    EXPORTING
    iv_rfc_dest
    = lv_destination
    ) .

    FYI, This error handling code gives the desired result when the CREATE_ENTITY_METHOD is used.

    Any suggestions?

    regards

    Nitesh

    (0) 
    1. Shalabh Jain

      Hi Nitesh,

      Please check if you need to add the error message to the Message Container. In case of an error, I usually raise an oData exception and pass the Message Container to the Exception Object. This way, the error messages are displayed in the HTTP Response.

      Regards,

      Shalabh

      (0) 
      1. Nitesh Jain

        Hi Shalabh,

        Tried below but no luck.

           DATA lo_logger  TYPE REF TO /iwbep/cl_cos_logger.

           DATA lo_message_container TYPE REF TO /iwbep/if_message_container.

           DATA lt_bapi_ret TYPE bapiret2_t.

           DATA lv_text TYPE bapi_msg.

           DATA lv_error_category TYPE /iwbep/if_message_container=>ty_error_category.

           lo_logger = /iwbep/if_mgw_conv_srv_runtime~get_logger( ).

           lo_message_container = /iwbep/if_mgw_conv_srv_runtime~get_message_container( ).

           APPEND e_return TO lt_bapi_ret.

           lv_error_category = /iwbep/if_message_container=>gcs_error_category-processing.

            ” Save backend returned Log

            lo_message_container->add_messages_from_bapi(

              EXPORTING

                it_bapi_messages  = lt_bapi_ret

                iv_error_category = lv_error_category

                iv_entity_type    = iv_entity_name

                it_key_tab        = it_key_tab ).

           MESSAGE ID e_return-id TYPE e_return-type NUMBER e_return-number INTO lv_text.

        ” Raise business exception to the consumer

           RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION

              EXPORTING

                textid            = /iwbep/cx_mgw_busi_exception=>business_error

                message           =  lv_text

                message_container = lo_message_container.

        regards

        Nitesh

        (0) 
    2. Ashwin Dutt R

      Hello Nitesh,

      Please use the below code and check once.

      data: ls_return_msg TYPE BAPIRET2.

      data: lt_return_msg TYPE BAPIRET2_T

      data: lo_message TYPE REF TO /IWBEP/IF_MESSAGE_CONTAINER.

      data: lx_bus_ex TYPE REF TO /IWBEP/CX_MGW_BUSI_EXCEPTION.

      LO_MESSAGE = MO_CONTEXT->GET_MESSAGE_CONTAINER( ).

      LO_MESSAGE->ADD_MESSAGES_FROM_BAPI( IT_BAPI_MESSAGES = LT_RETURN_MSG ).

      create OBJECT lx_bus_ex

      exporting

      message_container = LO_MESSAGE.

      raise EXCEPTION lx_bus_ex.

      Where LT_RETURN_MSG is a table containing all your messages.

      Regards,

      Ashwin

      (0) 
      1. Nitesh Jain

        Hi Ashwin,

        Checked but still the issue remains. The return error message is not coming in the response load.

        We are on

        SAP_GWFND 740 0011

        regards

        Nitesh

        (0) 
        1. Ashwin Dutt R

          Hello Nitesh,

          This piece of code is working fine for me in almost all CRUD operations to return a table of my error messages as part of exception.

          Not sure why its not working for you. Can you share the entire code here to show where exactly this piece of code is called ?

          Regards,

          Ashwin

          (0) 
          1. Nitesh Jain

            Hi Ashwin,

            This piece of code is called just after the RFC call in the CUSTOM_CREATE_DEEP_ENTITY method.

            DATA: lr_deep_entity TYPE ZCL_ZTDWM_OUTBOUND_PAC_MPC_EXT=>TS_MULTIPACK_DEEP_ENTITY,

                    lt_multipackdtl TYPE ZCL_ZTDWM_OUTBOUND_PAC_MPC_EXT=>TT_MULTIPACKDTL,

                    ls_multipackdtl TYPE ZCL_ZTDWM_OUTBOUND_PAC_MPC_EXT=>TS_MULTIPACKDTL.

               DATA lv_rfc_name TYPE tfdirfuncname.

               DATA lv_destination TYPE rfcdest.

               DATA lv_subrc TYPE systsubrc.

               DATA lv_exc_msg TYPE /iwbep/mgw_bop_rfc_excep_text.

               DATA e_proc_status TYPE char01.

               DATA e_return TYPE bapiret2.

               DATA lt_rfc_multipackdtl type standard table of ZCL_ZTDWM_OUTBOUND_PAC_MPC_EXT=>TS_RFC_MULTI_PACK.

               DATA ls_rfc_multipackdtl type ZCL_ZTDWM_OUTBOUND_PAC_MPC_EXT=>TS_RFC_MULTI_PACK.

            ** Data declaration for RFC to be added

               FIELD-SYMBOLS: <ls_multipackdtl> TYPE ZCL_ZTDWM_OUTBOUND_PAC_MPC_EXT=>TS_MULTIPACKDTL.

            *  Transform data into the internal structure

               io_data_provider->read_entry_data( IMPORTING

                                                    es_data = lr_deep_entity ).

            * Collect item details

               loop at lr_deep_entitymultipacknav assigning <ls_multipackdtl>.

                 clear ls_rfc_multipackdtl.

                 ls_rfc_multipackdtlSAP_PART = <ls_multipackdtl>ISAPPART.

                 ls_rfc_multipackdtlDELV_NO = <ls_multipackdtl>IDELVNO.

                 ls_rfc_multipackdtlDELV_ITEM = <ls_multipackdtl>IDELVITEM.

                 ls_rfc_multipackdtlPACK_QTY = <ls_multipackdtl>IPACKQTY.

                 ls_rfc_multipackdtlUOM = <ls_multipackdtl>IUOM.

                 ls_rfc_multipackdtlHANDLING_UNIT = <ls_multipackdtl>IHANDLINGUNIT.

                 append ls_rfc_multipackdtl to lt_rfc_multipackdtl.

               endloop.

            *————————————————————-

            *  Call RFC function module

            *————————————————————-

              CALL METHOD YTD_CL_GLOBAL=>GET_ECC_RFC_DESTINATION

               EXPORTING

                 SID                 = sysysid

                 CONN_TYPE           = ‘S’

               IMPORTING

                 ECC_RFC_DESTINATION = lv_destination.

            * For Packing

               if lr_deep_entityiactivity = ‘PACK’.

                 lv_rfc_name = ‘Y_OB_PACK’.

                 CALL FUNCTION lv_rfc_name DESTINATION lv_destination

                   EXPORTING

                    I_SHIPMENT_NO            = lr_deep_entityishipmentno

                    I_LINKED_HU              = lr_deep_entityilinkedhu

                    I_WHSE_NO                = lr_deep_entityiwhseno

                   IMPORTING

                    return                = e_return

                    PROC_STATUS           = e_proc_status

                   TABLES

                    T_PACK_MULTI_ITEM        = lt_rfc_multipackdtl

                   EXCEPTIONS

                    system_failure        = 1000  MESSAGE lv_exc_msg

                    communication_failure = 1001  MESSAGE lv_exc_msg

                    OTHERS                = 1002.

                  lv_subrc = sysubrc.

                 if sysubrc = 0.

                  er_deep_entityprocstatus = e_proc_status.

                 endif.

            * For Unpacking

               elseif lr_deep_entityiactivity = ‘UNPACK’.

                 lv_rfc_name = ‘Y_OB_UNPACK’.

                 CALL FUNCTION lv_rfc_name DESTINATION lv_destination

                   EXPORTING

                    I_SHIPMENT_NO            = lr_deep_entityishipmentno

                    I_LINKED_HU              = lr_deep_entityilinkedhu

                    I_WHSE_NO                = lr_deep_entityiwhseno

                   IMPORTING

                    return                = e_return

                    PROC_STATUS           = e_proc_status

                   TABLES

                    T_UNPACK_MULTI_ITEM        = lt_rfc_multipackdtl

                   EXCEPTIONS

                    system_failure        = 1000  MESSAGE lv_exc_msg

                    communication_failure = 1001  MESSAGE lv_exc_msg

                    OTHERS                = 1002.

                lv_subrc = sysubrc.

                if sysubrc = 0.

                  er_deep_entityprocstatus = e_proc_status.

                endif.

               endif.

            *Code for exception handling

            *————————————————————-

            * Error and exception handling

            *————————————————————-

              IF lv_subrc <> 0.

            * Execute the RFC exception handling process

                me->/iwbep/if_sb_dpc_comm_services~rfc_exception_handling(

                  EXPORTING

                    iv_subrc            = lv_subrc

                    iv_exp_message_text = lv_exc_msg ).

              ENDIF.

              IF e_return IS NOT INITIAL.

            data: ls_return_msg TYPE BAPIRET2.

            data: lt_return_msg TYPE BAPIRET2_T.

            data: lo_message TYPE REF TO /IWBEP/IF_MESSAGE_CONTAINER.

            data: lx_bus_ex TYPE REF TO /IWBEP/CX_MGW_BUSI_EXCEPTION.

            data: lv_text TYPE bapi_msg.

            append e_return to lt_return_msg.

            LO_MESSAGE = MO_CONTEXT->GET_MESSAGE_CONTAINER( ).

            LO_MESSAGE->ADD_MESSAGES_FROM_BAPI( IT_BAPI_MESSAGES = LT_RETURN_MSG ).

            create OBJECT lx_bus_ex

            exporting

            message_container = LO_MESSAGE.

              ENDIF.

            * Call RFC commit work

              me->/iwbep/if_sb_dpc_comm_services~commit_work(

                     EXPORTING

                       iv_rfc_dest = lv_destination

                  ) .


            regards

            Nitesh

            (0) 
            1. Ashwin Dutt R

              Hello Nitesh,

              I see that ‘ RAISE EXCEPTION lx_bus_ex. ‘ is missing in your code.

              Please add this at the end and check. It should work.

              Regards,

              Ashwin.

              (0) 
                1. Nitesh Jain

                  Hello Ashwin,

                  Issue resolved.

                  Silly mistake, had not added the Exceptions to the method CUSTOM_CREATE_DEEP_ENTITY.

                  BTW the following code is enough for exception handling.

                  * Call RFC call exception handling

                      me->/iwbep/if_sb_dpc_comm_services~rfc_save_log(

                        EXPORTING

                          is_return      = e_return

                          iv_entity_type = iv_entity_name

                          it_key_tab     = it_key_tab ).


                  No need to write the message container & add message to BAPI stuff..All this stuff is done by the above method.


                  Thanks.


                  regards

                  Nitesh

                  (0) 
  24. Kamal Jain

    Hi All,

    There is one thing here which I noticed during implementation of deep entity is the child name of structure(added in ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT DEFINITION) should be same as navigation property name. During Payload we have to provide the Navigation name and in execution gateway takes it as child name.

    Before I put different name and during debug I noticed this convention and sharing here.

    Regards,

    Kamal Jain

    (0) 
  25. Oscar Bermedo

    Hello!

    Thanks for sharing this solution!

    Could you please share an additional sample of how do I call this method from a Fiori App?

    I am stuck trying to figure out the code to achieve this in my Fiori app.

    Regards,

    Oscar

    (0) 
    1. Karthik Reddy

      Hi Muchena,

      After creating Association we have to do key field mapping(Principal entity – field & Dependent Entity – Field) . By default you will get principal entity key field name, give any field from dependent entity for mapping.

      After that delete referral constraint.

      This is how I’ve created association with out any key field mapping,

      Regards

      Karthik

      (0) 
  26. Inderpal Singh Bhangoo

    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

    (0) 
    1. Vamsi Krishna C V

      You do not need to mention the expand Query, Gateway will automatically interpret the Entity based on the structure you provide in the payload.

      Kind regards,

      Vamsi

      (0) 
      1. Sam Indra

        Hi Syam,

        Thank you for your reply.

        I completely missed out the payload query that supposed to be the skeleton of data to be created.

        Sorry because I just learned odata few days ago and from what I’ve been learned was I need to get the payload after we execute the GET method by clicking the send as request button.

        Thank you for this great tutorial, nothing could be clearer than this, you’re a gifted instructor.

        Thank you,

        sam

        (0) 
  27. Miguel Mejías

    Hi,

    what can I do if I have multiple deep entities in my SEGW project?

    Example:  If I need a deep entity operation for sales document and another for purchase orders.

    I can create two ts_deep_entity with diferents names, in the sameway I can create two custome_create_deep_entity methods.

    The redefinition of if_mgw_appl_srv_runtime~create_deep_entity method has a CASE with the HeaderSet and I can work with it.

    But I don’t know what I can do with the DEFINE Method. How can I make them coexist in the Define  Method?

    Thanks.

     

    (0) 

Leave a Reply