Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
volkerdrees
Product and Topic Expert
Product and Topic Expert

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.


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:

2. Choose the Create pushbutton:

3. Enter the following values for the Association and choose Enter:

NameSalesOrderSalesOrderItems
Principal Entity*SalesOrder
Principal Entity Cardinality*1
Dependent Entity*SalesOrderItem
Dependent Entity Cardinality*M

*) 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:

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:

NameSalesOrderSalesOrderItems
Association*SalesOrderSalesOrderItems

*) This field has an input help

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:

NameSalesOrderItems
Relationship Name*SalesOrderSalesOrderItems

*) This field has an input help

Now we need to re-generate the runtime objects and we’re 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


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 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.

24 Comments
wouter_peeters
Participant
0 Kudos

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

volkerdrees
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

wouter_peeters
Participant
0 Kudos

Hi Volker,

Thanks for the reply, for more information there's a topic on the matter:

http://scn.sap.com/thread/3434085

Regards,

Wouter

former_member188685
Active Contributor
0 Kudos

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" ?>

volker.drees/blog/2012/10/26/\l "" <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">

volker.drees/blog/2012/10/26/\l "" <edmx:DataServices m:DataServiceVersion="2.0">

volker.drees/blog/2012/10/26/\l "" <Schema Namespace="ZDEMO09_SRV" xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">

volker.drees/blog/2012/10/26/\l "" <EntityType Name="Orderheader" sap:content-version="1">

volker.drees/blog/2012/10/26/\l "" <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>

volker.drees/blog/2012/10/26/\l "" <EntityType Name="OrderItem" sap:content-version="1">

volker.drees/blog/2012/10/26/\l "" <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>

volker.drees/blog/2012/10/26/\l "" <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" />

volker.drees/blog/2012/10/26/\l "" <ReferentialConstraint>

volker.drees/blog/2012/10/26/\l "" <Principal Role="FromRole_SalesOrder">

<PropertyRef Name="Vbeln" />

</Principal>

volker.drees/blog/2012/10/26/\l "" <Dependent Role="ToRole_SalesOrder">

<PropertyRef Name="Vbeln" />

</Dependent>

</ReferentialConstraint>

</Association>

volker.drees/blog/2012/10/26/\l "" <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" />

volker.drees/blog/2012/10/26/\l "" <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

former_member188005
Contributor
0 Kudos

Very useful info . Thanks Volker

m4abrams
Participant
0 Kudos

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

volkerdrees
Product and Topic Expert
Product and Topic Expert
0 Kudos

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 (Right-Click on Data Model and choose Create -> Association Set).

Best Regards, Volker

RahulKeshav
Active Contributor
0 Kudos

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

former_member192561
Participant
0 Kudos

very illustrative. nice blog. appreciate it.

Former Member
0 Kudos

Very Informative..

Thanks.

Former Member
0 Kudos

Hi Volker,

It is a wonderful doc, I can not tell you how much I appreciate your work, thanks. :razz:

0 Kudos

Hi Volker,

amazing really valuable. thanks for your time composing this one. 

Best Regards, Alex

former_member196065
Participant
0 Kudos

Hi Volker,

I would like to add few comment to this wonderful blog.

People who are working on higher version of SAP Netweaver Gateway services who can't see the Associate Sets and Navigation folder in Gateway Service Builder Project they can actually follow navigation using following link

Association and Navigation in OData Service - SAP Netweaver Gateway - SAP Fiori,SAP HANA,SAPUI5,SAP ...

This is only for navigation still they need to follow the same naming convention what you used in this document

Uma

former_member196065
Participant
0 Kudos

Hi Volker,

Can you explain what is the difference between

/sap/opu/odata/sap/ZGW100_01_SO_SRV/SalesOrderCollection('500000000')/?expand=SalesOrderItems

and

/sap/opu/odata/sap/ZGW100_01_SO_SRV/SalesOrderCollection('500000000')

I think out put is looking same

what is the use of $expand

Thanks

Uma

volkerdrees
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Uma,

there is a typo in your URI. The '$' is missing. It should look like:


/sap/opu/odata/sap/ZGW100_01_SO_SRV/SalesOrderCollection('500000000')/?$expand=SalesOrderItems


With this you will see a difference.


Best Regards,

Volker

PatrickDean
Participant
0 Kudos

Step by step and succinct: Enough detail so we can't make any mistakes, not so much that we get confused as to what's going on. This is one I shall be showing to others when they need guidance!

Former Member
0 Kudos
Hey volker,

I am new to the Odata services, can you explain in the same way for all the CRUD properties.
That would be very helpful.

Thanks and regards,
Rohan.
Former Member
0 Kudos

hi volker,

very useful blog . Me and one of my friend were following your  blog ,he successfully completed the task using association and navigation.

When i am looking for all data it is ok.

but i am facing unknown problem Can u please help me out.

My mHeaderset is working fine it is giving back the required table entries, but when i am trying to retrieve the specific data it is throwing me 404.

it is not taking my service. what can be the reason for it?

 

0 Kudos
Hi Vijay,

Can you put a break point in entityset method and check if the sales order which you are trying to retrieve has done conversion(CONVERSION_EXIT_ALPHA_INPUT).

 

Srawan.

 
former_member144778
Discoverer
0 Kudos
Hi Volker

Hope you are doing good.As per the below screen the metadata connection is working fine and also completed part 3 .

 



The below step is not working for me when I am trying to fetch fields instead of $metedata I am using SalesOrderCollection.Can you help to support as I need to provide a demo.Or If any case you can provide or number or chat window where we can discuss.

 

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.This portion is not working and I am getting error 404.Can you help to resolve this step.
former_member548272
Participant
0 Kudos
Hi,

Do I need to add coding in the DEEP method as I saw in other blogs?

 

Thanks.
yang_aiolos
Active Participant
0 Kudos
Hi Volker,

your blog is pretty good, hope more in future. Thanks.
former_member540375
Discoverer
0 Kudos
Thansk for this information.

It's very useful.
former_member687301
Discoverer
0 Kudos
Thanks for the complete information