Anda di halaman 1dari 11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

GettingStarted Newsletters

Hi,Jayakrishna

LogOut

1points

Store

SearchtheCommunity

Products

Services&Support

AboutSCN

Downloads

Industries

Training&Education

Partnership

DeveloperCenter

Activity

LinesofBusiness

UniversityAlliances

Events&Webinars

Innovation

Browse

Communications

Actions

Create

SAPBusinessRulesManagement

HandlingofApplicationswiththeBRF+API(Part1)
PostedbyChristianLechnerinSAPBusinessRulesManagementonOct23,20148:08:23AM
Share

Tweet

9 Like

Introduction
ManyquestionsanddescriptionshereinSCNfocusontheusageoftheBRF+viatheworkbenchas
interfaceforthecreationandmaintenanceofobjectsoftheBRF+.Butthereisalsoanotherwaytoget
thesethingsdonenamelytheBRF+API.Thisblogshallintroduceyouintosomebasicusagescenariosof
theAPI.AcomprehensivedescriptionoftheAPIcanbefoundinthebook
CarstenZieglerand

BRFplusTheBookof

ThomasAlbrecht.

Thefirstquestionthatmightariseuptonowis:WhyshouldIuseanAPIifIhavethecomfortoftheBRF+workbench
withitsquiteusableWebdynproUI?
Theansweris:TherearescenarioswheretheBRF+workbenchcannotbeusedforthemaintenance.Oneexampleis
themaintenanceoftherulesontheproductiveenvironmentwhenDSMisnotinplace,IncaseyouareusingBRF+
applicationsofstoragetypeSorCyoursystemsettingswillusuallypreventtheirmaintenanceontheproductive
system.Thereisaworkaroundbyusinganapplicationexitbutthenyoureallyhavetotakecareonthe
synchronizationprocessbetweenthedevelopmentandtheproductivesystemasthoseapplicationsarestillpartofthe
regulartransportprocess.Thiscangetquitetrickyandisnotthebestwaytogo.
Nowyoumightsaythatamasterdataapplicationmightsolvetheissuebutthatoneisnotintendedtobetransported
exceptfortheXMLexportandimportfunctionalitywhichmightnotbethepreferredwayofyourIToperationsteam.So
thismightberighttimetoswitchtoagenerativeapproachusingtheBRF+API.Thisapproachmightalsobeoffavor
whenyouwantto(deeply)integrateanartefactoftheBRF+(e.g.adecisiontable)intoanexistingapplicationsothat
theuserisnotevenawareofusingtheBRF+butontheotherhandstillbeingabletouseallthenicefeaturesofthe
artefact.

BeforethestorygetsalittlebittootheoreticalIwanttointroduceabusinessscenariowherethisapproachcanbe
used.

TheBusinessScenario

Asmybackgroundisthefieldofinsurancesoismyscenario:LetusassumewehaveaSAPmodule(likeSAPPolicy
Management)thatallowsyoutomanagemasterpoliciesmorespecificthefleetmasterpolicies.Withinthesemaster
policiestheinsurerandtheinsuredcompanyagreeontheinsuranceofthecompanycars.Usuallytheinsured
companypaysacertainpremiumpercarandthebasisforthepremiumcalculationiswrittendowninthemaster
policy.Thisbasisdependsoncertainpropertiesofthecarstobeinsured.Letususethefollowingverysimplified
exampleforsuchatable:

Weightofcarintons
PerformanceofthecarinkW
PremiumamountinEUR
<=1.5

<=80

250

<=2.5

<=90

350

<=3.5

<=110

400

>3.5

>110

500

Eachinsuredcarfinallygetsonesinglepolicyissuedwiththepremiumcorrespondingtothepropertiesofcarandthe
agreementinthefleetmasterpolicye.g.foracarwithlessthan1.5tonsandaperformanceof80kwyoupaya
premiumof250.Eventhissimplifieddescriptionleadsustothepointthatadecisiontablemightbeaverygood
choicetotacklethescenario.Butherecometheproblems:
Thepremiumconditionsareenteredontheproductiveenvironmentafterthenegotiationbetweentheinsurer
andtheinsuredcompanyhasbeenconcluded.
NoDecisionServiceManagementisavailable.
TheuserdoesnotwanttoswitchfromthemasterpolicymanagementapplicationtotheBRF+applicationin
ordertoenterthedataofthemasterpolicy.Hewantstohaveonesingletransaction.

Soapossiblethesolutionforthatscenarioconsistsoftwotasks:

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

1/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

EnhancetheUIofthepolicymanagementapplicationinordertoallowtheusertodisplayandeditthedatainthe
decisiontable.ForthistopicIwanttorefertothecorrespondingdocumentavailablehereinSCN:

http://scn.sap.com/docs/DOC4578
Implementafunctionalityinthesystemthatcreatesadecisiontable(includingits"surroundings"like
application,functionetc.)inbackgroundforeachmasterpolicyandmakeitavailablefortheUI.This
taskalsocontainsthecreationofthefunctionalitytomaintainthedatainthedecisiontable(plusthe
nicefeatureslikecheckforoverlaps).Thisisthepartthattheblogfocusesoninthesubsequent
sections.

Disclaimer
Beforestartingwiththetechnicaldetailsjustashortdisclaimer:theusageoftheAPIforthemaintenanceoftheBRF+
objectsissomequiteadvancedtopicsoifyoudecidetouseityoushouldknowwhatyouaredoing(whichisinmost
casesaquitegoodapproach

).Especiallywhenyouareintegratingthefunctionalityintoanexistingapplicationyou

havetobecarefule.g.aboutthecommithandling,thetransactionhandlingetc.oftheapplicationandtheBRF+API
andtheinterplaybetweenthem.Alsointensivetestingoftheintegratedcomponentsplaysanimportantrole.

Inadditionthecodingsnippetsshownbelowdonothaveasophisticatederrorhandlingsoforarealusage
someadoptionshavetobemade.

Butnowenoughforthatpartandletusstartwiththerealstuff...thecodingwiththeBRF+API!

Solution
InordertomakethedecisiontableavailablefortheenhancedUIofthemasterpolicymanagementwewillimplement
ahandlerclassZCL_BRFPLUSAPI_FLEETforthesingleoperationsthathavetobetriggeredviatheBRF+API.This
meansthatasaroughguidewehavethefollowingmethodsforthe:
creationoftheBRF+applicationwithafunction(infunctionalmode)andadecisiontableassignedtothe
function
readthedecisiontabledata
insertandupdatedatainthedecisiontable
deletethecompleteapplication
servicefunctionalitieslikecheckforgapsoroverlapsinthedecisiontable
processingofthedecisiontable

Asthestructureforthedecisiontableisconstantthereisnoneedtocreatethesingledataobjectsofthecolumns
wheneveranewdecisiontableiscreatedsoasaprerequisitewehaveanadditionalBRF+applicationofstoragetype
Sthatholdsthecorrespondingdataobjectsfortheweight,theperformanceandthepremiumamountasreusabledata
objects.

Creatingthedecisiontable

InordertocreatethedecisiontablewefirsthavetocreateaBRF+application.Wewilluseanapplicationoftype
masterdatafortheexampleasthisistheobviousstorage.Forthetaskwedesignonemethodthatcreatesthe

applicationincludingitssubobjectsandreturnsareferencetoit:

WithinthatmethodwefirstfetchareferencetotheBRF+factorywhichisthecentralpointwhencreatingBRF+objects:

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

2/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

Asalreadyshownwethendelegatetoamethodthatcreatestheapplicationwithitsbasicfeaturesandreturnsthe
referencetoit.Themethodcontainsthefollowinglogic(thenumbersrefertothehighlightedsectionsinthefollowing
screenshot):
1. WecallGET_APPLICATIONontheBRF+factoryandgetbackareferencetoanemptyapplicationobject.Next
weenqueuetheapplicationobjectitselfbyusingthecorrespondingmethodoftheinterface
IF_FDT_TRANSACTION.
2. Afterthatwesetthebasicparameterslikeapplicationcomponentandsoonusingthemethodsthatare

availableontheapplicationobject.ForeveryfieldthatyoucanseeontheBRF+workbenchonemethod
isavailableintheapplicationAPI.
3. AfterthatwecallaspecificAPImethodthatcreatesthemasterdataapplicationbasedontheproperties

wesetintotheobject.
Therearealsomethodsfortheothertypesofapplicationslikecustomizingapplications.
4. Aswehavenowfinishedtheapplicationspecificactionsweactivatetheapplicationviathemethod

IF_FDT_TRANSACTION~ACTIVATE.Dependingonthesuccessorfailurewesaveanddequeuethe
applicationorjustdequeueit.IncaseofasuccesstheapplicationisnowavailableintheBRF+
workbench.

Someremarksonthisfirsttask:

TheAPIalsoallowsadeepactivationandsavingofobjects(meaningthatyoutriggerthesavinge.g.on
applicationlevelandallsubsequentobjectsaresavedtoo).Thisalternativewillbeshowninthefollowing
screenshots.
ThenamingoftheapplicationwasdeterminedusingtheclassCL_FDT_SERVICES.Thisclassoffers
methodsthatcreateGUIDsforyournameseitherwithorwithoutaspecificnamespaceandwascalled
inthemethodGET_UNIQUE_NAMEinthescreenshotabove.
MostoftheBRF+APImethodsthrowtheexceptionCX_FDT_INPUT.Youshouldalwayscatchand
handleit

Nowletusgobacktothemainmethodforthecreationoperation.Nextwewanttocreatethedecisiontableinorderto
haveitinplacewhenwecreatethefunctionandassignitastoplevelexpression.Butbeforewecandosoweneedto
getaccesstothedataobjectsusedinthedecisiontablei.e.theirreferencesthatwehavestoredintheSapplication
forreuse:

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

3/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

WithinthismethodweonceagainusetheBRF+factorytofetchthereferencestotheseobjects:

IfyouknowtheIDsofthedataelements(thatIstoredasconstantsinaninterface)thereferenceisjustonecallof
GET_DATA_OBJECTaway.Havingthesereferenceswehaveaccesstoalltheattributesofthedataobjectse.g.their
type.

HavingtheBRF+factorytheapplicationobjectandthereferencestothedataobjectsthatbuildthecolumnsofthe
decisiontablewecannowgoonandcreatethedecisiontableviaanotherprivatemethod:

Thecreationofadecisiontableisroughlyspeakingthesameasthecreationofanapplicationwiththefollowingsteps
(thenumbersrefertothehighlightedsectionsinthefollowingscreenshot):
1. Creationadecisiontableobjectviathefactory,enqueuingitandsettingthebasicproperties.Eachattributethat
canbesetisrepresentedbyamethodofthedecisiontableAPI.

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

4/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

2. Fillingofthedecisiontablecolumnsandsettingtheirproperties(e.g.isitaconditionoraresultcolumn)
3. Settingthecorrespondingobjectstothedecisiontableobject
4. InadditionwealsostoredtheobjectIDsofthecontextobjectsthatwillbeusedinthenexttaskwhen

creatingthefunction

Asyoucanseewedidnotyetactivateandsavetheobject.
Nowwehavethereferencestotheapplicationobject,the(empty)decisiontableobjectandthedataobjects.Wecan
thereforefinishthecreationoperationbycreatingafunctionandactivatingthefunctionanditssubobjects:

Thismethodencapsulatesthefollowingsteps(thenumbersrefertothehighlightedsectionsinthefollowing
screenshot):
1. First,asusual,wecreateareferencetoafunctionobjectviatheBRF+factory.Afterenqueuingitweassignitto
anapplicationandusethemethodsoftheobjecttosetthebasicattributesofafunctionobjectlikethenameand
versioning.Lastbutnotleastwesetthemodeofthefunctionto"functionalmode".AswitheveryBRF+APIthe
objectreferencehasmethodsforeachattributethatcanbeset.
2. Nextweassignthecontextandresultdataobjectsaswellastheexpressiontothefunction.Rememberthatwe
fetchedtheobjectIDsofthecontextparameterswhenweconstructedtheconditioncolumnsofourdecisiontable
3. Asthirdstepweactivatethefunction.ThistimewesettheoptionalparameterIV_DEEPtoABAP_TRUEwhich
leadstoanactivationofthefunctionanditsinactivesubobjects(inourcasethedecisiontable)
4. Lastbutnotleastwesaveanddequeuethefunctionincaseofasuccessfulactivation.Onceagainweusethe
IV_DEEPparameterofthemethodstopropagatetheaction.

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

5/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

That'sitexecutingthecreatemethodCREATE_MASTERDATA_APPLICATIONofthehandlerclass
ZCL_BRFPLUSAPI_FLEETwillnowcreateanapplicationwithfunctionandemptydecisiontablefromscratch.The
methodreturnsthereferencetotheapplicationobjectsowecanforexamplestoretheGUIDoftheapplication(stored
inthepublicattributeMV_IDofthereferencetotheapplication)inourmasterpolicyinordertobeabletoretrievethe
applicationanditssubobjectsatalaterpointintime.

Thekeytakeawaysofthisfirstsectionare:
EveryBRF+objecthasanAPIthatcanbeusedtocreateandmaintainit.
InordertogetanobjectreferencetooneoftheAPIsweneedtheBRF+factoryclassCL_FDT_FACTORY.
SomeglobalBRF+servicefunctionalitiesareimplementedintheclassCL_FDT_SERVICES

SettingandGettingtheData
Afterthesuccessfulcreationofthedecisiontablewewanttooffermethodsinourhandlerclassinordertoreadthe
entriesofthedecisiontableaswellastosetdataintothedecisiontable.

AsastartingpointletusassumethatthatwehavetheGUIDoftheapplicationandhavetoretrievethereferenceto
decisiontableviathatGUID.Sowehavetoimplementamethodthatfetchesthereferencestotheobjectsthatbelong
totheapplicationspecifiedviatheGUID:

Thecontentofthemethodconsistsoftwomajorpartsnamelythefetchingofthefunctionobjectandthenthefetching
ofthedecisiontableobject.
Forthefunctionobjectthefollowingstepsareperformed(thenumbersrefertothehighlightedsectionsinthefollowing
screenshot):
1. FirstwegetareferencetothequeryobjectoftheBRF+specificforfunctions.AsfortheBRF+APIaqueryobject
foreachartefactexists
2. ThenweconstructtheselectionparametersinourcasetheparametersoftheapplicationidentifiedbyitsIDand

specifythatwearelookingforamasterdataobject
3. AfterthatwefirethequeryandgettheIDofthefunctionasaresult.
4. AsalaststepweuseanotherimportantmethodoftheBRF+factorynamelythemethod
GET_INSTANCE_GENERICthatreturnsusareferencetothefunctionobjectthatwehavetocasttothefunction
specificinterface.

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

6/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

Aswehavea1:1relationshipbetweenthefunctionandthedecisiontablewecandirectlyfetchthereferencetothe
decisiontablebyusingthemethodGET_EXPRESSIONofthefunctionAPIthatreturnstheIDofthedecisiontable
object:

Aftercastingtotherightinterfacewehavethereferencetothedecisiontablethatwecanuseforgettingandsetting
thedata.SoweenhancethehandlerclassZCL_BRFPLUSAPI_FLEETwithtwoadditionalmethodsforthegettingand
settingofdatafrom/intothedecisiontableobject:

TheimplementationoftheGETmethodisstraightforwardaswecallthecorrespondingGETmethodofthedecision
tableAPI:

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

7/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

TheSETmethodisnearlyasstraightforwardastheGETmethodsowecalltheSETmethodoftheAPIbutaswemake
achangetothetablewehavetoenqueue/dequeueaswellasactivateandsavetheobjectinanalogytothecaseof
itsinitialcreation:

Asyoucanseethesettingandgettingofthedataitselfisnotdifficultbutitiscertainlyalsoofinterestwhatthetable
datahastolooklikeinordertobeabletocallthesetwomethods.
Thefollowingcodingsnippetgivesyousomeinsighthowthiscanbeachieved:
Firstwecreateareferencetoourhandlerclassandfetchthereferencetothedecisiontableobject(theapplicationID
isaparameterofthereport).
SecondwefetchthetypenamesofthesinglecolumnsusingtheBRF+factoryasshowninthescreenshotsbelow

Thenwefillthetableparameterswiththevaluesfortheconditioncolumnswherewespecifythetablecolumnandrow
theoperatorsforthecomparisonandtheconcretevalue:

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

8/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

Afterthatwefilltheresultcolumnwhichismorestraightforwardduetothedirectassignmentoftheresultvaluewithout
optionsforcomparisons:

Thiswaywehavetofillthetablelinebylineandfinallysetitintoourdecisiontableusingthehandlerclass:

Thekeytakeawaysofthissecondsectionare:
HavingtheIDofanBRF+objectenablesyoutosearchforotherBRF+objectsusingthequeryfunctionality
(IF_FDT_QUERY)availableviatheBRF+factory.
YoucaneitherinstantiateaBRF+objectviathecorrespondingmethodfortheobjectonthefactoryoryouuse
thestaticgenericmethodGET_INSTANCE_GENERICofthefactory.
EveryAPIhasmethodstosetandgetthedataandpropertiesstoredintheobject.Theconcreteparameters
dependonthespecificobjecttype.

SummaryandOutlook
WithinthisblogascenariowaspresentedwhichisanexamplefortheusageoftheBRF+APItocreateandmaintain
BRF+objects.Wecreatedanapplication,afunctionandanemptydecisiontableinstoragetype"masterdata".Then
wedeterminedthewayshowtofetchthereferencetothecreatedobjectsviatheIDoftheBRF+applicationandhow
toset/getdatato/fromthedecisiontableobject.

AsthereareseveralmorefunctionalitiesthatyoucanaddressviatheBRF+APIthatmightbeofinterestand
arelistedinthefunctionlistofthehandleraboveafurtherblogisavailablethatdescribese.g.theAPIto
checkforgapsandoverlapsinthedecisiontable: HandlingofApplicationswiththeBRF+API(Part2)

1471Views

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

9/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

Products:sap_netweaver_business_rules_managementTopics:business_rules_managementTags:sap_business_rules,
brfplus,brf+

AverageUserRating

MyRating:

(5ratings)

Share

Tweet

9 Like

8Comments
WolfgangSchaperOct23,20143:52PM

IjustwanttopointoutthattheBRFplusbookwascoauthoredbyCarstenZieglerandThomas
Albrecht.EspeciallyThomaswrotethechapterontheAPI.Soweshouldnotforgettomentionhim
here.
Like(1)

ChristianLechnerOct23,20145:18PM(inresponsetoWolfgangSchaper)

ThanksWolfgangforthecorrectiveadviceonthat.Icorrectedthecorrespondingsentence.
Like(1)

PrasadChouguleMar21,20159:30PM

HiChris,

Thanksforthisblog.

Pleasecanyouhelpmetounderstandthecorrectapproachonbelowreuirements.

iwanttomaintaincertaincombinationofIFconditioninBRF+Applicationwhichwillbecalled
dynamicallyinABAP.

eg.IFL_BUKRS='XYZ'andL_BSART='ABC'.

currentlyinmyreportiwanttocheckthistwovariablesconditionbutgoingfwdifiwanttocheckthird
variablesL_VKORG='DEF'insameIFcondition.
theniwillnotchangemyABAPcodeitshouldbehandlethorughourBRF+application.

AnyHelponthiswillbeAppreciated.
Like(0)

ChristianLechnerMar22,20157:03AM(inresponsetoPrasadChougule)

HiPrasad,

IamnotquitesureifIunderstandyoucorrectly:youwanttohaveone"generic"pieceof
ABAPthatmainlymodelsanIFconditionwiththesingleconditionslinkedbyanAND.
Ihaveseveralquestionsonthat:
Wheredoestheinformationconcerningthecontextparametersthatshallbeused
comefrom?
Wheredothevaluesthatyouwanttocompareagainstcomefrom?
WhatistheELSE(IF)cases(s)?

BR
Christians
Like(0)

PrasadChouguleMar23,20158:06PM(inresponsetoChristianLechner)

HiChris,

ManyThanksforquickreply,inthisapplicationihavecreatedonedecisiontable
whereiwillmaintainfieldandvalueswhichwillbecalledinABAPforchecking
thecondiitons.

andalsochriscanyouhelpmetomaintaintheuniquedatainBRF+decisiontable
whereitshouldnotallowforduplicateentries.

ManyThanks,
Prasad.
Like(0)

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

10/11

5/28/2015

HandlingofApplicationswiththeBRF+API(Par...|SCN

ChristianLechnerMar25,20158:27PM(inresponsetoPrasadChougule)

Hi,

thisdoesnotexactlyanswermyquestion.IfyouusetheBRFplusAPIin
ordertoaddanewfieldyouhavetochangetheABAPcodinginorderto
addthenewfield.Thesameisvalidforthecallofthecorresponding
BRFplusfunction.

Nonduplicateentrieswithinonesinglefieldcannotbecheckedusing
standardBRFplusfunctionality.Youcandoacheckforoverlapsof
conditionsforthecompletedecieiontable

BR
Christian

P.S.Itwouldbeappreciatedifyoupostyourquestionsasgeneral
questionsintheBusinessRuleMangementSpaceastheydonotdirectly
relytotheblog.Thiswillalsohelpotherstofindanserstosimiliar
questionsmucheasier.Thanks
Like(0)

PrasadChouguleMar27,201510:36AM(inresponsetoChristian
Lechner)

HiChris,

sorryforconfusion,Igotyourquestion.
wewillbemaintainingfieldsalsoindecisiontableforeg.
ifwehavetocheckbelowconditioninourprogramthen,wewill
maintainLWA_T001inonefieldand0500inonefieldandlike
thiswewillbemaintainingallifcombinationinmultiplerows.
ifLWA_T001BUKRS='0500'.
whenwewillretrievethedatatogetheritwillbestringandsame
wewillmatch.
IhavetriedtocreateadynamicIFconditioninABAPbutitisnot
isthisanswertoyourquestion.

andcanweavoidtheduplicateentriesusingexitclass.
ifyesplzcanyousendmesomeexampletoachievethe
functionality.

ManyThanks,
Prasad.

YesIwillpostmyquestioninOpenForum.
Like(0)

ChristianLechnerMar29,20155:19PM(inresponseto
PrasadChougule)

HiPrasad,

sorryIhavenoexampleforthischeckforduplicate
entriesathand.

BR
Christian
Like(0)

SiteIndex
Privacy

ContactUs
TermsofUse

SAPHelpPortal
LegalDisclosure

Copyright

http://scn.sap.com/community/brm/blog/2014/10/23/handlingofapplicationswiththebrfapipart1

FollowSCN

11/11

Anda mungkin juga menyukai