Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Getting Started Newsletters Store

Hi, Guest

Log On Join Us

Search the Community

Products

Services & Support

About SCN

Downloads

Industries

Training & Education

Partnership

Developer Center

Activity

Lines of Business

University Alliances

Events & Webinars

Innovation

Browse

Communications

Actions

Actions

volker.drees

Step-by-step guide to build an OData Service based


on RFCs Part 3

Login to follow, like, comment, share and


bookmark content.

Login

Register

Previous
Next
Posted by Volker Drees in volker.drees on Oct 26, 2012 11:45:07 AM
Share

Like

Thanks for sticking to this multi-part step-by-step guide.


Looking into this part (3) means that you have successfully completed the first part (1) and the second part (2)
and you are now curious to see how our EPM OData Service will be extended with an Association and a Navigation
Property. This will allow us to navigate from the Sales Order to the related Sales Order Line Items by using a link
instead of manually putting a filter together. Furthermore this also allows us to use the $expand statement to fetch the
Sales Order together with all Sales Order Line Items in one http call.
postpost
We are still in the Service Builder and enhancing our project that we created in part 1 and extended in part 2.
1. Double-click Associations:

Filter Blog
By date:
--By tag:

gateway mobile
netweaver_gateway odata rfc
sap_netweaver_gateway
service_builder
Recent Posts

2. Choose the Create pushbutton:

Step-by-step guide to build an OData Service based on


RFCs Part 3
Step-by-step guide to build an OData Service based on
RFCs Part 2
Step-by-step guide to build an OData Service based on
RFCs Part 1
How to set up Generic Workflow Handling in Alloy
3. Enter the following values for the Association and choose Enter:

How to set up the Verification Workflow in Alloy


Tiny ABAP Report to fire your Alloy Workflow

Name

SalesOrderSalesOrderItems

Principal Entity*

SalesOrder

How to enrich your Alloy Workflow with backend


attributes

Principal Entity Cardinality*

How to expose a Decision Workflow to Alloy

Dependent Entity*

SalesOrderItem

How to troubleshoot Duet ESA WebServices - Part 2

Dependent Entity Cardinality*

How to troubleshoot Duet ESA WebServices

*) This field has an input help


Now we will Create a referential constraint for the association
1. Expand the Associations node and the SalesOrderSalesOrderItems node and double-click Referential Constraints:

Incoming Links
Step-by-Step Add a New Entity with Association
and Implement it
Displaying only last record(in entityset) multiple
times in Table (Using Association & Navigation)?

converted by Web2PDFConvert.com

Re: expand query option in OData


Consuming an External RESTful Web Service
with ABAP in Gateway
Re: Not able to fetch data using Odata
Get_Entityset in SEGW
Re: Input Parameters for Odata Service

2. Choose the Create pushbutton:

3. Enter the following values and choose Enter:


Principal Key*

SoId

Dependent Property*

SoId

*) This field has an input help

Now we create an association set for the association


1. Double-click Association Sets:

2. Choose the Create pushbutton:

3. Enter the values and choose Enter:


Name

SalesOrderSalesOrderItems

Association*

SalesOrderSalesOrderItems

*) This field has an input help

converted by Web2PDFConvert.com

And finally we create a navigation property based on the referential constraint


1. Expand Data Model -> Entity Types -> SalesOrder and double-click Navigation Properties:

2. Choose the Create pushbutton:

3. Enter the following values and choose Enter:


Name

SalesOrderItems

Relationship Name*

SalesOrderSalesOrderItems

*) This field has an input help


Now we need to re-generate the runtime objects and were then ready to test the service
1. Choose the Generate pushbutton:

2. Verify that the runtime objects have been generated successfully:

3. Start the Gateway Client (Transaction /IWFND/GW_CLIENT) in a separate window to run the service. Provide the
following URI to get the metadata for the service:
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/$metadata

converted by Web2PDFConvert.com

The Sales Order collection now includes a navigation property.


4. When you now select a sales order entry using
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection('0500000001'), for example, you can simply add
the navigation link /SalesOrderItems to navigate to the line items without having to set a filter yourself:

5. And finally you can use $expand to read all sales order items for a given sales order in a single http call.
Simply provide the following URI:
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection('0500000001')/?$expand=SalesOrderItems

The $expand statement is handled by the framework (no additional implementation is required). Since the framework
converted by Web2PDFConvert.com

The $expand statement is handled by the framework (no additional implementation is required). Since the framework
does not know that both entities can be obtained using a single RFC call, it executes two calls to the underlying BAPI.
This can be improved by manually implementing (re-defining) the GET_EXPANDED_ENTITY method.
So we are done. The Service is up and running.
I hope you enjoyed creating and consuming an OData Service that is based on RFC modules.

16896 Views
Products: sap_netweaver_gateway Topics: mobile Tags: gateway, odata, netweaver_gateway, service_builder

Average User Rating

My Rating:

(16 ratings)
Share

Like

11 Comments
Wouter Peeters Oct 6, 2013 1:42 PM

Hi Volker,
Thx, these are a great tutorial series to get started with Gateway.
But I'm having some troubles adding a navigation torwards the Product Detail, from the Sales Order
Item entity. Do you have any pointers? Maybe this is a good idea for a part 4.
Regards,
wouter
Like (0)
Volker Drees Oct 8, 2013 10:32 AM (in response to Wouter Peeters)

Hi Wouter,
thanks for the feedback.
Navigating from a Line Item to the related Product is a little trickier. This is because the URI
that you use (e.g. ".../SalesOrderItemCollection( SoItemPos=..., SoID=...)/ToProduct" ) only
has the key information of the Line Item. In order to be able to navigate to the product entry
you first need to read the Line Item detail to fetch the related Product-Id, and from there fetch
the entire product.
Luckily this is taken care of by the Service Builder as well. You just need to make sure to
maintain the Association and the Referential Constraint between the Line Item and the
Product.
hth.
Regards, Volker
Like (1)
Wouter Peeters Oct 8, 2013 12:04 PM (in response to Volker Drees)

Hi Volker,
Thanks for the reply, for more information there's a topic on the matter:
http://scn.sap.com/thread/3434085
Regards,
Wouter
Like (0)
Vijay Dudla May 13, 2014 1:05 PM (in response to Volker Drees)

converted by Web2PDFConvert.com

Hi Volker,
I did the same steps but unable to use the navigation or expand option? what was
the issue.
Below is the metadata for my service.
<?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="ZDEMO09_SRV" xml:lang="en"
xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
- <EntityType Name="Orderheader" sap:content-version="1">
- <Key>
<PropertyRef Name="Vbeln" />
</Key>
<Property Name="Vbeln" Type="Edm.String" Nullable="false" MaxLength="10"
sap:label="Sales Document" sap:sortable="false" sap:filterable="false" />
<Property Name="Erdat" Type="Edm.DateTime" Nullable="false"
sap:label="Created on" sap:creatable="false" sap:updatable="false"
sap:sortable="false" sap:filterable="false" />
<Property Name="Erzet" Type="Edm.Time" Nullable="false" sap:label="Time"
sap:creatable="false" sap:updatable="false" sap:sortable="false"
sap:filterable="false" />
<Property Name="Ernam" Type="Edm.String" Nullable="false" MaxLength="12"
sap:label="Created by" sap:creatable="false" sap:updatable="false"
sap:sortable="false" sap:filterable="false" />
<NavigationProperty Name="OrderItemSet"
Relationship="ZDEMO09_SRV.SalesOrder" FromRole="FromRole_SalesOrder"
ToRole="ToRole_SalesOrder" />
</EntityType>
- <EntityType Name="OrderItem" sap:content-version="1">
- <Key>
<PropertyRef Name="Posnr" />
<PropertyRef Name="Vbeln" />
</Key>
<Property Name="Pstyv" Type="Edm.String" Nullable="false" MaxLength="4"
sap:label="Item category" sap:creatable="false" sap:updatable="false"
sap:sortable="false" sap:filterable="false" />
<Property Name="Matkl" Type="Edm.String" Nullable="false" MaxLength="9"
sap:label="Material Group" sap:creatable="false" sap:updatable="false"
sap:sortable="false" sap:filterable="false" />
<Property Name="Matnr" Type="Edm.String" Nullable="false" MaxLength="18"
sap:label="Material" sap:creatable="false" sap:updatable="false"
sap:sortable="false" sap:filterable="false" />
<Property Name="Posnr" Type="Edm.String" Nullable="false" MaxLength="6"
sap:label="Item" sap:sortable="false" sap:filterable="false" />
<Property Name="Vbeln" Type="Edm.String" Nullable="false" MaxLength="10"
sap:label="Sales Document" sap:sortable="false" sap:filterable="false" />
</EntityType>
- <Association Name="SalesOrder" sap:content-version="1">
<End Type="ZDEMO09_SRV.Orderheader" Multiplicity="1"
Role="FromRole_SalesOrder" />
<End Type="ZDEMO09_SRV.OrderItem" Multiplicity="*"
Role="ToRole_SalesOrder" />
- <ReferentialConstraint>
- <Principal Role="FromRole_SalesOrder">
<PropertyRef Name="Vbeln" />
</Principal>
- <Dependent Role="ToRole_SalesOrder">
<PropertyRef Name="Vbeln" />
</Dependent>
</ReferentialConstraint>
</Association>
- <EntityContainer Name="ZDEMO09_SRV" m:IsDefaultEntityContainer="true">
<EntitySet Name="OrderHeaders" EntityType="ZDEMO09_SRV.Orderheader"
sap:pageable="false" sap:addressable="false" sap:content-version="1" />
<EntitySet Name="OrderItems" EntityType="ZDEMO09_SRV.OrderItem"
sap:pageable="false" sap:addressable="false" sap:content-version="1" />
- <AssociationSet Name="SalesOrderSet"
Association="ZDEMO09_SRV.SalesOrder" sap:creatable="false"
sap:updatable="false" sap:deletable="false" sap:content-version="1">
<End EntitySet="OrderHeaders" Role="FromRole_SalesOrder" />
<End EntitySet="OrderItems" Role="ToRole_SalesOrder" />
</AssociationSet>
</EntityContainer>
<atom:link rel="self"
href="http://sapcis01.citrite.net:8080/sap/opu/odata/sap/ZDEMO09_SRV/$metadata"
xmlns:atom="http://www.w3.org/2005/Atom" />
<atom:link rel="latest-version"
href="http://sapcis01.citrite.net:8080/sap/opu/odata/sap/ZDEMO09_SRV/$metadata"
xmlns:atom="http://www.w3.org/2005/Atom" />
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Thanks
Vijay

converted by Web2PDFConvert.com

Like (0)
Shakeeluddin Khaja Nov 24, 2014 1:47 PM

Very useful info . Thanks Volker


Like (0)
Starlet Abraham Dec 8, 2014 10:52 AM

Hi Volker,
Your Tutorial has been very helpful. I am learning Webservices from scratch.
I have a doubt.
I cant find the ASSOCIATION SETS block in my SEGW Project. Would there be a reason for this?
Thanks
Abraham
Like (0)
Volker Drees Dec 8, 2014 4:25 PM (in response to Starlet Abraham)

Hi Abraham,
I assume you are using a newer version of SAP NetWeaver Gateway (the blog was written
for SP5)?
The Gateway Framework is automatically generating the Association Sets based on the
defined Associations. That's the reason why the Service Builder is not showing them in the
navigation tree anymore. But you can still create own Association Sets if you want (RightClick on Data Model and choose Create -> Association Set).
Best Regards, Volker
Like (0)
Rahul Keshav May 25, 2015 10:28 AM

It worked for me...Thanks Volker......


Like (0)
Amber Badam May 26, 2015 1:55 PM

very illustrative. nice blog. appreciate it.


Like (0)
Kavitha Fredrick Jul 3, 2015 9:32 AM

Very Informative..
Thanks.
Like (0)
Sara Zhang Sep 24, 2015 5:26 AM

Hi Volker,
It is a wonderful doc, I can not tell you how much I appreciate your work, thanks.
Like (0)

Site Index
Privacy

Contact Us
Terms of Use

SAP Help Portal


Legal Disclosure

Copyright

Follow SCN

converted by Web2PDFConvert.com

You might also like