Anda di halaman 1dari 7

16/04/2015

StepbystepguidetobuildanODataServiceba...|SCN

GettingStarted Newsletters

Hi,Guest

LogOn

JoinUs

Store

SearchtheCommunity

Products

Services&Support

AboutSCN

Downloads

Industries

Training&Education

Partnership

DeveloperCenter

Activity

LinesofBusiness

UniversityAlliances

Events&Webinars

Innovation

Browse

Communications

Actions

volker.drees

StepbystepguidetobuildanODataServicebased
onRFCsPart3
PostedbyVolkerDreesinvolker.dreeson26Oct201211:45:07
Share

Tweet

Thanksforstickingtothismultipartstepbystepguide.
Lookingintothispart(3)meansthatyouhavesuccessfullycompletedthe firstpart(1)andthe secondpart(2)
andyouarenowcurioustoseehowourEPMODataServicewillbeextendedwithanAssociationandaNavigation
Property. This will allow us to navigate from the Sales Order to the related Sales Order Line Items by using a link
insteadofmanuallyputtingafiltertogether.Furthermorethisalsoallowsustousethe$expandstatementtofetchthe
SalesOrdertogetherwithallSalesOrderLineItemsinonehttpcall.
WearestillintheServiceBuilderandenhancingourprojectthatwecreatedinpart1andextendedinpart2.
1.DoubleclickAssociations:

2.ChoosetheCreatepushbutton:

3.EnterthefollowingvaluesfortheAssociationandchooseEnter:

Name
SalesOrderSalesOrderItems
PrincipalEntity*

SalesOrder

PrincipalEntityCardinality*

DependentEntity*

SalesOrderItem

DependentEntityCardinality*

*)Thisfieldhasaninputhelp

NowwewillCreateareferentialconstraintfortheassociation
1.ExpandtheAssociationsnodeandtheSalesOrderSalesOrderItemsnodeanddoubleclickReferentialConstraints:

http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart3

1/7

16/04/2015

StepbystepguidetobuildanODataServiceba...|SCN

2.ChoosetheCreatepushbutton:

3.EnterthefollowingvaluesandchooseEnter:

PrincipalKey*

SoId

DependentProperty*

SoId

*)Thisfieldhasaninputhelp

Nowwecreateanassociationsetfortheassociation
1.DoubleclickAssociationSets:

2.ChoosetheCreatepushbutton:

3.EnterthevaluesandchooseEnter:

http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart3

2/7

16/04/2015

StepbystepguidetobuildanODataServiceba...|SCN

Name

SalesOrderSalesOrderItems

Association*

SalesOrderSalesOrderItems

*)Thisfieldhasaninputhelp

Andfinallywecreateanavigationpropertybasedonthereferentialconstraint
1.ExpandDataModel>EntityTypes>SalesOrderanddoubleclickNavigationProperties:

2.ChoosetheCreatepushbutton:

3.EnterthefollowingvaluesandchooseEnter:

Name

SalesOrderItems

RelationshipName*

SalesOrderSalesOrderItems

*)Thisfieldhasaninputhelp

Nowweneedtoregeneratetheruntimeobjectsandwerethenreadytotesttheservice
1.ChoosetheGeneratepushbutton:

2.Verifythattheruntimeobjectshavebeengeneratedsuccessfully:

http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart3

3/7

16/04/2015

StepbystepguidetobuildanODataServiceba...|SCN

3.StarttheGatewayClient(Transaction/IWFND/GW_CLIENT)inaseparatewindowtoruntheservice.Providethe
followingURItogetthemetadatafortheservice:
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/$metadata

TheSalesOrdercollectionnowincludesanavigationproperty.

4.Whenyounowselectasalesorderentryusing
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection('0500000001'), for example, you can simply add
thenavigationlink/SalesOrderItemstonavigatetothelineitemswithouthavingtosetafilteryourself:

5.Andfinallyyoucanuse$expandtoreadallsalesorderitemsforagivensalesorderinasinglehttpcall.
SimplyprovidethefollowingURI:
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection('0500000001')/?$expand=SalesOrderItems

http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart3

4/7

16/04/2015

StepbystepguidetobuildanODataServiceba...|SCN

The$expandstatementishandledbytheframework(noadditionalimplementationisrequired).Sincetheframework
doesnotknowthatbothentitiescanbeobtainedusingasingleRFCcall,itexecutestwocallstotheunderlyingBAPI.
Thiscanbeimprovedbymanuallyimplementing(redefining)theGET_EXPANDED_ENTITYmethod.

Sowearedone.TheServiceisupandrunning.
IhopeyouenjoyedcreatingandconsuminganODataServicethatisbasedonRFCmodules.

11050Views

Products:sap_netweaver_gatewayTopics:mobileTags:gateway,odata,netweaver_gateway,service_builder

AverageUserRating

MyRating:

(6ratings)

Share

Tweet

7Comments
WouterPeeters06Oct201313:42

HiVolker,

Thx,theseareagreattutorialseriestogetstartedwithGateway.

ButI'mhavingsometroublesaddinganavigationtorwardstheProductDetail,fromtheSalesOrder
Itementity.Doyouhaveanypointers?Maybethisisagoodideaforapart4.

Regards,
wouter
Like(0)

VolkerDrees08Oct201310:32(inresponsetoWouterPeeters)

HiWouter,
thanksforthefeedback.

NavigatingfromaLineItemtotherelatedProductisalittletrickier.ThisisbecausetheURI
thatyouuse(e.g.".../SalesOrderItemCollection(SoItemPos=...,SoID=...)/ToProduct")only
hasthekeyinformationoftheLineItem.Inordertobeabletonavigatetotheproductentry
youfirstneedtoreadtheLineItemdetailtofetchtherelatedProductId,andfromtherefetch
theentireproduct.
LuckilythisistakencareofbytheServiceBuilderaswell.Youjustneedtomakesureto
maintaintheAssociationandtheReferentialConstraintbetweentheLineItemandthe
Product.

http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart3

5/7

16/04/2015

StepbystepguidetobuildanODataServiceba...|SCN

hth.
Regards,Volker
Like(1)

WouterPeeters08Oct201312:04(inresponsetoVolkerDrees)

HiVolker,

Thanksforthereply,formoreinformationthere'satopiconthematter:
http://scn.sap.com/thread/3434085

Regards,
Wouter
Like(0)

VijayDudla13May201413:05(inresponsetoVolkerDrees)

HiVolker,

Ididthesamestepsbutunabletousethenavigationorexpandoption?whatwas
theissue.

Belowisthemetadataformyservice.

<?xmlversion="1.0"encoding="utf8"?>
<edmx:EdmxVersion="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:DataServicesm:DataServiceVersion="2.0">
<SchemaNamespace="ZDEMO09_SRV"xml:lang="en"
xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityTypeName="Orderheader"sap:contentversion="1">
<Key>
<PropertyRefName="Vbeln"/>
</Key>
<PropertyName="Vbeln"Type="Edm.String"Nullable="false"MaxLength="10"
sap:label="SalesDocument"sap:sortable="false"sap:filterable="false"/>
<PropertyName="Erdat"Type="Edm.DateTime"Nullable="false"
sap:label="Createdon"sap:creatable="false"sap:updatable="false"
sap:sortable="false"sap:filterable="false"/>
<PropertyName="Erzet"Type="Edm.Time"Nullable="false"sap:label="Time"
sap:creatable="false"sap:updatable="false"sap:sortable="false"
sap:filterable="false"/>
<PropertyName="Ernam"Type="Edm.String"Nullable="false"MaxLength="12"
sap:label="Createdby"sap:creatable="false"sap:updatable="false"
sap:sortable="false"sap:filterable="false"/>
<NavigationPropertyName="OrderItemSet"
Relationship="ZDEMO09_SRV.SalesOrder"FromRole="FromRole_SalesOrder"
ToRole="ToRole_SalesOrder"/>
</EntityType>
<EntityTypeName="OrderItem"sap:contentversion="1">
<Key>
<PropertyRefName="Posnr"/>
<PropertyRefName="Vbeln"/>
</Key>
<PropertyName="Pstyv"Type="Edm.String"Nullable="false"MaxLength="4"
sap:label="Itemcategory"sap:creatable="false"sap:updatable="false"
sap:sortable="false"sap:filterable="false"/>
<PropertyName="Matkl"Type="Edm.String"Nullable="false"MaxLength="9"
sap:label="MaterialGroup"sap:creatable="false"sap:updatable="false"
sap:sortable="false"sap:filterable="false"/>
<PropertyName="Matnr"Type="Edm.String"Nullable="false"MaxLength="18"
sap:label="Material"sap:creatable="false"sap:updatable="false"
sap:sortable="false"sap:filterable="false"/>
<PropertyName="Posnr"Type="Edm.String"Nullable="false"MaxLength="6"
sap:label="Item"sap:sortable="false"sap:filterable="false"/>
<PropertyName="Vbeln"Type="Edm.String"Nullable="false"MaxLength="10"
sap:label="SalesDocument"sap:sortable="false"sap:filterable="false"/>
</EntityType>
<AssociationName="SalesOrder"sap:contentversion="1">
<EndType="ZDEMO09_SRV.Orderheader"Multiplicity="1"
Role="FromRole_SalesOrder"/>
<EndType="ZDEMO09_SRV.OrderItem"Multiplicity="*"
Role="ToRole_SalesOrder"/>
<ReferentialConstraint>
<PrincipalRole="FromRole_SalesOrder">
<PropertyRefName="Vbeln"/>
</Principal>
<DependentRole="ToRole_SalesOrder">
<PropertyRefName="Vbeln"/>
</Dependent>
</ReferentialConstraint>
</Association>

http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart3

6/7

16/04/2015

StepbystepguidetobuildanODataServiceba...|SCN
<EntityContainerName="ZDEMO09_SRV"m:IsDefaultEntityContainer="true">
<EntitySetName="OrderHeaders"EntityType="ZDEMO09_SRV.Orderheader"
sap:pageable="false"sap:addressable="false"sap:contentversion="1"/>
<EntitySetName="OrderItems"EntityType="ZDEMO09_SRV.OrderItem"
sap:pageable="false"sap:addressable="false"sap:contentversion="1"/>
<AssociationSetName="SalesOrderSet"
Association="ZDEMO09_SRV.SalesOrder"sap:creatable="false"
sap:updatable="false"sap:deletable="false"sap:contentversion="1">
<EndEntitySet="OrderHeaders"Role="FromRole_SalesOrder"/>
<EndEntitySet="OrderItems"Role="ToRole_SalesOrder"/>
</AssociationSet>
</EntityContainer>
<atom:linkrel="self"
href="http://sapcis01.citrite.net:8080/sap/opu/odata/sap/ZDEMO09_SRV/$metadata
xmlns:atom="http://www.w3.org/2005/Atom"/>
<atom:linkrel="latestversion"
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
Like(0)

ShakeeluddinKhaja24Nov201413:47

Veryusefulinfo.ThanksVolker
Like(0)

StarletAbraham08Dec201410:52

HiVolker,

YourTutorialhasbeenveryhelpful.IamlearningWebservicesfromscratch.
Ihaveadoubt.

IcantfindtheASSOCIATIONSETSblockinmySEGWProject.Wouldtherebeareasonforthis?

Thanks
Abraham
Like(0)

VolkerDrees08Dec201416:25(inresponsetoStarletAbraham)

HiAbraham,
IassumeyouareusinganewerversionofSAPNetWeaverGateway(theblogwaswritten
forSP5)?
TheGatewayFrameworkisautomaticallygeneratingtheAssociationSetsbasedonthe
definedAssociations.That'sthereasonwhytheServiceBuilderisnotshowingtheminthe
navigationtreeanymore.ButyoucanstillcreateownAssociationSetsifyouwant(Right
ClickonDataModelandchooseCreate>AssociationSet).

BestRegards,Volker
Like(0)

SiteIndex
Privacy

ContactUs
TermsofUse

SAPHelpPortal
LegalDisclosure

Copyright

http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart3

FollowSCN

7/7

Anda mungkin juga menyukai