1step-by-step guide to build an odata service ba

Upload: kannan-selvam

Post on 01-Nov-2015

31 views

Category:

Documents


1 download

DESCRIPTION

oDATAfIORI

TRANSCRIPT

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 1/13

    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

    2 Tweet

    HellofellowODataServicedevelopersoutthere.

    WhenitcomestoODataServicedevelopmentwithSAPNetWeaverGatewayavery typicalusecase is tobuildaservicethatisbasedonanRFCmodule(orasetofRFCmodules)e.g.foraList/Detailapplication.ForsuchascenariotherearedozensofRFCmodules(BAPIs)availableintheSAPstandardthatcanbeused.Andofcourseyoucanalsobuildandconsumeyourown(Z)RFCmodulesiftheexistingmodulesdontsatisfyyourneeds...For additional information regarding the Service Builder please also see Thomas Meigens Blog: The new SAPNetWeaverGatewayServiceBuilder:BuildnewODataServicesin3QuickSteps

    InthisStepbystepGuidewewillbuildanODataServicethatconsumestwoRFCmodulesfromtheEPM(EnterpriseProcurementModel)democontent.FromthisEPMdemocontentwepicktwoBAPIsthatretrievethelistanddetailofSalesOrders/LineItems.Thedatamodelisprettysimple.WehaveoneentityfortheSalesOrderheaderdata,andoneentityfortheSalesOrderLineItem.

    ThetwoBAPIsthatwewilluseinourserviceare:BAPI_EPM_SO_GET_LISTandBAPI_EPM_SO_GET_DETAILThisguideisbasedonSAPNetWeaverGateway2.0SP5.WewillbemainlyusingtheSAPNetWeaverGatewayServiceBuilderfortheservicecreation.TheServiceBuilderallowsustobuildourservicewithoutwritingasinglelineofcode(althoughyoustillcandocodingifyouwant).In this firstpart (1)wewillbuildaMetaModelof theservice. In the secondpart(2)wewillperform theserviceimplementation.Soletsgetstarted.1.CreateanewprojectZGW100_XX_SO(SOstandsforSalesOrder).XXisjustaplaceholderforagroupnumberandGW100indicatesthecoursenumberasthescreenshotsweretakenfromtheGW100trainingcoursematerialthatIhavecreated.

    StepbystepguidetobuildanODataServicebasedonRFCsPart1PostedbyVolkerDreesinvolker.dreeson26Oct201211:43:50

    Share 10

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 2/13

    2. Create the first entity by importing an RFC interface. For this rightclick onDataModel and choose Import >RFC/BORInterface

    3.EnterthefollowingvaluesinthewizardandthenchooseNext:EntityTypeName SalesOrder

    TargetSystem Local

    DataSourceType RemoteFunctionCalls

    DataSourceName BAPI_EPM_SO_GET_LIST

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 3/13

    4.ExpandtheSOHEADERDATAnodeandselectthefollowingfields:SO_ID, NOTE, BUYER_ID, BUYER_NAME, CURRENCY_CODE, GROSS_AMOUNT, NET_AMOUNT,TAX_AMOUNTNotethatSOHEADERDATAisnotselected.ChooseNext.

    5.Inthefirstline,SO_ID,selectthefieldIsKeyandchooseFinish:

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 4/13

    6. Create the second entity again by importing an RFC interface. RightclickData Model and choose Import >RFC/BORInterface

    7.EnterthefollowingvaluesinthewizardandchooseNext:EntityTypeName SalesOrderItem

    TargetSystem Local

    DataSourceType RemoteFunctionCalls

    DataSourceName BAPI_EPM_SO_GET_LIST

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 5/13

    8.ExpandtheSOITEMDATAnodeandselectthefollowingfields:SO_ID, SO_ITEM_POS, PRODUCT_ID, NOTE, CURRENCY_CODE, GROSS_AMOUNT, NET_AMOUNT,TAX_AMOUNT,QUANTITY,QUANTITY_UNITNotethatSOITEMDATAisnotselected.ChooseNext.

    9.Inthefirstandsecondline,SO_ID,SO_ITEM_POS,selectthefieldIsKeyandchooseFinish:

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 6/13

    Nowourprojecthas2entitiesonefortheSalesOrderandonefortheSalesOrderLineItem.Asanextstepwecreateentitysetsoutoftheseentities.

    1.ExpandthenodeDataModelanddoubleclickEntitySets:

    2.ClicktheCreatebuttontwicetoaddtwonewlinestothetable:

    3.Enterthefollowingvalues:

    Name EntityTypeName

    SalesOrderCollection SalesOrder

    SalesOrderItemCollection SalesOrderItem

    4.ChooseSave:

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

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

    NowthebasicdefinitionoftheModelisdone.Asanextstepwecangeneratethenecessaryruntimeartifacts.1.ChoosetheGeneratepushbutton:

    2.LeavethedefaultvaluesandchooseEnter:

    PleasenotetheTechnicalServiceNameZGW100_XX_SO_SRVisequaltotheExternalServiceNamerequiredtoconsumethisservicelateron.3.ChooseLocalObject:

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 8/13

    4.Verifythattheruntimeobjectshavebeengeneratedsuccessfully:

    NowwecanRegisterandActivatetheService.1.DoubleclickServiceMaintenance:

    2.SelectsystemZMEandchoosetheRegisterbutton.PleasenotethattheentrieslistedheredependontheSystemAliasconfigurationyouhavedoneintheSAPNetWeaverGatewayImplementationGuide(IMG).Inalocaldeployedenvironment(BackendandHubcomponentsdeployedonthesamebox)youmightalsofindLOCALwiththeRFCdestinationNONEhere.

    3.Confirmthewarningmessagedisplayedinthepopup:

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 9/13

    4.PressF4 toselect thesystemalias.SelectERP_EMEA from the inputhelp.Pleasenote thatyouwontgetanypopupifthereisonly1SystemAliasmaintained.Asmentionedabove,dependingonthedeploymentmethodandIMGconfigurationyoupossiblyseeanaliasLOCALinsteadoftheonesshowninthescreenshot:

    5.ConfirmtheSelectSystemAliaspopup:

    6.Leavethedefaultvaluesandenter$tmpasthepackageandchooseEnter:

    TheExternalServiceNameisdefaultedwiththeTechnicalServiceNamefromtheGenerationStep.7.Verifythattheservicehasbeenregisteredandactivatedsuccessfully:

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

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

    AverageUserRating

    (15ratings)

    MyRating:

    2 Tweet

    Nowwecanrunourservicethefirsttime.Pleasenotethatweveonlymaintainedthebasicmodeldatasofar.Asaconsequencewecanaccessthemetadataoftheservice,butnotyetanybusinessdata(thatwillcomeinpart2).1.Openanewwindow,starttransaction/IWFND/GW_CLIENT.

    2.EnterURI:/sap/opu/odata/sap/ZGW100_XX_SO_SRV/$metadataandchooseExecute:

    ZGW100_XX_SO_SRVistheExternalServiceNamethatwasregisteredbefore.Sowearedoneforthemoment.WehavecreatedaServiceBuilderProjectwithtwoentitiesandtwoentitysets.WehavegeneratedtheruntimeartifactsandregisteredandactivatedourODataservice.In part2wewillmapthedataprovidertobringlifeintoourODataservice.

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

    Share 10

    14Comments

    SyamBabu15Nov201210:56

    HiDrees,NiceBlog.WheniamtryingtocreateprojectthroughSEGWprojectiscreatedsuccessbutinimportmenuoptioniamnotgettingBAPI/RFCInterfacetab.

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 11/13

    Like(0)

    Ref:UsingSP04Thanks,Syam.

    Like(0)

    VolkerDrees15Nov201213:11(inresponsetoSyamBabu)

    HiSyam,thatiscorrect.ThementionedfeaturesareavailableasofGW2.0SP5.BestRegards,Volker

    Like(0)

    SyamBabu15Nov201213:31(inresponsetoVolkerDrees)

    HiDrees,Thanksfortheinformation.

    Like(0)

    MatteoSomensi12May201409:21(inresponsetoVolkerDrees)

    hi,someonecanhelpme?Ifollowedstepbystepyourguide,butitdoesnotwork,theservicewhenIcallSalesOrderCollectionorSalesOrderItemCollectiongivesmeanerrorlikethis:

    Like(0)

    NickArchontis11Jul201320:35

    Thanks!Veryclearandprecise.Nick.

    Like(0)

    PhillipParkinson24Jul201316:36

    Excellentblog,thanksVolker.MaybeworthmentioningtheEPMDataGeneratortransactionissepm_dgforthosethatareusingafreshsystemwithoutdatayet.CheersPhillip

    Like(0)

    AkhilaM04Dec201306:14

    ThankssomuchVolker,Itisreallyhelpful

    ArshadAnsary11Jun201410:23

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

    http://scn.sap.com/people/volker.drees/blog/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1 12/13

    Like(0)

    HiVolker,Thanksfortheblog.ThisisveryhelpfulforbeginnersinGateway.IfollowedyourstepsandIregisteredtheserviceusing/iwfnd/maint_serviceinLOCALserver.1WhilecreatingdatamodelforGatewayservcice,Iamnotabletoselecttheindividaulfieldsw/oselectingtheSOITEMDATAandSOHEADERDATAnodes.2Iamnotabletotesttheservicein/IWFND/GW_CLIENTitsyassomeHTTPerror.ButIcopiedtheURLandpasteitinchromebrowser.IamabletogettheresultbuttheindividualfieldsinEntityisnotshown

    RegardsArshad

    Like(0)

    VolkerDrees13Jun201415:49(inresponsetoArshadAnsary)

    HiArshad,thereasonfornotmarkingSOHEADERDATAwastokeeptheEntityTypenamethatyoudefinedonthefirstpageofthewizard.TheblogwascreatedbasedonGW2.0SP5.NowwithSP8(andSP9comingsoon)thebehaviorofSEGWhaschangedabit.Soit'snotaproblemiftheSOITEMDATAorSOHEADERDATAnodesaremarked.YoujustneedtomakesurethatyougettheexpectedEntityTypenameintheend.AlsotheEntitySetsyoudonotneedtoaddmanuallyanymore.Thisisdoneusingthe"CreateDefaultEntitySet"checkboxautomatically.Asperthe2nderrorit'smoretrickytosaywhatiswrong.Ilearnedthatyoue.g.needtohavethecertificatesgeneratedinSTRUSTSSO2.Buttheremightbemorestepsnecessary.BestRegards,Volker

    Like(0)

    MartinMaruskin14Jan201514:42

    HiVolker,interestingblog!IhaveaquestionwhetherpaginationcanbedonewithinyourexampleBAPIBAPI_EPM_SO_GET_LIST.IseethatwithinthecodeoftheBAPIthepaginationrelatedparameter(IS_PAGING_OPTIONS)ofmethodQUERY_BY_HEADERarenotpassed.SoInotthinkitissupportedbutmaybeyoufoundawayforthis...IncaseyouagreewithmethatnopaginationsupportedbytheabovementionedBAPI...AreyouawareofanyotherstandardSAPBAPIwhichsupportspaginationfunctionalitywithintheresultset?thanksm./

    Like(1)

    VolkerDrees14Jan201516:04(inresponsetoMartinMaruskin)

    HelloMartin,theBAPIBAPI_EPM_SO_GET_LISTunfortunatelydoesnotexposetheparameterIS_PAGING_OPTIONS.ThereforeitisnotpossbiletouseitwhencallingtheBAPI.InthegeneratedDPCmethod(...GET_ENTITYSET)thepagingishandledoutofthebox.ButthisisdoneinagenericwayaftertheBAPIhasprovidedthefulllist.YoucanadjustthegeneratedcodingtofilltheMAX_ROWSparameterbasedonthepagingrequest.ThatcanimprovetheperformancewhencallingtheBAPI.I'mnotawareofanystandardBAPIthatsupportsfullpaging.IfyouhaveaccesstoaNW7.40systemwithSAP_GWFNDSP8installedyoucancheckmysampleservice(/sap/opu/odata/IWBEP/GWSAMPLE_BASIC)whichimplementsthepagingbyperformingadirectdatabaseaccess(SELECT).BestRegards,Volker

    MartinMaruskin14Jan201519:52(inresponsetoVolkerDrees)

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

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

    FollowSCNSiteIndex ContactUs SAPHelpPortalPrivacy TermsofUse LegalDisclosure Copyright

    Like(0)

    Thanksforclarifyingthis,muchappreciated!

    Like(0)

    ArshadAnsary23Jan201505:07(inresponsetoVolkerDrees)

    HiVolker,IaminSP10andIamnotabletofindyoursampleserviceGWSAMPLE_BASICin/IWFND/MAINT_SERVICE.Canyoupostthecodeofpaginationhandlinginselectifwecanlimittherecordsattheselectitself(insteadofattheDPCclasses),wecanhugelyimprovetheperformance.Moreoverhowthepaginationshouldworkalongwithsortisalsoaquestion.Becauseideallysortshouldhappenfirstandthentopskippaginationshouldhappennext.InourprojectwearecurrentlygettingallrecordsfromDBandthendoingsortingandpaginationafterthatwhichisaffectingperfomanceRegardsArshad

    Like(0)

    VolkerDrees23Jan201517:22(inresponsetoArshadAnsary)

    HiArshad,Iassumeyouareon7.40?Haveyoutriedtouse"AddService"toaddtheGWSAMPLE_BASICserviceifitisnotyetpresentinthelistofregisteredservices?AsperthepaginationinaSELECTstatement,youcanonlyusethe"uptoxrows"statementtoreducethenumberofitemstoberead.Asaconsequencetheefficiencyishigherifyouarebrowsingthefirstpagesofyourentityset.InmyexampleIfirstpreparesomehelpervaraibles(alloftypei):lv_top=io_tech_request_context>get_top().lv_skip=io_tech_request_context>get_skip().IF(lv_top>0).lv_maxrows=lv_top+lv_skip.ENDIF.AndintheSELECTstatementIusethelv_maxrowsvariabletolimitthenumberofrecordstoberead.sydbcnthelpsmetoskiptherecordsatthebeginning(thoughtheystillneedtobereadfromtheDB).SortingandfilteringtakesplacealongwiththeSELECTstatement.SELECTINTO()FROM()UPTOlv_maxrowsROWSWHERE(lv_where_clause)ORDERBY(lv_orderby_clause).IF(sydbcnt>lv_skip).APPENDls_entityTOet_entityset.ENDIF.ENDSELECT.hthBestRegards,Volker