0% found this document useful (0 votes)
43 views6 pages

Performance Tuning - ABAP Development - SCN Wiki

Performance

Uploaded by

sudh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views6 pages

Performance Tuning - ABAP Development - SCN Wiki

Performance

Uploaded by

sudh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

11/8/2016

PerformanceTuningABAPDevelopmentSCNWiki
GettingStarted

CommunityWIKI

SAPCommunity

Welcome,Guest

Login

Register

Store

ABAPDevelopment

PerformanceTuning
CreatedbyGuest,lastmodifiedonJul04,2007

ABAPPerformanceGuidelines
TopicObjectives
a)DescribeEfficientProgramming
b)DescribetheFactorsImpactingApplicationPerformance
c)DescribetheGeneralPerformanceGuidelines
AllABAPprogramsshouldbedevelopedusingthemostefficientmeanspossible.
ProgramefficiencyguidelinesareincludedintheEBSABAPProgrammingStandards.
Developingefficientprogramminginvolvestheefficientusageofprogramming
standards,SAPABAPWorkbenchtools,andABAPperformancemonitoringtools.
Whatis"EfficientProgramming"?
Efficientprogramminginvolvessolvingaproblemasfastaspossiblewhileusingsystemresourcesassparinglyaspossible.
FactorsImpactingApplicationPerformance
a)Programstructure.
b)Programminglanguagecommands/syntax.
c)SQLstatements.
d)Input/Outputoperations.
e)Databaseorganization.
f)Datavolumes/archivingstrategy.
g)Systemsizing/configuration.
h)Systemconfiguration/loadbalancing.
Ofthefactorslistedabove,the1stfourareofparticularconcerntotheABAPprogrammer.
ProgramStructureThedegreeofmodularization(i.e.useofsubroutines,function
modules,etc.)andthedegreeofnesting(i.e.nestedloopsandcontrolstatements)
impactsprogramperformance.
ProgrammingLanguageCommands/SyntaxCertainABAPstatementsaremore
expensivethanothers.Useofaninefficientstatementwhenamoreefficient
alternativeisavailableaffectsprogramperformance.
SQLStatementsEfficiencyofSQLstatementscandramaticallyeffectprogram
performance.CareshouldbetakentocodethemostefficientSQLpossible.
Input/OutputOperationsTheamountofreadingandwritingtodatasetswithina
programwillimpactprogramperformance.Careshouldbetakentoeliminateany
unnecessaryinput/outputoperations.
TheremainingfactorstendtobethepurviewoftheBASISteamandaretypicallynot
addressedbyanABAPprogrammer.
DatabaseOrganizationThewaythatthedatabaseisorganizedonthephysicaldisk
affectsperformance.
DataVolumes/ArchivingStrategyTheamountofdatastoredwithineachdatabase
tableaffectsprogramperformance.
SystemSizing/ConfigurationThehardwareusedneedstobesizedappropriately
tosupportthenumberofusersandtheexpecteddatavolumesofperformancewill
besignificantlyimpacted.
SystemConfiguration/LoadBalancingTheappropriatenumberofapplication
serversshouldexisttosupportprocessingneeds.Usersandbackgroundtasks
shouldbeappropriatelydistributedacrossservers.
GeneralPerformanceGuidelines
1.Keeptheamountofdatatransferredbetweendatabaseandapplicationsmall.
2.Keepthenumberoftransfersbetweendatabaseandapplicationsmall.
3.Keepthedatatobesearchedsmall.
4.Taketheloadoffofthedatabasewherepossible.
KeeptheAmountofDataTransferredSmall
Usedataselectively.
a)Nosinglelineupdates.
b)Useaggregatefunctions.
c)SELECTwithDISTINCT.
Usingdataselectivelymeansthatonlythedataofinterestshouldbeselected.
Selectingextraneousdataunnecessarilyincreasestheamountofdatathatmustbe
transferredbetweenthedatabaseandtheapplication.
Onewaytoappropriatelylimittheamountofdataselectedistoselectindividual
fieldsofinterestasopposedtowholerows.

https://wiki.scn.sap.com/wiki/display/ABAP/Performance+Tuning

1/6

11/8/2016

PerformanceTuningABAPDevelopmentSCNWiki

TheWHEREclauselimitstheamountofdataselected.Unlessalldatawithinatable
isofinterest,aWHEREclauseshouldbespecified.AWHEREclauseshouldbe
structuredtotakeadvantageoftableINDEXES(i.e.primarykeyfieldsshouldbe
specified,inorder,totheextentpossible).
ItispreferabletoupdatethedatabasewiththesyntaxUPDATE...WHEREas
opposedtoperformingasinglelineupdate(SELECT...UPDATE...ENDSELECT).
Aggregatefunctions(SUM,MIN,MAX,AVG,etc.)arethepreferredmethodforperformingmathematicalandstatisticalfunctionsondatabaserecords.
Performingthesefunctionsprogrammaticallywouldrequiredtransferringtoomuchdatafromthedatabasetotheapplication.Aggregatefunctionslimittheamountofdatatransferredbetweenthedatabase
andtheapplication.
TheSELECTDISTINCTstatementrequeststhattheresultsetbeuniqueandthereforeresultinaconsiderablereductionintheamountofdatatransportedfromthedatabasetotheapplicationserver.
SELECTfield1field2
INTO(ifield1,ifield2)FROMdbtable
WHEREcondition.
...
ENDSELECT
SELECTfield1field2
INTO(ifield1,ifield2)FROMdbtable
WHEREcondition.
...
ENDSELECT
UseDataSelectively
1.UseWHEREclause
2.UseSELECTSINGLE
3.UseFieldLists
SELECT*FROMdbtable.
WHEREfield1=value1
ANDfield2>=value2.
...
ENDSELECT
SELECTSINGLE*FROMdbtable
WHEREcondition.
SELECTfield1field2
INTO(ifield1,ifield2)FROM
dbtable
WHEREcondition.
...
ENDSELECT
NoteonuseofWHEREclausebeawareofthetabletypeforthedatabasetablebeingaccessedwhenconstructingaWHEREclause.(TofindoutthetabletypeusetransactionSE12).
ForTRANSP(transparent)andPOOLtables,theSELECTstatementshouldbeafullyqualifiedaspossibleusingtheWHEREclause.Thisincludesdatafieldsthatmaynotbeapartofthekeyinadditionto
thekeyfields.Thisallowsthedatabaseto
evaluatetherecordsandreturnonlythoserecordsmatchingtheselectioncriteria.
ForCLUSTERtables,theoppositeistrue.WhenworkingwithCLUSTERtables,onlyfieldsthatarepartofthekeyshouldbeusedtoqualifySELECTstatements.ForCLUSTERtables,usetheCHECK
statementtoeliminaterecordsaftertheselection
hasbeennarrowedviatheWHEREclauseforkeyfields.ThisisbecauseCLUSTERtablescannotbeprocessedinthedatabasedirectly,ascanTRANSPandPOOLtables.Forcingthedatabaseto
unpackandcheckfields(aswithSELECTstatementscontainingnonkeyfieldsintheWHEREclauses)islessefficient,inmostcases,thanqualifyingonlywithkeyfieldsandlettingABAPchecknonkey
fieldsoncethedataisreturned.
Itisalwaysmoreefficienttospecifyasmanyasthetables'keyfieldsaspossiblewhenreadingadatabasetable.TheSELECTSINGLEstatementcanbeusedtoreturnasinglerecordonlyifthefulltable
keyisspecified.
SelectstatementsthatqueryonlythenecessarycolumnsfromatablearemoreefficientthanSELECT*.
Onlythefieldsthatareneededshouldbeselectedandstoredforlateruse.Singlelineupdates(i.e.selectingdataandupdatingthatdatawithinaloop)isinefficientandshouldbeavoided.
NoSinglelineUpdates
SELECT*FROMdbtable.
WHEREcondition.
Dbtablefield=dbtablefield+delta.
UPDATEdbtable.
ENDSELECT
UPDATEdbtable
SETfield=field+delta
WHEREcondition.
UPDATEdbtableFROMTABLEitable
WHEREcondition.
Useofaggregatefunctionsismuchfasterthancomputingtheaggregateswithintheprogram.Networktrafficisalsosignificantlyreducedbyusingaggregates.UseAggregateFunctions
Total=0
SELECT*FROMdbtable.
WHEREcondition.
Total=total*dbtableamount.
ENDSELECT.
SELECTSUM(amount)

https://wiki.scn.sap.com/wiki/display/ABAP/Performance+Tuning

2/6

11/8/2016

PerformanceTuningABAPDevelopmentSCNWiki

INTOtotalFROMdbtable
WHEREcondition.
TheSELECTDISTINCTstatementrequeststhattheresultsetbeuniqueandthereforeresultinaconsiderablereductionintheamountofdatatransportedfromthedatabasetotheapplicationserver.
UseSELECTDISTINCT
SELECTDISTINCTfield1
INTOifield1FROMdbtable
WHEREfield2>value2.
....
ENDSELECT.
DatabasecallscanbesavedbyperformingarrayprocessingforSELECT,INSERT,UPDATEandDELETEusinginternaltables,orwithUPDATE/DELETEstatementswhichselectasetofrecordsusinga
condition.ThesimplestandunfortunatelymostwidelyspreadwaytoreaddatafromlogicallylinkedtablesiswithanestedSELECTstatement.ThissolutionhasthegreatdisadvantagethataSELECTis
executedinthedatabaseandthispossiblyalsoonthenetworkforeachrecordthatisprocessedintheouterSELECTloop.Ifthehitlistdefinedbytheouterselectionisverylarge,therewillbeextremely
high
communicationcostsfortheapplicationanddatabaseservers.
TheSELECT...FORALLENTRIESpermitsarrayorientedprocessingonthedatabase.Thissyntaxpermitsmorethanonerecordtobereadfromthedatabaseatonetime.Thisprovidesadistinct
advantageoverthenestedSELECTapproach.
Useofasubquery,thedatasetisfilteredwithinthedatabaseinsteadofwithintheABAPprogram,therebylimitedtheamountofdatatransferredbetweenthedatabaseandtheapplication.
KeeptheNumberofDataTransfersSmall
1.Usearrayoperations.
2.AvoidnestedSELECTs.
3.UseFORALLENTRIES
4.Usesubquery
5.UseJoins
6.UseVIEWs
Ajoinhasanadvantageinthatonlyonestatementisexecutedinthedatabase.Whendefinedproperly(i.ejoinonkeyfieldsonly,usinganindex,includingonthenecessaryfields,limitingthenumberof
tables)ajoincanofferaperformance
increase.TwotypesofjoinsareprovidedbySAP,INNERJOINandLEFTOUTERJOIN.
ViewsarecreatedintheABAPdictionary.Essentially,theyarereusableINNERJOINdefinitionsthatcanbebufferedinamannersimilartointernaltables.
Arrayoperations(i.e.specifyingdatatobeinsertedordeletedinaninternaltableandthenprocessingtheINSERTorDELETEwithasingleSQLstatement)ismuchmoreefficientthatembeddingthe
INSERTorDELETEwithinaloop.
UseArrayOperations
LOOPATitable.
INSERTINTOdbtableVALUESitable.
ENDLOOP
INSERTdbtableFROMTABLEitable
ACCEPTINGDUPLICATEKEYS.
*ArrayoperationsarealsopossiblewithSELECT,
UPDATEandDELETE.
NestedSELECTstatementsshouldbeavoidedbecausetheyareveryslow.Severalcursorsinthedatabasehavetobemaintained.Additionally,theyarehardertodebugbecausethecursortendstobe
losteasilyduringdebugmode,causingtheprogramtoabend.AcommonmethodforavoidingnestedSELECTstatementsistoreaddatadirectlyintoaninternaltableandthenuseLOOP...ENDLOOPto
processtheinternaltable.However,thisisnotalwaystheanswer.Thecorrectmethod(nestedSELECTstatementsv.internaltables)canonlybechosenafterperformingruntimeanalysisonbothoptions.
Inmanycases,acombinationofthetwomethodswillworkbest.ThekeybenefittousingSELECT...INTOaninternaltablev.usingnestedSELECTstatementsisthatthenumberofaccessestothe
databasetableissignificantly
reduced.However,ifthedatabeingselectedwillonlybeusedonceanditisasmallamountofdata,theuseofaninternaltablemaybeoverkill.
AvoidNestedSelects
SELECT*FROMdbtable1
WHEREcondition.
SELECT*FROMdbtable2
WHEREcondition.
....
ENDSELECT.
....
ENDSELECT.
NOTE:WhenusingthesyntaxFORALLENTRIES,itisimportanttofirstensurethat
theinternaltableisnotinitial.Iftherearenoentriesintheinternaltable,that
portionoftheWHEREclausewillbeignored.
UseFORALLENTRIESandSubqueries
SELECTfield1FROMdbtable1
INTOTABLEitable
WHEREcondition.
IFNOTitableISINITIAL.
SELECT*FROMdbtable2
FORALLENTRIESINitable
WHEREfield2=itablefield1
...
ENDSELECT.
ENDIF.
SELECT*FROMdbtable2
WHEREfield2IN
(SELECTfield1FROMdbtable1

https://wiki.scn.sap.com/wiki/display/ABAP/Performance+Tuning

3/6

11/8/2016

PerformanceTuningABAPDevelopmentSCNWiki

WHEREcondition).
...
ENDSELECT.
Aviewshouldbecreatedwhenappropriatetoeliminateseveralnestedselectstatements.Aviewisavirtualtablethatisnotstoredondiskbutisinsteadderivedfromoneormoretables.JOINScanalso
beusedwhenappropriatetoeliminateseveralnestedselects.
UseJoinsandViews
SELECTdbtable1~field1dbtable2~fieldn
FROMdbtable1INNERJOINdbtable2
ON(dbtable1~field1=dbtable2~field1)
WHEREcondition.
...
ENDSELECT.
SELECT*FROMv_dbtable1_2
WHEREcondition.
...
ENDSELECT.
AlldatabasesystemscopebestwithEQconditionswhicharelinkedwithAND.UseasmayEQconditionsaspossibleineachSQLstatementinordertolimittheamountofdatatobesearched.TheOR
conditionandtheuseofrangetablescanadverselyimpactperformance.TheNOTconditionshouldbeusedverycarefully.Thereisnoindexsupportforthe
NOTcondition.Indexesshouldbedesignedinordertohavethegreatestimpactonperformance.Tabledesignshouldequalindexdesign.Mostselectivefieldsshouldbelistedfirst.SmallindexesNottoo
manyindexes!
KeeptheDatatobeSearchedSmall
a)UseasmanyEQinWHEREclauseaspossible.
b)BecarefulwithORandrangetables.
c)BecarefulwithNOT.
d)Indexdesign.
Whenselectingdatafromclusterandpooltables,theWHEREclauseshouldbelimitedtokeyfields,insequence.Forexample,ifdbtable1iskeyedbyf1,f2,f3andf4,andonlythevaluesoff1,f2andf4are
available,itisbettertoignoref4andconstructtheWHEREclauseusingf1andf2only.Whenselectingdatafromaclusterorpooltablewherethekeyfieldvaluesarenotavailable,itisbettertoselectthe
entiretableintoaninternaltablewithintheABAPprogram.
UseasmanyEQinWHEREclauseaspossible
SELECT*FROMdbtable1
WHEREfield1=value1
ANDfield3=value3
...
ENDSELECT
SELECTfield2FROMdbtable2
INTOTABLEitable2
WHEREfield1=value1.
SELECT*FROMdbtable1
FORALLENTRIESinitable2
WHEREfield1=value1
ANDfield2=itablefield2
ANDfield3=value3.
...
ENDSELECT.
Avoidtheuseofrangesinselects.Whilethisisunrealisticinmanycases,alimitof8KoracleselectstatementexistsandlargerangeswillcauseABAPprogramstoabendinproduction.(Astimegoeson
therangevaluestendtogrowandlargerandlargerSQLstatementsarecreated.)AvoidtheuseofNOTasindexsupportisnotprovided.
BecarefulwithOR,RangeTablesandNOT
SELECT*FROMdbtable1
WHEREfield1=value1
ANDfield2INitable
ANDfield3=value3
...
ENDSELECT
SELECT*FROMdbtable
WHEREfield1=value1
ANDfield2=value2
ANDNOT(field3INvalue3a,value3b).
...
ENDSELECT
Anindexisasearchhelptofinddatainthedatabase.Everydatabasetablehasaprimaryindexconsistingofallkeyfields.
Adatabasecanhavesecondaryindexes.ThesearedefinedintheABAPdictionary.Upto16indexescanbecreatedbecareful!!Whentocreateasecondaryindex.Fieldsareselectedwithoutindex
support.Onlyasmallpartofthetable(<5%)isselected.WHEREclauseiseasy(ANDsonly).OftendoSORTswithoutindexsupport.
IndexDesign
a)Indexmustbeselective.
b)Keepthenumberoffieldssmall.
c)Mostselectivefieldsfirst.
d)Createtheindexforthemaincase.
Inordertogetthebestusageofanindex,specifyallindexfieldswithintheWHEREclause"withoutgaps"(i.e.ifthe1stand3rdfieldsofanindexarespecified,onlythe1stonewillbeused,ifthe1stand
2ndfieldsarespecified,bothfieldswillbeused).ThecolumnsspecifiedintheWHEREclauseshouldalsobeinthesameorderastheyarespecifiedintheindex.ThisallowstheABAPSQLinterpreterto
morequicklyconvertaSELECTintoanOraclestatementandchosethecorrectindex.

https://wiki.scn.sap.com/wiki/display/ABAP/Performance+Tuning

4/6

11/8/2016

PerformanceTuningABAPDevelopmentSCNWiki

IndexUsageGuidelines
1.Specifyfieldvalueswithoutgaps.
2.DonotuseanORoperatorforafieldwhichisrelevantfortheindex.
3.UseFORALLENTRIESINinsteadofIN,asINisinterpretedlikeOR.
4.ConstructVIEWswithindexusageinmind.
5.UnderstandhowNULLvaluesarehandledforthespecificDBMSinuse.
ORDERBYv.SORT:SortsshouldbedoneinABAPandnotinthedatabase.Sortsonthedatabaseserverwilleffectallusers.Theexceptionishugesetsofdata(e.g.>10MB).Inthecaseoflargedata
sets,theDBMScanuseanindexandprocessmoreefficiently.Also,ifanindexcanbeusedforthesorting,thereishardlyanyadditionalcostforsortingonthedatabaseserver.
DISTINCTv.ABAPSORT+DELETEADJACENTDUPLICATES:UseofDISTINCTrequiressortingonthedatabaseserverandisrelativelyexpensiveifnoindexcanbeused.ThereforetheDISTINCT
specificationonlymakessenseifthefullkeyisnotspecifiedorwhenaccessingviaviews.
Takeloadoffdatabasewherepossible
a)Tablebuffering.
b)Avoidrepeatedreadingofdata.
c)ORDERBYv.SORT
d)DISTINCTv.DELETEADJACENT
e)LogicalDatabases
Toavoidexpensivetypeconversions,alwaysspecifyatypeforformalparametersinsubroutines.
ABAP"Expensive"ThingstoAvoid
a)Nestedloops
b)Deeplynestedinternaltables
c)Hugeinternaltables.
d)SORTwithoutusingBY
e)APPEND/COLLECT...SORTEDBY
f)READTABLEtWITHkeyK.
g)Insertofreportsdynamically.
h)TypeConversions
i)FieldswithtypeP
Abinarysearchbreaksatableintologicalunitsbasedonthekeydefined.ThisallowstheREADtojumpthroughthetabletofindtherequiredentryinsteadofsequentiallyreadingeachtablerowuntilthe
requiredentryisfound.(Note:The
internaltablemustbesortedinordertousethebinarysearchqualifier).
UseCONTINUE,CHECKandEXITtoterminateloopsandlooppassesappropriatelyandtoeliminateanyunnecessaryprocessing.Useworkareasinsteadofheaderlines(implicitworkareas)when
workingwithinternaltables.
GuidelinesforInternalTables
a)Readwithindexorbinarysearch
b)Nonestedloop
c)EXITfromloop
d)FilltablesortedinsteadofusingSORT
e)ChoosesuitableINITIALSIZEparameter
f)Useexplicitworkareas.
g)DELETEexplicitlinesinsteadoflooping.
h)APPENDING/copyinginsteadoflooping.
i)MODIFY...TRANSPORTINGinsteadoflooping.
BufferingOverview
TherearethreetypesofbufferingthatcanbeusedwithSAPdatabasetables:Resident/FullBufferingWithresidentbuffering,theentiretableisstoredinthebuffer.Assoonasareadaccessismadeto
thetable,allrecordsaretransferredtothebuffer.Tablesbestsuitedtothistypeofbufferingaresmall,frequentlyreadandrarelyupdated.GenericBufferingWithgenericbuffering,onlyrecordscontaining
akeythatcorrespondstoarecordthathasalreadybeenreadareloadedintothebuffer.Assoonasareadaccessismadetothetable,allrecordswhosekeyvaluesmatchthespecifiedkeyvaluesofthe
recordbeingreadareloadedintothebuffer.Atableshouldbebufferedgenericallyifusuallyonlycertainareasofthetablearerequired.Theindividualgenericareasaretreatedlikeindependenttableswhich
arefullybuffered.PartialBuffering/SingleRecordBufferingWiththiskindofbuffering,onlytherecordsofatablewhichareactuallyaccessedareloadedintothebuffer.
ThefollowingstatementsdonottakeadvantageofanySAPtablebuffering.What
thismeansisthatevenifatableisbuffered(eitherresident/full,generic,orpartial),
executingoneoftheabovestatementsagainstthattablewillbypassthebufferand
godirectlytotheversionofthetablestoredinthedatabaseinordertoresolvethe
statement.
SQLStatementsBypassingBuffer
1.SELECT...BYPASSINGBUFFER
2.AnySELECTfromaVIEW(exceptaprojectionview).
3.SELECTFORUPDATE...
4.Aggregatefunctions(e.g.COUNT,MIN,MAX,SUM,AVG).
5.SELECTDISTINCT...
6.WHERE...ISNOTNULL
7.ORDERBY(otherthanprimarykey)
8.GROUPBYorHAVING
9.Subqueries
10.Joins
11.AnynativeSQLStatement(EXECSQL)

Nolabels

1ChildPage

AdvancedPerformanceOptimizationTechniques

ContactUs
Privacy

SAPHelpPortal
TermsofUse

LegalDisclosure

Copyright

https://wiki.scn.sap.com/wiki/display/ABAP/Performance+Tuning

FollowSCN

5/6

11/8/2016

PerformanceTuningABAPDevelopmentSCNWiki

https://wiki.scn.sap.com/wiki/display/ABAP/Performance+Tuning

6/6

You might also like