Skip to Content
author's profile photo Former Member
Former Member

How to return more than one parameter in OData service

Hi,

I'm developing an OData service for a SAPUI5 application.

I have a custom function module that returns two parameters: employee data and messages.

I created a service from the SEGW transaction with: two entities, the read and the query method for both of them and the association.

When I try to get the employee data entity only, it works (.../sap/opu/odata/sap/ZGW_GET_CID_DATA_SRV/CidDataSet('00000001')/?$format=json).

But if I try with the $expand statement (.../sap/opu/odata/sap/ZGW_GET_CID_DATA_SRV/CidDataSet('00000001')/?$expand=MsgSet&$format=json), I receive the error: Resource not found for the segment 'MsgSet'.

The metadata:

<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:sap="http://www.sap.com/Protocols/SAPData" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm" sap:schema-version="1" Namespace="ZGW_GET_CID_DATA_SRV_02">
<EntityType sap:content-version="1" Name="CidData">
<Key>
<PropertyRef Name="Pernr"/>
</Key>
<Property Name="Pernr" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Personnel no." MaxLength="8" Nullable="false" Type="Edm.String"/>
<Property Name="Groupname" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Group name" Nullable="false" Type="Edm.String"/>
<Property Name="Tabname" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Table name" Nullable="false" Type="Edm.String"/>
<Property Name="Fieldname" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Field name" Nullable="false" Type="Edm.String"/>
<Property Name="Fielddesc" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Field description" Nullable="false" Type="Edm.String"/>
<Property Name="Fieldvalue" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Field value" Nullable="false" Type="Edm.String"/>
<Property Name="Input" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Input" MaxLength="1" Nullable="false" Type="Edm.String"/>
<Property Name="Required" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Required" MaxLength="1" Nullable="false" Type="Edm.String"/>
<Property Name="Shlpname" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Search Help Name" MaxLength="30" Nullable="false" Type="Edm.String"/>
<Property Name="History" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="History" MaxLength="1" Nullable="false" Type="Edm.String"/>
<Property Name="Table" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Table" MaxLength="1" Nullable="false" Type="Edm.String"/>
<Property Name="Icon" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Icon" Nullable="false" Type="Edm.String"/>
<NavigationProperty Name="ReturnMsg" ToRole="ToRole_RetMsg" FromRole="FromRole_RetMsg" Relationship="ZGW_GET_CID_DATA_SRV_02.RetMsg"/>
</EntityType>
<EntityType sap:content-version="1" Name="Msg">
<Key>
<PropertyRef Name="Pernr"/>
</Key>
<Property Name="Pernr" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Personnel no." MaxLength="8" Nullable="false" Type="Edm.String"/>
<Property Name="Type" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Message Type" MaxLength="1" Nullable="false" Type="Edm.String"/>
<Property Name="Message" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Character 100" MaxLength="100" Nullable="false" Type="Edm.String"/>
</EntityType>
<Association sap:content-version="1" Name="RetMsg">
<End Type="ZGW_GET_CID_DATA_SRV_02.CidData" Role="FromRole_RetMsg" Multiplicity="0..1"/>
<End Type="ZGW_GET_CID_DATA_SRV_02.Msg" Role="ToRole_RetMsg" Multiplicity="*"/>
<ReferentialConstraint>
<Principal Role="FromRole_RetMsg">
<PropertyRef Name="Pernr"/>
</Principal>
<Dependent Role="ToRole_RetMsg">
<PropertyRef Name="Pernr"/>
</Dependent>
</ReferentialConstraint>
</Association>
<EntityContainer Name="ZGW_GET_CID_DATA_SRV_02_Entities" sap:supported-formats="atom json xlsx" m:IsDefaultEntityContainer="true">
<EntitySet sap:content-version="1" Name="MsgSet" sap:updatable="false" sap:creatable="false" sap:pageable="false" sap:deletable="false" EntityType="ZGW_GET_CID_DATA_SRV_02.Msg"/>
<EntitySet sap:content-version="1" Name="CidDataSet" sap:updatable="false" sap:creatable="false" sap:pageable="false" sap:deletable="false" EntityType="ZGW_GET_CID_DATA_SRV_02.CidData"/>
<AssociationSet sap:content-version="1" Name="RetMsgSet" sap:updatable="false" sap:creatable="false" sap:deletable="false" Association="ZGW_GET_CID_DATA_SRV_02.RetMsg">
<End Role="FromRole_RetMsg" EntitySet="CidDataSet"/>
<End Role="ToRole_RetMsg" EntitySet="MsgSet"/>
</AssociationSet>
</EntityContainer>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://52.17.15.122:1090/sap/opu/odata/sap/ZGW_GET_CID_DATA_SRV/$metadata" rel="self"/>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://52.17.15.122:1090/sap/opu/odata/sap/ZGW_GET_CID_DATA_SRV/$metadata" rel="latest-version"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

It's not necessary for the application that the entities have to be associated, but I just need the service to return the two parameters.

Any idea?

Thanks

Regards,

Federico

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 26, 2016 at 01:53 PM

    Hi,

    When you do a get for employee entity, in the response we get a href link. Which give the proper association URI, take the name from there after $links.

    Pass that in expand, also check for source value in your get entity set method for messages.

    Regards

    Ashish

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.