cancel
Showing results for 
Search instead for 
Did you mean: 

Problem when creating deep entity functionality

Former Member
0 Kudos

Hi experts,

I have a problem when creating deep entity for my service.

I have 2 entity Types :

* Dealer

* Bank

I have 2 entity Sets :

* Dealers

* Banks

The relationships of (Dealer : Bank) is 1 : N

I redefined /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY method.

by calling the following method

call method io_data_provider->read_entry_data( importing es_data = ls_data ).

then I execute 'POST' from gateway client

'/sap/opu/odata/sap/ZMASTERDATA_SRV/Dealers'

with XML request that has 1 Dealer and 2 banks data.

and I got the error message 'Method 'DEALERS_CREATE_ENTITY' not implemented in data provider class'

the thing that I do not understand - how the system will know to call 'Deep Entity' method instead of 'Create Entity' ?

do I need to implement 'Create Entity' method in this case ?

Really appreciate your help !!

Please let me know if you need more information from me.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Krishna,

Thanks for your response.

so I put a breakpoint in create_entity and create_deep_entity methods below.

then I executed the URI in the Gateway client - it brought me to

create_entity method.

and this is their response

and back to my original question - i don't know how the system will know to call 'Deep Entity' method instead of 'Create Entity' ?

Please let me know what you think.

Thank You,

-Martin-


kammaje_cis
Active Contributor
0 Kudos

I am sure about this logic. It calls deep entity based on availability of <inline> entries in the request body. But it is not happening in your case. Hope associations and Navigations are fine.

I assume some problem with the Data model here.

Whenever you do a deep insert, business cases are like this. Create Sales Order Items with Sales Order. Create Purchase Order Items with Purchase Order Header. Yours is a not a ideal Parent child relationship. (Dealer and Bank). This is more of an Association.

As you can see in the examples I gave Child Entity has keys of the parent as well as keys. In your case I do not thin Bank has keys of Dealer as Keys as well.

Thanks

Krishna

kammaje_cis
Active Contributor
Former Member
0 Kudos

Hi Krishna,

Thanks again for your help.

This is my data model

* Dealer (as parent) - the key is 'Dealer ID'

* Bank (as child) - the key is 'Dealer ID' and 'Bank ID'

Yeah, I have already read the document.

if you see inside the document (page 2) - the data model that they have pretty much the same with mine.

SOHeader - has key Order ID

SOItem - has key Order ID and item ID

I am not sure if the data model could be a problem in my case.

Please let me know what you think.

Thank You,

-Martin-

Former Member
0 Kudos

Hi Martin,

We are also facing similar issue while calling the POST method for one of the Gateway Service. Did you find any solution, if so Kindly share.

Thanks in advance.

Radhika

Former Member
0 Kudos

Hi Radhika,

yeah - I got this problem solved.

in the create_deep_entity method - the declaration of the child has to be the same name as Navigation Property name of the parent.

  types : ty_t_io type table of zcl_zmasterdata2_mpc=>ts_insoobject with default key.

  types : begin of ty_dealer_io.

          include type zcl_zmasterdata2_mpc=>ts_dealer.

  types : sodealer type ty_t_io,

          end of ty_dealer_io.

sodealer is the navigation property's name of my dealer entity.

Hope this helps !!!

Regards,

-Martin-

Former Member
0 Kudos

Same problem, same solution!

Thanks

Former Member
0 Kudos

Have the same problem, but still no solution. Has anybody an idea?

*-----------------------------------------------------------------------------
* Sales Order Header
*-----------------------------------------------------------------------------
* Create the SalesOrderHeader data object
     lo_entity_type = model->create_entity_type( 'OrderHeader' ).
* Define the properties of the SalesOrderHeader object
     lo_property = lo_entity_type->create_property( 'vbeln' )."OrderId
* set it as a key element
     lo_property->set_is_key( ).
     lo_property = lo_entity_type->create_property( 'auart' )."DocumentType
     lo_property = lo_entity_type->create_property( 'audat' )."DocumentDate
     lo_property = lo_entity_type->create_property( 'kunnr' )."CustomerId
     lo_property = lo_entity_type->create_property( 'vkorg' )."SalesOrg
     lo_property = lo_entity_type->create_property( 'vtweg' )."DistChannel
     lo_property = lo_entity_type->create_property( 'spart' )."Division
     lo_property = lo_entity_type->create_property( 'netwr' )."OrderValue
     lo_property = lo_entity_type->create_property( 'waerk' )."Currency

     lo_property = lo_entity_type->create_property( 'erdat' )"Auftrag ange-legt am
     lo_property = lo_entity_type->create_property( 'zzgruppe' ). "gruppe
     lo_property = lo_entity_type->create_property( 'zzgebiet' ). "gebiet

     lo_property = lo_entity_type->create_property( 'bstdk' ). "bestelldatum

     lo_property = lo_entity_type->create_property( 'gbsta' ). "Gesamtstatus
     lo_property = lo_entity_type->create_property( 'lfsta' ). "lieferstatus

*    lo_property = lo_entity_type->create_property( 'kunnr' ). "KNA1-KUNNR  Kundennummer
     lo_property = lo_entity_type->create_property( 'anred' ). "KNA1-ANRED  Anrede
     lo_property = lo_entity_type->create_property( 'name1' )."KNA1-NAME1  Name
     lo_property = lo_entity_type->create_property( 'name2' )."KNA1-NAME2  Name 2
     lo_property = lo_entity_type->create_property( 'stras' )."KNA1-STRAS  Straße und Hausnummer
     lo_property = lo_entity_type->create_property( 'pstlz' )."KNA1-PSTLZ  Postleitzahl
     lo_property = lo_entity_type->create_property( 'ort01' )."KNA1-ORT01  Ort
     lo_property = lo_entity_type->create_property( 'land1' )."KNA1-LAND1  Länderschlüssel
     lo_property = lo_entity_type->create_property( 'telf1' )."KNA1-TELF1  1. Telefonnummer
     lo_property = lo_entity_type->create_property( 'telfx' )."KNA1-TELFX  Telefaxnummer

* Bind your structure that represents the above properties
     lo_entity_type->bind_structure( 'ZCL_DIVA_ORDER_MPC=>S_SO_HDR' ).
* Name for the collection
     lo_entity_type->create_entity_set( 'OrderHeaders' ).

*-----------------------------------------------------------------------------
* Sales Order Item
*-----------------------------------------------------------------------------
* Create the SalesOrderItem data object
     lo_entity_type = model->create_entity_type( 'OrderItem' ).
* Define the properties of the SalesOrderItem object
     lo_property = lo_entity_type->create_property( 'vbeln' )."OrderId
* set it as a key element
     lo_property->set_is_key( ).
     lo_property = lo_entity_type->create_property( 'posnr' )."Item
* set it as a key element
     lo_property->set_is_key( ).
     lo_property = lo_entity_type->create_property( 'matnr' )."Material
     lo_property = lo_entity_type->create_property( 'arktx' )."Description
     lo_property = lo_entity_type->create_property( 'werks' ). "Plant
     lo_property = lo_entity_type->create_property( 'kwmeng' )." Quantity
     lo_property = lo_entity_type->create_property( 'vrkme' )."UoM
     lo_property = lo_entity_type->create_property( 'netwr' )."Value

* Bind your structure that represents the above properties
     lo_entity_type->bind_structure( 'ZCL_DIVA_ORDER_MPC=>S_SO_ITEM' ).
     lo_entity_type->create_entity_set( 'OrderItems' ).


******************************************************************************
* ASSOCIATIONS
******************************************************************************
     "Define Association SO Header to SO Items
     lo_association = model->create_association(
                                                  iv_association_name = 'OrderHeader_OrderItems'
                                                  iv_left_type = 'OrderHeader'
                                                  iv_right_type = 'OrderItem'
                                                  iv_right_card = cardinality_feed
                                                  iv_left_card = cardinality_entity ).


     "Define Association SO Item to SO Header
     lo_association = model->create_association(
                                                 iv_association_name = 'OrderItem_OrderHeader'
                                                 iv_left_type = 'OrderItem'
                                                 iv_right_type = 'OrderHeader'
                                                 iv_right_card = cardinality_entity
                                                 iv_left_card = cardinality_entity ).


******************************************************************************
* NAVIGATION PROPERTIES
******************************************************************************
     "Navigation Properties for entity SO Header
     lo_entity_type = model->get_entity_type( iv_entity_name = 'OrderHeader' ).

     "Add Navigation Property from role SOHeader to role SOItems
     lo_entity_type->create_navigation_property(
                                   iv_property_name = 'OrderItems'
                                   iv_association_name = 'OrderHeader_OrderItems' ).

     "Navigation Properties for entity SO Item
     lo_entity_type = model->get_entity_type( iv_entity_name = 'OrderItem' ).

     "Add Navigation Property from role SOItem to SOHeader
     lo_entity_type->create_navigation_property(
                                   iv_property_name = 'OrderHeader'
                                   iv_association_name = 'OrderItem_OrderHeader' ).

SyambabuAllu
Contributor
0 Kudos

Hi Sandro,

Please look into below blog for your solution

Thanks,

Syam

Former Member
0 Kudos

Hi Syam


Thanks for your Blog Post, I already went through your example. I just extended the "How To... Create Complex Business .."  Document with some additional fields in the structure. Everthing works fine, except, that the create_entity instead create_deep_entity method is called.

(Yes I used <m:inline> in my XML).

In the debugger I saw, that the "LV_EXPAND" Variable is empty. This should be filled, because I'm using the inline tag in my http header.

Is there a SAP error in my gateway or are the definitions of my associations/navigation properties wrong?

******************************************************************************
* ASSOCIATIONS
******************************************************************************
     "Define Association SO Header to SO Items
     lo_association = model->create_association(
                                                  iv_association_name = 'OrderHeader_OrderItems'
                                                  iv_left_type = 'OrderHeader'
                                                  iv_right_type = 'OrderItem'
                                                  iv_right_card = cardinality_feed
                                                  iv_left_card = cardinality_entity ).


     "Define Association SO Item to SO Header
     lo_association = model->create_association(
                                                 iv_association_name = 'OrderItem_OrderHeader'
                                                 iv_left_type = 'OrderItem'
                                                 iv_right_type = 'OrderHeader'
                                                 iv_right_card = cardinality_entity
                                                 iv_left_card = cardinality_entity ).


******************************************************************************
* NAVIGATION PROPERTIES
******************************************************************************
     "Navigation Properties for entity SO Header
     lo_entity_type = model->get_entity_type( iv_entity_name = 'OrderHeader' ).

     "Add Navigation Property from role SOHeader to role SOItems
     lo_entity_type->create_navigation_property(
                                   iv_property_name = 'OrderItems'
                                   iv_association_name = 'OrderHeader_OrderItems' ).

     "Navigation Properties for entity SO Item
     lo_entity_type = model->get_entity_type( iv_entity_name = 'OrderItem' ).

     "Add Navigation Property from role SOItem to SOHeader
     lo_entity_type->create_navigation_property(
                                   iv_property_name = 'OrderHeader'
                                   iv_association_name = 'OrderItem_OrderHeader'

AshwinDutt
Active Contributor
0 Kudos

Hello Sandro,

Kindly share the URL & payload used to fire your Create operation which has got Header & Item relation. So that we can figure out what is wrong.

U have implemented Create Deep Entity and placed your code there is it?

Regards,

Ashwin

Former Member
0 Kudos

Unfortunatly I can't share the URL, but I copied all the content from the "DEFINE" method. My payload was the same used in this doc.

<edmx:Edmx Version="1.0"><edmx:DataServices m:DataServiceVersion="2.0"><Schema Namespace="ZDIVA_ORDER" xml:lang="de"><EntityType Name="OrderHeader" sap:content-version="1"><Key><PropertyRef Name="vbeln"/></Key><Property Name="vbeln" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Vertriebsbeleg"/><Property Name="auart" Type="Edm.String" MaxLength="4" sap:label="Verk.belegart"/><Property Name="audat" Type="Edm.DateTime" sap:label="Datum"/><Property Name="kunnr" Type="Edm.String" MaxLength="10" sap:label="Debitor"/><Property Name="vkorg" Type="Edm.String" MaxLength="4" sap:label="Verkaufsorg."/><Property Name="vtweg" Type="Edm.String" MaxLength="2" sap:label="Vertriebsweg"/><Property Name="spart" Type="Edm.String" MaxLength="2" sap:label="Sparte"/><Property Name="netwr" Type="Edm.Decimal" Precision="15" Scale="2" sap:label="Nettowert"/><Property Name="waerk" Type="Edm.String" MaxLength="5" sap:label="Belegwährung" sap:semantics="currency-code"/><Property Name="erdat" Type="Edm.DateTime" sap:label="Angelegt am"/><Property Name="zzgruppe" Type="Edm.String" MaxLength="4" sap:label="Gruppe"/><Property Name="zzgebiet" Type="Edm.String" MaxLength="4" sap:label="Gebiet"/><Property Name="bstdk" Type="Edm.DateTime" sap:label="Bestelldatum"/><Property Name="gbsta" Type="Edm.String" MaxLength="1"/><Property Name="lfsta" Type="Edm.String" MaxLength="1"/><Property Name="anred" Type="Edm.String" MaxLength="15" sap:label="Anrede"/><Property Name="name1" Type="Edm.String" MaxLength="30" sap:label="Name 1"/><Property Name="name2" Type="Edm.String" MaxLength="30" sap:label="Name 2"/><Property Name="stras" Type="Edm.String" MaxLength="30" sap:label="Straße/Hausnr"/><Property Name="pstlz" Type="Edm.String" MaxLength="10" sap:label="Postleitzahl"/><Property Name="ort01" Type="Edm.String" MaxLength="25" sap:label="Ort"/><Property Name="land1" Type="Edm.String" MaxLength="3" sap:label="Land"/><Property Name="telf1" Type="Edm.String" MaxLength="16" sap:label="Telefon-1"/><Property Name="telfx" Type="Edm.String" MaxLength="31" sap:label="Telefax"/><NavigationProperty Name="OrderItems" Relationship="ZDIVA_ORDER.OrderHeader_OrderItems" FromRole="FromRole_OrderHeader_OrderItems" ToRole="ToRole_OrderHeader_OrderItems"/></EntityType><EntityType Name="OrderItem" sap:content-version="1"><Key><PropertyRef Name="vbeln"/><PropertyRef Name="posnr"/></Key><Property Name="vbeln" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Vertriebsbeleg"/><Property Name="posnr" Type="Edm.String" Nullable="false" MaxLength="6" sap:label="Position"/><Property Name="matnr" Type="Edm.String" MaxLength="18" sap:label="Material"/><Property Name="arktx" Type="Edm.String" MaxLength="40" sap:label="Bezeichnung"/><Property Name="werks" Type="Edm.String" MaxLength="4" sap:label="Werk"/><Property Name="kwmeng" Type="Edm.Decimal" Precision="15" Scale="3" sap:label="KumAuftMenge"/><Property Name="vrkme" Type="Edm.String" MaxLength="3" sap:label="VerkaufsME" sap:semantics="unit-of-measure"/><Property Name="netwr" Type="Edm.Decimal" Precision="15" Scale="2" sap:label="Nettowert"/><NavigationProperty Name="OrderHeader" Relationship="ZDIVA_ORDER.OrderItem_OrderHeader" FromRole="FromRole_OrderItem_OrderHeader" ToRole="ToRole_OrderItem_OrderHeader"/></EntityType><Association Name="OrderHeader_OrderItems" sap:content-version="1"><End Type="ZDIVA_ORDER.OrderHeader" Multiplicity="1" Role="FromRole_OrderHeader_OrderItems"/><End Type="ZDIVA_ORDER.OrderItem" Multiplicity="*" Role="ToRole_OrderHeader_OrderItems"/></Association><Association Name="OrderItem_OrderHeader" sap:content-version="1"><End Type="ZDIVA_ORDER.OrderItem" Multiplicity="1" Role="FromRole_OrderItem_OrderHeader"/><End Type="ZDIVA_ORDER.OrderHeader" Multiplicity="1" Role="ToRole_OrderItem_OrderHeader"/></Association><EntityContainer Name="ZDIVA_ORDER" m:IsDefaultEntityContainer="true"><EntitySet Name="OrderItems" EntityType="ZDIVA_ORDER.OrderItem" sap:content-version="1"/><EntitySet Name="OrderHeaders" EntityType="ZDIVA_ORDER.OrderHeader" sap:content-version="1"/><AssociationSet Name="OrderItem_OrderHeader_AssocSet" Association="ZDIVA_ORDER.OrderItem_OrderHeader" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:content-version="1"><End EntitySet="OrderItems" Role="FromRole_OrderItem_OrderHeader"/><End EntitySet="OrderHeaders" Role="ToRole_OrderItem_OrderHeader"/></AssociationSet><AssociationSet Name="OrderHeader_OrderItems_AssocSet" Association="ZDIVA_ORDER.OrderHeader_OrderItems" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:content-version="1"><End EntitySet="OrderHeaders" Role="FromRole_OrderHeader_OrderItems"/><End EntitySet="OrderItems" Role="ToRole_OrderHeader_OrderItems"/></AssociationSet></EntityContainer><atom:link rel="self" href="https://URL:44300/sap/opu/odata/sap/ZDIVA_ORDER/$metadata"/><atom:link rel="latest-version" href="https://URL:44300/sap/opu/odata/sap/ZDIVA_ORDER/$metadata"/></Schema></edmx:DataServices></edmx:Edmx>

AshwinDutt
Active Contributor
0 Kudos

Hello Sandro,

Full URL is not expected.

Expected is <Entity Set Name> & <Service Name> in the below sample URL. Not <GWHost> & <Port>

http://<GWHost>:<port>/sap/opu/odata/sap/<Service Name>/<Entity Set Name>

With the details you have shared its very tedious to figure out things.

Kindly share your model which you would have defined in DEFINE method of you MPC_EXT class.

It would be great if you share the exact payload used to fire your Create Deep Insert rather than giving reference to the documents as we cannot infer anything without seeing exact your payload , navigation & association properties ( your MODEL not the metadata from GW Client ).

The reason why its not hitting Create Deep Entity method would be incorrect Payload.

To resolve this we need the details which i have already requested above.

Kindly provide those details.

Regards,

Ashwin

Former Member
0 Kudos

Thanks for your support guys! I solved the problem with this SAP Note

http://service.sap.com/sap/support/notes/1922411

this thread:

I used JSON instead of XML/ATOM and I generated the JSON file from my GET Request, removed the result tag and added this HTTP Header:

Acceptapplication/json
Content-Type

application/json

One Big problem was the incorrect payload. I had troubles with the correct layout and patterns (Navigation, Assoc. etc.). The JSON document is much more clearer.

Former Member
0 Kudos

Hi Sandro,

I have similar requrement. But I donot have associations and navigations. All i need to create is multiple values.

I have header to item realtion posting only. But the header data is hardcoded in SEGW. (No input from URI). The URI will give only item values, multiple.

Can some one guide me how to create deep entity for the same.  Also please guide me on how to handle to payload in xml format.

One more doubt. Do we need CREATE operation to follow the READ/QUERY operation.

Thanks,

SK

AshwinDutt
Active Contributor
0 Kudos

Hello Siva,

I would suggest below approach even though u have hard coded header values.

1. Use SEGW to model ur service.

Create entities and create association & navigation between them with appropriate cardinality as per ur scenario.

In ur use case Header entity to Item entity with cardinality 1 to N

2. Implement Create_Deep_Entity method in DPC_EXT class manually and call ur logic.

3. Use JSON payload which be easy to generate that from UI application.

However XML payload can also be used.

4. JSON Sample payload ->

{

"Id":"01",

"Name":"Ashwin",

"Name2":"Dutt",

"HeaderItem":[{"IdO":"10","NameO":"TestO1"},

{"IdO":"20","NameO":"TestO2"}]

}

Refer below for all the details to accomplish ur scenario.

Step by Step development for CREATE_DEEP_ENTITY operation

Regards,

Ashwin

Answers (1)

Answers (1)

kammaje_cis
Active Contributor
0 Kudos

Hi Martin,

Framework looks into the Payload (request body) to decide whether call Normal Create method or Deep Create. So for me the problem seems to be with your request body. May be you can post it here.

Thanks

Krishna

Former Member
0 Kudos

Hi Krishna,

Thank you for your response.

This is the XML Request

<?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:DealerID>WN01234</d:DealerID>

           <d:DealerName>Dealer ABC</d:DealerName>

           <d:Street>Main St</d:Street>

           <d:City>Dallas</d:City>

           <d:State>TX</d:State>

           <d:PostalCode>77766</d:PostalCode>

      </m:properties>

</atom:content>

<atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Bank"

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

      title="ZMASTERDATA_SRV.Dealer_Banks">

<m:inline>

      <atom:feed>

      <atom:entry>

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

           <m:properties>

                <d:BankAcct>1234567892</d:BankAcct>

                <d:BankKey>122000247</d:BankKey>

                <d:DealerID>WN01234</d:DealerID>

                <d:BankDetailID>TES8</d:BankDetailID>

           </m:properties>

      </atom:content>

      </atom:entry>

      </atom:feed>

</m:inline>

</atom:link>

</atom:entry>

URI : /sap/opu/odata/sap/ZMASTERDATA_SRV/Dealers

Please let me know what you think.

Thanks again,

-Martin-

kammaje_cis
Active Contributor
0 Kudos

HI Martin,

I do not see any problem with the request body. The control should go to create_deep_entity method.

Can you put a breakpoint in create_entity method and create_deep_entity methods and confirm where the control is coming ?

Thanks

Krishna