handling of applications with the brf+ api (part-1)
DESCRIPTION
Handling of Applications with the BRF+ API (Part-1)TRANSCRIPT
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 1/11
GettingStarted Newsletters Store
Products Services&Support AboutSCN Downloads
Industries Training&Education Partnership DeveloperCenter
LinesofBusiness UniversityAlliances Events&Webinars Innovation
1pointsHi,Jayakrishna LogOut SearchtheCommunity
Activity Communications Actions
Browse Create
SAPBusinessRulesManagement
0 Tweet 9
IntroductionManyquestionsanddescriptionshereinSCNfocusontheusageoftheBRF+viatheworkbenchasinterfaceforthecreationandmaintenanceofobjectsoftheBRF+.ButthereisalsoanotherwaytogetthesethingsdonenamelytheBRF+API.ThisblogshallintroduceyouintosomebasicusagescenariosoftheAPI.AcomprehensivedescriptionoftheAPIcanbefoundinthebook BRFplusTheBookof
CarstenZieglerand ThomasAlbrecht.Thefirstquestionthatmightariseuptonowis:WhyshouldIuseanAPIifIhavethecomfortoftheBRF+workbenchwithitsquiteusableWebdynproUI?Theansweris:TherearescenarioswheretheBRF+workbenchcannotbeusedforthemaintenance.OneexampleisthemaintenanceoftherulesontheproductiveenvironmentwhenDSMisnotinplace,IncaseyouareusingBRF+applicationsofstoragetypeSorCyoursystemsettingswillusuallypreventtheirmaintenanceontheproductivesystem.Thereisaworkaroundbyusinganapplicationexitbutthenyoureallyhavetotakecareonthesynchronizationprocessbetweenthedevelopmentandtheproductivesystemasthoseapplicationsarestillpartoftheregulartransportprocess.Thiscangetquitetrickyandisnotthebestwaytogo.NowyoumightsaythatamasterdataapplicationmightsolvetheissuebutthatoneisnotintendedtobetransportedexceptfortheXMLexportandimportfunctionalitywhichmightnotbethepreferredwayofyourIToperationsteam.SothismightberighttimetoswitchtoagenerativeapproachusingtheBRF+API.Thisapproachmightalsobeoffavorwhenyouwantto(deeply)integrateanartefactoftheBRF+(e.g.adecisiontable)intoanexistingapplicationsothattheuserisnotevenawareofusingtheBRF+butontheotherhandstillbeingabletouseallthenicefeaturesoftheartefact.BeforethestorygetsalittlebittootheoreticalIwanttointroduceabusinessscenariowherethisapproachcanbeused.TheBusinessScenarioAsmybackgroundisthefieldofinsurancesoismyscenario:LetusassumewehaveaSAPmodule(likeSAPPolicyManagement)thatallowsyoutomanagemasterpoliciesmorespecificthefleetmasterpolicies.Withinthesemasterpoliciestheinsurerandtheinsuredcompanyagreeontheinsuranceofthecompanycars.Usuallytheinsuredcompanypaysacertainpremiumpercarandthebasisforthepremiumcalculationiswrittendowninthemasterpolicy.Thisbasisdependsoncertainpropertiesofthecarstobeinsured.Letususethefollowingverysimplifiedexampleforsuchatable:
Weightofcarintons PerformanceofthecarinkW PremiumamountinEUR
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 2/11
EnhancetheUIofthepolicymanagementapplicationinordertoallowtheusertodisplayandeditthedatainthedecisiontable.ForthistopicIwanttorefertothecorrespondingdocumentavailablehereinSCN:
http://scn.sap.com/docs/DOC4578
Implementafunctionalityinthesystemthatcreatesadecisiontable(includingits"surroundings"likeapplication,functionetc.)inbackgroundforeachmasterpolicyandmakeitavailablefortheUI.Thistaskalsocontainsthecreationofthefunctionalitytomaintainthedatainthedecisiontable(plusthenicefeatureslikecheckforoverlaps).Thisisthepartthattheblogfocusesoninthesubsequentsections.
DisclaimerBeforestartingwiththetechnicaldetailsjustashortdisclaimer:theusageoftheAPIforthemaintenanceoftheBRF+objectsissomequiteadvancedtopicsoifyoudecidetouseityoushouldknowwhatyouaredoing(whichisinmostcasesaquitegoodapproach ).Especiallywhenyouareintegratingthefunctionalityintoanexistingapplicationyouhavetobecarefule.g.aboutthecommithandling,thetransactionhandlingetc.oftheapplicationandtheBRF+APIandtheinterplaybetweenthem.Alsointensivetestingoftheintegratedcomponentsplaysanimportantrole.Inadditionthecodingsnippetsshownbelowdonothaveasophisticatederrorhandlingsoforarealusagesomeadoptionshavetobemade.Butnowenoughforthatpartandletusstartwiththerealstuff...thecodingwiththeBRF+API!SolutionInordertomakethedecisiontableavailablefortheenhancedUIofthemasterpolicymanagementwewillimplementahandlerclassZCL_BRFPLUSAPI_FLEETforthesingleoperationsthathavetobetriggeredviatheBRF+API.Thismeansthatasaroughguidewehavethefollowingmethodsforthe:
creationoftheBRF+applicationwithafunction(infunctionalmode)andadecisiontableassignedtothefunctionreadthedecisiontabledata
insertandupdatedatainthedecisiontabledeletethecompleteapplicationservicefunctionalitieslikecheckforgapsoroverlapsinthedecisiontableprocessingofthedecisiontable
AsthestructureforthedecisiontableisconstantthereisnoneedtocreatethesingledataobjectsofthecolumnswheneveranewdecisiontableiscreatedsoasaprerequisitewehaveanadditionalBRF+applicationofstoragetypeSthatholdsthecorrespondingdataobjectsfortheweight,theperformanceandthepremiumamountasreusabledataobjects.CreatingthedecisiontableInordertocreatethedecisiontablewefirsthavetocreateaBRF+application.Wewilluseanapplicationoftypemasterdatafortheexampleasthisistheobviousstorage.Forthetaskwedesignonemethodthatcreatestheapplicationincludingitssubobjectsandreturnsareferencetoit:
WithinthatmethodwefirstfetchareferencetotheBRF+factorywhichisthecentralpointwhencreatingBRF+objects:
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 3/11
Asalreadyshownwethendelegatetoamethodthatcreatestheapplicationwithitsbasicfeaturesandreturnsthereferencetoit.Themethodcontainsthefollowinglogic(thenumbersrefertothehighlightedsectionsinthefollowingscreenshot):
1. WecallGET_APPLICATIONontheBRF+factoryandgetbackareferencetoanemptyapplicationobject.NextweenqueuetheapplicationobjectitselfbyusingthecorrespondingmethodoftheinterfaceIF_FDT_TRANSACTION.
2.Afterthatwesetthebasicparameterslikeapplicationcomponentandsoonusingthemethodsthatareavailableontheapplicationobject.ForeveryfieldthatyoucanseeontheBRF+workbenchonemethodisavailableintheapplicationAPI.
3.AfterthatwecallaspecificAPImethodthatcreatesthemasterdataapplicationbasedonthepropertieswesetintotheobject.Therearealsomethodsfortheothertypesofapplicationslikecustomizingapplications.
4.AswehavenowfinishedtheapplicationspecificactionsweactivatetheapplicationviathemethodIF_FDT_TRANSACTION~ACTIVATE.Dependingonthesuccessorfailurewesaveanddequeuetheapplicationorjustdequeueit.IncaseofasuccesstheapplicationisnowavailableintheBRF+workbench.
Someremarksonthisfirsttask:
TheAPIalsoallowsadeepactivationandsavingofobjects(meaningthatyoutriggerthesavinge.g.onapplicationlevelandallsubsequentobjectsaresavedtoo).Thisalternativewillbeshowninthefollowingscreenshots.ThenamingoftheapplicationwasdeterminedusingtheclassCL_FDT_SERVICES.ThisclassoffersmethodsthatcreateGUIDsforyournameseitherwithorwithoutaspecificnamespaceandwascalledinthemethodGET_UNIQUE_NAMEinthescreenshotabove.MostoftheBRF+APImethodsthrowtheexceptionCX_FDT_INPUT.Youshouldalwayscatchandhandleit
Nowletusgobacktothemainmethodforthecreationoperation.Nextwewanttocreatethedecisiontableinordertohaveitinplacewhenwecreatethefunctionandassignitastoplevelexpression.Butbeforewecandosoweneedtogetaccesstothedataobjectsusedinthedecisiontablei.e.theirreferencesthatwehavestoredintheSapplicationforreuse:
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 4/11
WithinthismethodweonceagainusetheBRF+factorytofetchthereferencestotheseobjects:
IfyouknowtheIDsofthedataelements(thatIstoredasconstantsinaninterface)thereferenceisjustonecallofGET_DATA_OBJECTaway.Havingthesereferenceswehaveaccesstoalltheattributesofthedataobjectse.g.theirtype.HavingtheBRF+factorytheapplicationobjectandthereferencestothedataobjectsthatbuildthecolumnsofthedecisiontablewecannowgoonandcreatethedecisiontableviaanotherprivatemethod:
Thecreationofadecisiontableisroughlyspeakingthesameasthecreationofanapplicationwiththefollowingsteps(thenumbersrefertothehighlightedsectionsinthefollowingscreenshot):
1. Creationadecisiontableobjectviathefactory,enqueuingitandsettingthebasicproperties.EachattributethatcanbesetisrepresentedbyamethodofthedecisiontableAPI.
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 5/11
2. Fillingofthedecisiontablecolumnsandsettingtheirproperties(e.g.isitaconditionoraresultcolumn)3. Settingthecorrespondingobjectstothedecisiontableobject
4. InadditionwealsostoredtheobjectIDsofthecontextobjectsthatwillbeusedinthenexttaskwhencreatingthefunction
Asyoucanseewedidnotyetactivateandsavetheobject.Nowwehavethereferencestotheapplicationobject,the(empty)decisiontableobjectandthedataobjects.Wecanthereforefinishthecreationoperationbycreatingafunctionandactivatingthefunctionanditssubobjects:
Thismethodencapsulatesthefollowingsteps(thenumbersrefertothehighlightedsectionsinthefollowingscreenshot):
1. First,asusual,wecreateareferencetoafunctionobjectviatheBRF+factory.Afterenqueuingitweassignittoanapplicationandusethemethodsoftheobjecttosetthebasicattributesofafunctionobjectlikethenameandversioning.Lastbutnotleastwesetthemodeofthefunctionto"functionalmode".AswitheveryBRF+APItheobjectreferencehasmethodsforeachattributethatcanbeset.
2. Nextweassignthecontextandresultdataobjectsaswellastheexpressiontothefunction.RememberthatwefetchedtheobjectIDsofthecontextparameterswhenweconstructedtheconditioncolumnsofourdecisiontable
3. Asthirdstepweactivatethefunction.ThistimewesettheoptionalparameterIV_DEEPtoABAP_TRUEwhichleadstoanactivationofthefunctionanditsinactivesubobjects(inourcasethedecisiontable)
4. Lastbutnotleastwesaveanddequeuethefunctionincaseofasuccessfulactivation.OnceagainweusetheIV_DEEPparameterofthemethodstopropagatetheaction.
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 6/11
That'sitexecutingthecreatemethodCREATE_MASTERDATA_APPLICATIONofthehandlerclassZCL_BRFPLUSAPI_FLEETwillnowcreateanapplicationwithfunctionandemptydecisiontablefromscratch.ThemethodreturnsthereferencetotheapplicationobjectsowecanforexamplestoretheGUIDoftheapplication(storedinthepublicattributeMV_IDofthereferencetotheapplication)inourmasterpolicyinordertobeabletoretrievetheapplicationanditssubobjectsatalaterpointintime.Thekeytakeawaysofthisfirstsectionare:
EveryBRF+objecthasanAPIthatcanbeusedtocreateandmaintainit.InordertogetanobjectreferencetooneoftheAPIsweneedtheBRF+factoryclassCL_FDT_FACTORY.SomeglobalBRF+servicefunctionalitiesareimplementedintheclassCL_FDT_SERVICES
SettingandGettingtheDataAfterthesuccessfulcreationofthedecisiontablewewanttooffermethodsinourhandlerclassinordertoreadtheentriesofthedecisiontableaswellastosetdataintothedecisiontable.AsastartingpointletusassumethatthatwehavetheGUIDoftheapplicationandhavetoretrievethereferencetodecisiontableviathatGUID.SowehavetoimplementamethodthatfetchesthereferencestotheobjectsthatbelongtotheapplicationspecifiedviatheGUID:
Thecontentofthemethodconsistsoftwomajorpartsnamelythefetchingofthefunctionobjectandthenthefetchingofthedecisiontableobject.Forthefunctionobjectthefollowingstepsareperformed(thenumbersrefertothehighlightedsectionsinthefollowingscreenshot):
1. FirstwegetareferencetothequeryobjectoftheBRF+specificforfunctions.AsfortheBRF+APIaqueryobjectforeachartefactexists
2. ThenweconstructtheselectionparametersinourcasetheparametersoftheapplicationidentifiedbyitsIDandspecifythatwearelookingforamasterdataobject
3. AfterthatwefirethequeryandgettheIDofthefunctionasaresult.4. AsalaststepweuseanotherimportantmethodoftheBRF+factorynamelythemethod
GET_INSTANCE_GENERICthatreturnsusareferencetothefunctionobjectthatwehavetocasttothefunctionspecificinterface.
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 7/11
Aswehavea1:1relationshipbetweenthefunctionandthedecisiontablewecandirectlyfetchthereferencetothedecisiontablebyusingthemethodGET_EXPRESSIONofthefunctionAPIthatreturnstheIDofthedecisiontableobject:
Aftercastingtotherightinterfacewehavethereferencetothedecisiontablethatwecanuseforgettingandsettingthedata.SoweenhancethehandlerclassZCL_BRFPLUSAPI_FLEETwithtwoadditionalmethodsforthegettingandsettingofdatafrom/intothedecisiontableobject:
TheimplementationoftheGETmethodisstraightforwardaswecallthecorrespondingGETmethodofthedecisiontableAPI:
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 8/11
TheSETmethodisnearlyasstraightforwardastheGETmethodsowecalltheSETmethodoftheAPIbutaswemakeachangetothetablewehavetoenqueue/dequeueaswellasactivateandsavetheobjectinanalogytothecaseofitsinitialcreation:
Asyoucanseethesettingandgettingofthedataitselfisnotdifficultbutitiscertainlyalsoofinterestwhatthetabledatahastolooklikeinordertobeabletocallthesetwomethods.Thefollowingcodingsnippetgivesyousomeinsighthowthiscanbeachieved:Firstwecreateareferencetoourhandlerclassandfetchthereferencetothedecisiontableobject(theapplicationIDisaparameterofthereport).SecondwefetchthetypenamesofthesinglecolumnsusingtheBRF+factoryasshowninthescreenshotsbelow
Thenwefillthetableparameterswiththevaluesfortheconditioncolumnswherewespecifythetablecolumnandrowtheoperatorsforthecomparisonandtheconcretevalue:
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 9/11
Afterthatwefilltheresultcolumnwhichismorestraightforwardduetothedirectassignmentoftheresultvaluewithoutoptionsforcomparisons:
Thiswaywehavetofillthetablelinebylineandfinallysetitintoourdecisiontableusingthehandlerclass:
Thekeytakeawaysofthissecondsectionare:HavingtheIDofanBRF+objectenablesyoutosearchforotherBRF+objectsusingthequeryfunctionality(IF_FDT_QUERY)availableviatheBRF+factory.YoucaneitherinstantiateaBRF+objectviathecorrespondingmethodfortheobjectonthefactoryoryouusethestaticgenericmethodGET_INSTANCE_GENERICofthefactory.EveryAPIhasmethodstosetandgetthedataandpropertiesstoredintheobject.Theconcreteparametersdependonthespecificobjecttype.
SummaryandOutlookWithinthisblogascenariowaspresentedwhichisanexamplefortheusageoftheBRF+APItocreateandmaintainBRF+objects.Wecreatedanapplication,afunctionandanemptydecisiontableinstoragetype"masterdata".ThenwedeterminedthewayshowtofetchthereferencetothecreatedobjectsviatheIDoftheBRF+applicationandhowtoset/getdatato/fromthedecisiontableobject.
AsthereareseveralmorefunctionalitiesthatyoucanaddressviatheBRF+APIthatmightbeofinterestandarelistedinthefunctionlistofthehandleraboveafurtherblogisavailablethatdescribese.g.theAPItocheckforgapsandoverlapsinthedecisiontable: HandlingofApplicationswiththeBRF+API(Part2)
1471Views
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 10/11
AverageUserRating
(5ratings)
MyRating:
0 Tweet 9
Products:sap_netweaver_business_rules_managementTopics:business_rules_managementTags:sap_business_rules,brfplus,brf+
Share 1 1Like
8Comments
Like(1)
WolfgangSchaperOct23,20143:52PM
IjustwanttopointoutthattheBRFplusbookwascoauthoredbyCarstenZieglerandThomasAlbrecht.EspeciallyThomaswrotethechapterontheAPI.Soweshouldnotforgettomentionhimhere.
Like(1)
ChristianLechnerOct23,20145:18PM(inresponsetoWolfgangSchaper)
ThanksWolfgangforthecorrectiveadviceonthat.Icorrectedthecorrespondingsentence.
Like(0)
PrasadChouguleMar21,20159:30PM
HiChris,Thanksforthisblog.Pleasecanyouhelpmetounderstandthecorrectapproachonbelowreuirements.iwanttomaintaincertaincombinationofIFconditioninBRF+ApplicationwhichwillbecalleddynamicallyinABAP.eg.IFL_BUKRS='XYZ'andL_BSART='ABC'.currentlyinmyreportiwanttocheckthistwovariablesconditionbutgoingfwdifiwanttocheckthirdvariablesL_VKORG='DEF'insameIFcondition.theniwillnotchangemyABAPcodeitshouldbehandlethorughourBRF+application.AnyHelponthiswillbeAppreciated.
Like(0)
ChristianLechnerMar22,20157:03AM(inresponsetoPrasadChougule)
HiPrasad,IamnotquitesureifIunderstandyoucorrectly:youwanttohaveone"generic"pieceofABAPthatmainlymodelsanIFconditionwiththesingleconditionslinkedbyanAND.Ihaveseveralquestionsonthat:
BRChristians
Wheredoestheinformationconcerningthecontextparametersthatshallbeusedcomefrom?Wheredothevaluesthatyouwanttocompareagainstcomefrom?WhatistheELSE(IF)cases(s)?
Like(0)
PrasadChouguleMar23,20158:06PM(inresponsetoChristianLechner)
HiChris,ManyThanksforquickreply,inthisapplicationihavecreatedonedecisiontablewhereiwillmaintainfieldandvalueswhichwillbecalledinABAPforcheckingthecondiitons.andalsochriscanyouhelpmetomaintaintheuniquedatainBRF+decisiontablewhereitshouldnotallowforduplicateentries.ManyThanks,Prasad.
-
5/28/2015 HandlingofApplicationswiththeBRF+API(Par...|SCN
http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1 11/11
FollowSCNSiteIndex ContactUs SAPHelpPortalPrivacy TermsofUse LegalDisclosure Copyright
Like(0)
ChristianLechnerMar25,20158:27PM(inresponsetoPrasadChougule)
Hi,thisdoesnotexactlyanswermyquestion.IfyouusetheBRFplusAPIinordertoaddanewfieldyouhavetochangetheABAPcodinginordertoaddthenewfield.ThesameisvalidforthecallofthecorrespondingBRFplusfunction.NonduplicateentrieswithinonesinglefieldcannotbecheckedusingstandardBRFplusfunctionality.YoucandoacheckforoverlapsofconditionsforthecompletedecieiontableBRChristianP.S.ItwouldbeappreciatedifyoupostyourquestionsasgeneralquestionsintheBusinessRuleMangementSpaceastheydonotdirectlyrelytotheblog.Thiswillalsohelpotherstofindanserstosimiliarquestionsmucheasier.Thanks
Like(0)
PrasadChouguleMar27,201510:36AM(inresponsetoChristianLechner)
HiChris,sorryforconfusion,Igotyourquestion.wewillbemaintainingfieldsalsoindecisiontableforeg.ifwehavetocheckbelowconditioninourprogramthen,wewillmaintainLWA_T001inonefieldand0500inonefieldandlikethiswewillbemaintainingallifcombinationinmultiplerows.ifLWA_T001BUKRS='0500'.whenwewillretrievethedatatogetheritwillbestringandsamewewillmatch.IhavetriedtocreateadynamicIFconditioninABAPbutitisnotisthisanswertoyourquestion.andcanweavoidtheduplicateentriesusingexitclass.ifyesplzcanyousendmesomeexampletoachievethefunctionality.ManyThanks,Prasad.YesIwillpostmyquestioninOpenForum.
Like(0)
ChristianLechnerMar29,20155:19PM(inresponsetoPrasadChougule)
HiPrasad,sorryIhavenoexampleforthischeckforduplicateentriesathand.BRChristian