cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in implemnting Gateway service

prathik
Participant
0 Kudos

Hi ,

This is my scenario...

I have created a function module which accepts two numbers and displays the result of it...in this I have two import parameters( A & B) and one export parameter(RES). RES stores the sum of A & B.

Using this function module i have created a service in gateway, I'm able to view the xml file in the HTTP Response part of the gateway client (/iwfnd/gw_client)

the name of my service is ZMY_DEMO_SRV

this is my URL -> /sap/opu/odata/sap/ZMY_DEMO_SRV/?$format=xml

<?xml version="1.0" encoding="utf-8" ?>

- <app:service xml:lang="en" xml:base="http://<server-name>:<port-no>/sap/opu/odata/sap/ZMY_DEMO_SRV/" xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">

- <app:workspace>

<atom:title type="text">Data</atom:title>

- <app:collection sap:content-version="1" href="NEWCollection">

<atom:title type="text">NEWCollection</atom:title>

<sap:member-title>NEW</sap:member-title>

</app:collection>

</app:workspace>

<atom:link rel="self" href="http://<server-name>:<port-no>sap/opu/odata/sap/ZMY_DEMO_SRV/" />

<atom:link rel="latest-version" href="http://<server-name>:<port-no>/sap/opu/odata/sap/ZMY_DEMO_SRV/" />

</app:service>

Here is my metadata xml file

-> /sap/opu/odata/sap/ZMY_DEMO_SRV/$metadata

<?xml version="1.0" encoding="utf-8" ?>

- <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">

- <edmx:DataServices m:DataServiceVersion="2.0">

- <Schema Namespace="ZMY_DEMO_SRV" xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">

- <EntityType Name="NEW" sap:content-version="1">

- <Key>

<PropertyRef Name="Res" />

</Key>

<Property Name="A" Type="Edm.Int32" Nullable="false" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

<Property Name="B" Type="Edm.Int32" Nullable="false" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

<Property Name="Res" Type="Edm.Int32" Nullable="false" sap:sortable="false" sap:filterable="false" />

</EntityType>

- <EntityContainer Name="ZMY_DEMO_SRV" m:IsDefaultEntityContainer="true">

<EntitySet Name="NEWCollection" EntityType="ZMY_DEMO_SRV.NEW" sap:content-version="1" />

</EntityContainer>

<atom:link rel="self" href="http://<server-name>:<port-no>/sap/opu/odata/sap/ZMY_DEMO_SRV/$metadata" xmlns:atom="http://www.w3.org/2005/Atom" />

<atom:link rel="latest-version" href="http://<server-name>:<port-no>/sap/opu/odata/sap/ZMY_DEMO_SRV/$metadata" xmlns:atom="http://www.w3.org/2005/Atom" />

</Schema>

</edmx:DataServices>

</edmx:Edmx>

         Now I wanted my service to accept two inputs and print the result .

C      Could you please guide me through as to how to go about doing this in the URL if possible or is there any other

         way to go about this ...

          Regards,

          Prathik.

Accepted Solutions (1)

Accepted Solutions (1)

former_member184867
Active Contributor
0 Kudos

Hi,

Ideally for this case function import should be used.

You can get the details of function import (or Service Operation)  in http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/  section 3.3.

A function import is meant for performing some action and return the result based on the input passed. 

In your case you may pass two numbers to function import as parameter and get the result back.

You can have a look at the following link,

http://help.sap.com/saphelp_nw74/helpdata/en/c5/dc22512c312314e10000000a44176d/content.htm

However it is not possible to create function import in service builder. Some manual coding is necessary for this. You can have a look at the sample coding done for service RMTSAMPLFLIGHT_2. The metadata definition for this service can be found in class /IWBEP/CL_MGW_RMTSFLIGHT2_MPC method DEFINE(in the code search with GetAvailableFlights). The data provider implementation can be found in class /IWBEP/CL_MGW_RMTSFLIGHT2_DPC  method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION.

Hope this helps.

Regards,

Atanu

CRVMANISH
Contributor
0 Kudos

Hello Atanu,

Is there any example how function import works.

I tried but i get same error.

Please see the screenshot , let me know what is wrong here.

Regards

Manish

former_member184867
Active Contributor
0 Kudos

Hi Manish,

The screenshot says everything is successful.

what is the Error ?

Please also share the metadata and the URL that you are executing.

Regards,

Atanu

CRVMANISH
Contributor
0 Kudos

Hello Atanu

Here is the metadata

-------------------------------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8" ?>

- <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">

- <edmx:DataServices m:DataServiceVersion="2.0">

- <Schema Namespace="ZGIS_GW_TEST_SRV" xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">

- <EntityType Name="ZWRK_CTR" sap:content-version="1">

- <Key>

<PropertyRef Name="IsNotifNo" />

<PropertyRef Name="IsPlant" />

<PropertyRef Name="IsWrkCtr" />

</Key>

<Property Name="IsNotifNo" Type="Edm.String" Nullable="false" MaxLength="12" sap:label="Notification" sap:sortable="false" sap:filterable="false" />

<Property Name="IsPlant" Type="Edm.String" Nullable="false" MaxLength="4" sap:label="Company Code" sap:sortable="false" sap:filterable="false" />

<Property Name="IsWrkCtr" Type="Edm.String" Nullable="false" MaxLength="8" sap:label="Work center" sap:sortable="false" sap:filterable="false" />

</EntityType>

- <EntityContainer Name="ZGIS_GW_TEST_SRV" m:IsDefaultEntityContainer="true">

<EntitySet Name="ZWRK_CTR" EntityType="ZGIS_GW_TEST_SRV.ZWRK_CTR" sap:pageable="false" sap:addressable="false" sap:content-version="1" />

- <FunctionImport Name="Update_Wrk_Ctr" m:HttpMethod="POST" sap:action-for="ZGIS_GW_TEST_SRV.ZWRK_CTR">

- <Parameter Name="IS_WRK_CTR" Type="Edm.String" Mode="In" MaxLength="8">

- <Documentation>

<Summary>Work center</Summary>

<LongDescription />

</Documentation>

</Parameter>

- <Parameter Name="IsNotifNo" Type="Edm.String" Mode="In" MaxLength="12">

- <Documentation>

<Summary>Notification</Summary>

<LongDescription />

</Documentation>

</Parameter>

- <Parameter Name="IsPlant" Type="Edm.String" Mode="In" MaxLength="4">

- <Documentation>

<Summary>Company Code</Summary>

<LongDescription />

</Documentation>

</Parameter>

</FunctionImport>

</EntityContainer>

</Schema>

</edmx:DataServices>

</edmx:Edmx>

----------------------------------------------------------------------------------------------------------------------------------------------

URL used

/sap/opu/odata/sap/ZGIS_GW_TEST_SRV/Update_Wrk_Ctr(IS_WRK_CTR='CENTER6',IsNotifNo='000300000131',IsPlant='0001')

Error

----------------------------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8" ?>

- <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<code>005056A509B11EE1B9A8DBD9EA7B5778</code>

<message xml:lang="en">An unexpected error occured when accessing the entity data model</message>

</error>

CRVMANISH
Contributor
0 Kudos

Hello Atanu

Am i using correct URL.

Please suggest.

Regards

Manish

former_member184867
Active Contributor
0 Kudos

Hi,

the URL is incorrect.

It Should be

/sap/opu/odata/sap/ZGIS_GW_TEST_SRV/Update_Wrk_Ctr?IS_WRK_CTR='CENTER6'&IsNotifNo='000300000131'&IsPlant='0001'

Refer to section  3.3 of following link

http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/

Atanu

CRVMANISH
Contributor
0 Kudos

Tried this URL also but gives same error.

Please Suggest.

Regards

Manish

former_member184867
Active Contributor
0 Kudos

Hi,

What is the error?

Does the control go to method  /IWFND/IF_MGW_APPL_RUNTIME~UPDATE_ENTITY() of your Data provider class ?

Atanu

CRVMANISH
Contributor
0 Kudos

Hello Atanu,

No it does not goes to /IWFND/IF_MGW_APPL_RUNTIME~UPDATE_ENTITY()

Please Suggest.

Regards

Manish

Former Member
0 Kudos

Hello,

my model recently also resulted in the error message An unexpected error occured when accessing the entity data model. Szenario:

  • I have an entity type with a navigation property and an association
  • I have two entity sets of that type
  • I have declared two association sets
  • When I looked into $metadata, you could see that the association sets where not correctly attributed to the respective entity sets (even though in SEGW I had done that)

Solution:

In the model provider class (...MPC_EXT), I manually added the missing association set:

METHOD define.

   super->define( ).
   model->create_association_set( iv_association_set_name  = 'MyMissingAssociationSet'
                                  iv_association_name      = 'LegsOfAnimals'
                                  iv_left_entity_set_name  = 'Dogs'
                                  iv_right_entity_set_name = 'Legs' ).

ENDMETHOD.

BTW: This seems to be bug in /IWBEP/CL_MGW_ODATA_ASSOCIATN->/IWBEP/IF_MGW_ODATA_ASSOC~CREATE_ASSOC_SET, where a comment says

" again defaulting... by the first entityset which is found for the entity type


Björn

Answers (1)

Answers (1)

paschmann
Advisor
Advisor
0 Kudos

Hello Prathik,

I believe the parameter input method you are trying to achieve is defined as a service operation parameter. You see the documentation below for some additional details and an example.

http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/

I hope this helps, Paul