3Step-By-step Guide to Build an OData Service Ba..

7
Getting Started Newsletters Store Products Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Innovation Log On Join Us Hi, Guest Search the Community Activity Communications Actions Browse volker.drees 0 Tweet 1 Thanks for sticking to this multipart stepbystep 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. Doubleclick Associations: 2. Choose the Create pushbutton: 3. Enter the following values for the Association and choose Enter: Name SalesOrderSalesOrderItems 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 doubleclick Referential Constraints: Stepbystep guide to build an OData Service based on RFCs – Part 3 Posted by Volker Drees in volker.drees on 26Oct2012 11:45:07 Share

description

oDATAfIORI

Transcript of 3Step-By-step Guide to Build an OData Service Ba..

  • 16/04/2015 StepbystepguidetobuildanODataServiceba...|SCN

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

    GettingStarted Newsletters Store

    Products Services&Support AboutSCN Downloads

    Industries Training&Education Partnership DeveloperCenter

    LinesofBusiness UniversityAlliances Events&Webinars Innovation

    LogOn JoinUsHi,Guest SearchtheCommunity

    Activity Communications Actions

    Browse

    volker.drees

    0 Tweet 1

    Thanksforstickingtothismultipartstepbystepguide.

    Lookingintothispart(3)meansthatyouhavesuccessfullycompletedthe firstpart(1)andthe secondpart(2)andyouarenowcurioustoseehowourEPMODataServicewillbeextendedwithanAssociationandaNavigationProperty.Thiswillallowus tonavigate from theSalesOrder to the relatedSalesOrderLine Itemsbyusinga linkinsteadofmanuallyputtingafiltertogether.Furthermorethisalsoallowsustousethe$expandstatementtofetchtheSalesOrdertogetherwithallSalesOrderLineItemsinonehttpcall.

    WearestillintheServiceBuilderandenhancingourprojectthatwecreatedinpart1andextendedinpart2.

    1.DoubleclickAssociations:

    2.ChoosetheCreatepushbutton:

    3.EnterthefollowingvaluesfortheAssociationandchooseEnter:Name SalesOrderSalesOrderItems

    PrincipalEntity* SalesOrder

    PrincipalEntityCardinality* 1

    DependentEntity* SalesOrderItem

    DependentEntityCardinality* M

    *)ThisfieldhasaninputhelpNowwewillCreateareferentialconstraintfortheassociation

    1.ExpandtheAssociationsnodeandtheSalesOrderSalesOrderItemsnodeanddoubleclickReferentialConstraints:

    StepbystepguidetobuildanODataServicebasedonRFCsPart3PostedbyVolkerDreesinvolker.dreeson26Oct201211:45:07

    Share

  • 16/04/2015 StepbystepguidetobuildanODataServiceba...|SCN

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

    2.ChoosetheCreatepushbutton:

    3.EnterthefollowingvaluesandchooseEnter:PrincipalKey* SoId

    DependentProperty* SoId

    *)Thisfieldhasaninputhelp

    Nowwecreateanassociationsetfortheassociation

    1.DoubleclickAssociationSets:

    2.ChoosetheCreatepushbutton:

    3.EnterthevaluesandchooseEnter:

  • 16/04/2015 StepbystepguidetobuildanODataServiceba...|SCN

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

    Name SalesOrderSalesOrderItems

    Association* SalesOrderSalesOrderItems

    *)Thisfieldhasaninputhelp

    Andfinallywecreateanavigationpropertybasedonthereferentialconstraint

    1.ExpandDataModel>EntityTypes>SalesOrderanddoubleclickNavigationProperties:

    2.ChoosetheCreatepushbutton:

    3.EnterthefollowingvaluesandchooseEnter:Name SalesOrderItems

    RelationshipName* SalesOrderSalesOrderItems

    *)ThisfieldhasaninputhelpNowweneedtoregeneratetheruntimeobjectsandwerethenreadytotesttheservice

    1.ChoosetheGeneratepushbutton:

    2.Verifythattheruntimeobjectshavebeengeneratedsuccessfully:

  • 16/04/2015 StepbystepguidetobuildanODataServiceba...|SCN

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

    3.StarttheGatewayClient(Transaction/IWFND/GW_CLIENT) inaseparatewindowtoruntheservice.ProvidethefollowingURItogetthemetadatafortheservice:/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 addthenavigationlink/SalesOrderItemstonavigatetothelineitemswithouthavingtosetafilteryourself:

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

  • 16/04/2015 StepbystepguidetobuildanODataServiceba...|SCN

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

    AverageUserRating

    (6ratings)

    MyRating:

    0 Tweet 1

    The$expandstatementishandledbytheframework(noadditionalimplementationisrequired).SincetheframeworkdoesnotknowthatbothentitiescanbeobtainedusingasingleRFCcall,itexecutestwocallstotheunderlyingBAPI.Thiscanbeimprovedbymanuallyimplementing(redefining)theGET_EXPANDED_ENTITYmethod.Sowearedone.TheServiceisupandrunning.

    IhopeyouenjoyedcreatingandconsuminganODataServicethatisbasedonRFCmodules.

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

    Share

    7Comments

    Like(0)

    WouterPeeters06Oct201313:42

    HiVolker,Thx,theseareagreattutorialseriestogetstartedwithGateway.ButI'mhavingsometroublesaddinganavigationtorwardstheProductDetail,fromtheSalesOrderItementity.Doyouhaveanypointers?Maybethisisagoodideaforapart4.Regards,wouter

    VolkerDrees08Oct201310:32(inresponsetoWouterPeeters)

    HiWouter,thanksforthefeedback.NavigatingfromaLineItemtotherelatedProductisalittletrickier.ThisisbecausetheURIthatyouuse(e.g.".../SalesOrderItemCollection(SoItemPos=...,SoID=...)/ToProduct")onlyhasthekeyinformationoftheLineItem.InordertobeabletonavigatetotheproductentryyoufirstneedtoreadtheLineItemdetailtofetchtherelatedProductId,andfromtherefetchtheentireproduct.LuckilythisistakencareofbytheServiceBuilderaswell.YoujustneedtomakesuretomaintaintheAssociationandtheReferentialConstraintbetweentheLineItemandtheProduct.

  • 16/04/2015 StepbystepguidetobuildanODataServiceba...|SCN

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

    Like(1)

    hth.Regards,Volker

    Like(0)

    WouterPeeters08Oct201312:04(inresponsetoVolkerDrees)

    HiVolker,Thanksforthereply,formoreinformationthere'satopiconthematter:

    http://scn.sap.com/thread/3434085Regards,Wouter

    VijayDudla13May201413:05(inresponsetoVolkerDrees)

    HiVolker,Ididthesamestepsbutunabletousethenavigationorexpandoption?whatwastheissue.Belowisthemetadataformyservice.

  • 16/04/2015 StepbystepguidetobuildanODataServiceba...|SCN

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

    FollowSCNSiteIndex ContactUs SAPHelpPortalPrivacy TermsofUse LegalDisclosure Copyright

    Like(0)

    ThanksVijay

    Like(0)

    ShakeeluddinKhaja24Nov201413:47

    Veryusefulinfo.ThanksVolker

    Like(0)

    StarletAbraham08Dec201410:52

    HiVolker,YourTutorialhasbeenveryhelpful.IamlearningWebservicesfromscratch.Ihaveadoubt.IcantfindtheASSOCIATIONSETSblockinmySEGWProject.Wouldtherebeareasonforthis?ThanksAbraham

    Like(0)

    VolkerDrees08Dec201416:25(inresponsetoStarletAbraham)

    HiAbraham,IassumeyouareusinganewerversionofSAPNetWeaverGateway(theblogwaswrittenforSP5)?TheGatewayFrameworkisautomaticallygeneratingtheAssociationSetsbasedonthedefinedAssociations.That'sthereasonwhytheServiceBuilderisnotshowingtheminthenavigationtreeanymore.ButyoucanstillcreateownAssociationSetsifyouwant(RightClickonDataModelandchooseCreate>AssociationSet).BestRegards,Volker