Sie sind auf Seite 1von 7

ExamplesforFormulaApplications

1.Priceplanning
2.PricePlanningwithPricesintheMasterData
3.ProportionalPlanning
4.CopyingwithConditionontheValueofaKeyFigure
5.CopyingwithConditionandIterationoverKeyFigureName
6.PlausibilityCheckofData
7.RollingPlanning
8.Depreciation
9.CalculatingwithDataType'D'
10.WorkingwithCharacterStrings

1.PricePlanning
Inversion1itisplanned,inversion2thepricesarestoredinthetransactiondata.Thecharacteristicstobe
changedare:
Version(0VERSION)
FiscalYear(0FYEAR)
Customer(0CUSTOMER)
TherecordshavethespecialfeaturethatthecharacteristicsCustomerandFiscalYearhavethevalueNot
Assignedandmustthereforebeincludedinthegroupofcharacteristicstobechanged.Foreveryobjecttobe
plannedinversion1,theremustalsobeanobjectinversion2fromwhichthepricecanbedetermined.Ifno
priceisplannedforanarticle,anotificationisissued.Thecalculationisonlyexecutedwhenthecombination
{QUANTITY,1,FYEAR,CUSTOMER}isscheduled,therefore>0.
DATACUSTOMERTYPE0CUSTOMER.
DATAFYEARTYPE0FYEAR.
DATAARTICLETYPE0ARTICLE.
IF{PRICE,2,#,#}=0.
ARTICLE=OBJV().
MESSAGEI001(/SEM/003)WITHARTICLE.
ELSE.
FOREACHFYEAR,CUSTOMER.
IF{QUANTITY,1,FYEAR,CUSTOMER}>0.
{REVENUE,1,FYEAR,CUSTOMER}={QUANTITY,1,FYEAR,CUSTOMER}*{PRICE,2,#,#}.
ENDIF.
ENDFOR.
ENDIF.
ItseemssurprisingthattheArticle(0ARTICLE)ismissingfromthelistofcharacteristicstobe
changedasthepricesthatareusedforcalculatingrefertothe0ARTICLE.Ifspecificallyincluding
the0ARTICLEcharacteristic,theexamplewouldlookasfollows:

DATACUSTOMERTYPE0CUSTOMER.
DATAFYEARTYPE0FYEAR.
DATAARTICLETYPE0ARTICLE.
FOREACHARTICLE,FYEAR,CUSTOMER.
IF{PRICE,2,#,#,ARTICLE}=0.
MESSAGEI001(/SEM/003)WITHARTICLE.
ELSE.
IF{QUANTITY,1,FYEAR,CUSTOMER,ARTICLE}>0.
{REVENUE,1,FYEAR,CUSTOMER,ARTICLE}={QUANTITY,1,FYEAR,CUSTOMER,ARTICLE}*
{PRICE,2,#,#,ARTICLE}.
ENDIF.
ENDIF.
ENDFOR.
The0ARTICLEcharacteristicisnotactuallynecessaryfortheformulaasthevaluesofthecharacteristic
arenotchanged.Whencalculatingtheplannedrevenueitisshownthatthesamearticleisreferencedon
bothsidesoftheassignmentoperator.

Inacasesuchasthis,SAPrecommendsthatyoudonotincludethecharacteristicinthe
quantityofcharacteristicstobechangedasitisnotrequiredforthecalculation,butcostsin
performancewhenaccessingthevalues.Anotherwayofacceleratingtheformulaistosave
thevalueofthe{PRICE,2,#,#}elementinahelpvariableandthentoworkwiththis.Ifthe
valueofacharacteristicisneededtooutputanerrormessageortodetermineattribute
values,thevaluecanbereadwiththeOBJV()function.
Theformulacanbemadeevenshorterifthereferencedataisaccessedexplicitly.Apartfromthekeyfigure
nametherearenocharacteristicstobechanged.Theformulaisexecutedforeachdatarecord.AFOREACH
loopthroughcharacteristicstobechangedisthereforenotrequired.
DATAARTICLETYPE0ARTICLE.
IF{PRICE|0VERSION=2,0FYEAR=#,0CUSTOMER=#}=0.
ARTICLE=OBJV().
MESSAGEI001(/SEM/003)WITHARTICLE.
ELSE.
REVENUE=QUANTITY*{PRICE|0VERSION=2,0FYEAR=#,0CUSTOMER=#}.
ENDIF.

2.PricePlanningwithPricesintheMasterData
Whatdoespriceplanninglooklikewhenthepriceisstoredinthemasterdata?Weaccessthevalueofthe
articleusingtheOBJVfunction.ThevalueoftheOPRICEattributeisreadusingtheATRVfunction.Ina
simplecasetheATRVfunctionhastwoarguments.Thefirstargumentmustbethenameofamasterdata
attributeandthesecondavariable.Thevalueoftheattributeisreadfromthemasterdatatableusingthe
variablevalue.Compoundcharacteristicsdifferinthefollowingways:

Iftheparentcharacteristicsareforfieldstobechanged,thevaluesofthesefunctioncharacteristics
mustbespecifiedintheformofvariables.Thenumberofargumentsofthefunctionisdeterminedin
thiscasebyhowmanyfieldshavetobespecified.
Iftheparentcharacteristicsarenotincludedinthequantityoffieldstobechanges,thevaluesare
automaticallyremovedfromthevaluesofthecurrentpackage.Thefollowingexampleshowsonlythe
keyfigurenameofacharacteristictobechanged.
DATAARTICLETYPE0ARTICLE.
ARTICLE=OBJV().
REVENUE=ATRV('0PRICE',ARTICLE)*QUANTITY.

3.ProportionalPlanning
Characteristicstobechangedarekeyfigurename,version(0VERSION),fiscalyear(0FYEAR),and
customer(0CUSTOMER).
DATATOTREVENUETYPEF.
DATATOTQUANTITYTYPEF.
DATACUSTOMERTYPE0CUSTOMER.
FOREACHCUSTOMER.
TOTREVENUE=TOTREVENUE+{REVENUE,2,CUSTOMER}.
TOTQUANTITY=TOTQUANTITY+{QUANTITY,2,CUSTOMER}.
ENDFOR.
FOREACHCUSTOMER.
{REVENUE,1,CUSTOMER}={QUANTITY,1,CUSTOMER}*TOTREVENUE/TOTQUANTITY.
ENDFOR.

4.CopyingwithConditionontheValueofaKeyFigure
ThecharacteristictobechangedisVersion.Thekeyfigurenameisselectedasthecharacteristicfor
conditions.REVENUEwasselectedasthevalueforthekeyfigurename.Thefollowingformulacopiesthe
revenuefromversion1toversion2iftherevenueinversion1isgreaterthan500.Wecannotimplementthe
planningfunctionoftypeCopyinthisexampleasitisnotpossibletoformulateconditionsforkeyfigure
valueshere.Itisgenerallyanadvantagetousethespecialplanningfunctionsratherthanformulasasthese
areimplementedmoreefficiently.
IF{1}>500.
{2}={1}.
ENDIF.

5.CopyingwithConditionandIterationoverKeyFigureName
Characteristicstobechangedarekeyfigurenameandversion.Incontrasttotheexampleabove,allkey
figuresarenowcopiedtoversion2iftherevenueisgreaterthan500.Toavoidhavingtoassignallkey

figures,wedefineaRATIOvariableoftypeKEYFIGURE_NAMEanditerateacrossallkeyfiguresofthe
planninglevelusingtheFOREACHconstruct.
DATARATIOTYPEKEYFIGURE_NAME.
IF{REVENUE,1}>500.
FOREACHRATIO.
{RATIO,2}={RATIO,1}.
ENDFOR.
ENDIF.

6.PlausibilityCheckofData
Characteristicstobechangedarekeyfigurename,version,andarticle.Wecheckwhethertheplanned
revenuehasreachedatleast90percentoftherevenueofversion1.Iftheboundaryisexceeded,the
systemgivesawarningmessage.
DATAARTICLETYPE0ARTICLE.
DATAMINREVENUETYPEF.
FOREACHARTICLE.
MINREVENUE={REVENUE,1,ARTICLE}*0.9.
IF{REVENUE,2,ARTICLE}<MINREVENUE.
*Theplannedrevenueforarticle&1exceedsthepredefinedminimumrevenue
MESSAGEI034(ZSEM)WITHARTICLE.
ENDIF.
ENDFOR.

7.RollingPlanning
Characteristicstobechangedareversionandfiscalyear/period.Theactualdataofthecurrentperiodis
copiedtotheplanversion.Thedifferenceisspreadacrosstheremainingperiods.Thecurrentperiodis
determinedfromavariable.
DATAACTPERTYPEFISCPER.
DATAFISCPERTYPEFISCPER.
DATASUMTYPEF.
DATADELTATYPEF.
*PeriodsreadfromthevariableswiththetechnicalnamePERIOD
ACTPER=VARV('PERIOD').
*Getsumforweight
FOREACHFISCPER.
IFFISCPER>ACTPER.
SUM=SUM+{1,FISCPER}.

ENDIF.
ENDFOR.
*Deltabetweenplannedvalueandactualvalue
DELTA={1,ACTPER}{0,ACTPER}.
*Setplannedvaluetoactualvalue
{1,ACTPER}={0,ACTPER}.
*Weighteddeltadistribution
FOREACHFISCPER.
IFFISCPER>ACTPER.
{1,FISCPER}={1,FISCPER}+DELTA*{1,FISCPER}/SUM.
ENDIF.
ENDFOR.

8.Depreciation
Characteristicstobechangedarekeyfigurenameandfiscalyear.Determinesthevalueof
the0AMOUNTkeyfigureforfiveyears.Costpriceis1000.Netbookvalueis100.Depreciationpercentage
rateis20percent.Itisstraightlinedepreciation.InthisexampletheDECL(straightlinedepreciation)
functionisnotofimportance,buttheTMVLfunction.Thisfunctionhasthevalueofatimecharacteristicas
itsfirstargumentandanoffsetasitssecond.Theoffsetspecifieswhichnextlargestvaluethefunction
shoulddeliver.Youcanalsotransfernegativeoffsets.Thenthecorrespondingsmallervaluesaredelivered.
ItisnotpossibletosetthesameeffectwithaFOREACHloopbecausenotallyearshavetobeincludedin
thetransactiondata.
DATAYEARSTYPEI.
DATAFYEARTYPE0FISCYEAR.
FYEAR=VARV('ACTYEAR').
DO.
YEARS=YEARS+1.
FYEAR=TMVL(FYEAR,1).
{0AMOUNT,FYEAR}=DECL(1000,100,20,YEARS).
IFYEARS=5.
EXIT.
ENDIF.
ENDDO.

9.CalculatingwithDataType'D'
Itisalsopossibletoexecutecalculationsusingdatatype'D'.Asmallexampleisshownbelow.Inthe
FOREACHloop,thedateofthefirstdayisspecifiedinD1inFISPCERandthelastdayinD2inFISCPER.

Inadditiontothis,thedifferencebetweenD2andD1isshowninI1andtwodaysaresubtracted.I1isof
typeI.IfthedateformatinD1andD2isinvalid,theresult0isreturned.Whencalculatingwithfieldsoftype
D,theconstantoperandsarealsocheckedforvaliddateformats.ThereforewecouldnotwriteI1=D2D1
2.buthavetouseahelpvariableI2.
DATAD1TYPED.
DATAD2TYPED.
DATAI1TYPEI.
DATAI2TYPEI.
DATAFISCPERTYPE0FISCPER.
FOREACHFISCPER.
*Calculate1stdayofFISCPER
D1=C2DATE(FISCPER,S).
*CalculatelastdayofFISCPER
D2=C2DATE(FISCPER,E).
*Calculatethedifferencebetweenlastand1stdayminustwodays
I2=2.
I1=D2D1I2.
MESSAGEI001(UPF)WITH'DIFFERENCE'I1.
ENDFOR.

10.WorkingwithCharacterStrings
Inthefollowingexampleitischeckedifthecharacteristicsfiscalyear/period(0FISCPER),fiscal
year(0FISCYEAR)andthreefigurepostingperiod(0FISCPER3)arecompleted
consistently.Fiscalyear/periodissevencharacterslong,thefirstfourrepresentthefiscalyearand
thecharactersfivetosevenrepresentthepostingperiod.UsingtheSUBSTRfunction(characteristic,
offset,length)thecorrespondingvaluesarereadfromthevaluefiscalyear/period.Ifthe
characteristicvalueofFiscalyear/periodisinitial,itisfilledwiththeconcatenatedvalueoffiscal
yearandpostingperiod.TheCONCATfunctionisusedforthis.
DATAFISCPERTYPE0FISCPER.
DATAFISCPER_CMPTYPE0FISCPER.
DATAYEARTYPE0FISCYEAR.
DATAPERTYPE0FISCPER3.
DATAPER_CMPTYPE0FISCPER3.
DATAYEAR_CMPTYPE0FISCYEAR.
DATAKYFNMTYPEKEYFIGURE_NAME.
YEAR=OBJV().
PER=OBJV().
FISCPER_CMP=CONCAT(YEAR,PER3).

FOREACHKYFNM,FISCPER.
IFFISCPERISINITIAL.
{KYFNM,FISCPER_CMP}={KYFNM,FISCPER}.
ELSE.
PER_CMP=SUBSTR(FISCPER,4,3).
YEAR_CMP=SUBSTR(FISCPER,0,4).
IFYEAR<>YEAR_CMPORPER<>PER_CMP.
*Errormessage
MESSAGEE021(/SEM/003)WITHYEARYEAR_CMPPERPER_CMP.
ENDIF.
ENDIF.
ENDFOR.

Das könnte Ihnen auch gefallen