Skip to Content
0
Former Member
Jul 26, 2016 at 01:45 PM

How to return more than one parameter in OData service

490 Views

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