Professional Documents
Culture Documents
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
SAPapplicationperformance
ABAPprogrammingperformancetips
andtricks
PostedonMay11,2014
WhenyouarecodinganABAPprogram,youoftenfindthattheABAPprogramcanbecoded
indifferentwaystodothesamejob,youarewonderingwhichwaywouldgiveabetter
performance.WhenyouaretuningtheABAPprogramperformance,youencounteran
expensiveABAPstatementinSAPST12/SE30trace,youarewonderingwhyitisso
expensiveandwhatareotherBAPcodingalternativestoreplacetheexpensiveoneto
improvetheABAPprogramperformance.TipsandtricksutilitybuiltinstandardSAP
transactionSAT/SE30mighthelpyouwiththosequestions.SAPSAT/SE30iscomparing
performanceofcommonABAPtechniques/statementsusedbyABAPdevelopersviaABAP
performanceexamples.SounderstandingthosetripsandtrickscanhelpABAPdevelopersto
avoidcommonperformancepitfallsduringABAPprogramdevelopmentphase.Itcanalso
helpyouwhenyouneedtotuneABAPprogramperformance.Thispostwouldcover
1. IntroductionofABAPperformancetipsandtricks,
2. HowtoaccessABAPperformancetipsandtricksexamples,
A. PreferredcodingtechniquesforSAPSQLinterfacedatabasetable
access,
B. PreferredcodingtechniquesforABAPinternaltableaccess,
3. HowtouseperformancetipsandtricksexamplesinABAPprogramdevelopmentand
performancetuning.
1IntroductionofSAPABAPperformancetipsandtricks
SAPSE30/SATorganizesABAPcodingperformancetipsandtricksintofollowinggroupsor
categoriestomakeiteasierforyoutoidentifyspecificABAPcodetechniques.SeeTable1
forgroupsandtheirexplanation.
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
1/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
Table1ABAPperformanceTipsandTricksGroup
Performance
Explanation
Tips/Tricks
Group
SQLinterface
Explainwhichdatabaseaccesstechniquewouldgivebetter
performancebycomparingpairsofDatabasetableaccess
techniques:Select+checkvsSelect+Where,SelectandExitvs
SelectUpto1Rows,Find,SelectArrayselectvssingleselect,
readwithoutindexvsreadwithindex,individualoperationandmass
operationetc.
Context
Obsoleted.Ifapplicableinyourversion,usingcontextisbetterthan
selectsincecommonaccesseddataisstoredinthememoryand
sharedacrossSAPtransactions.
InternalTables
Explainwhichinternaltableaccesstechniquewouldgivebetter
performancebycomparingpairsofkillslikebinaryreadvskeyread,
individualtableoperationvsmassinternaltableoperationetc.
Typing
Explainthatparameters/fieldsymbolswhosetypesarespecifiedis
moreefficientthanparameterswhosetypesarenotspecified.
If,Case
ExplainthatcasestatementismoreefficientthanIFstatement
FieldConversion
Explainthatweshouldavoidunnecessaryfieldconversionbyusing
thesamedatatype.
Character/String
Explainthatusingstringisbetterthancharacterfromperformance
Manipulation
pointview
ABAPObjects
Explainthatcallmethodandcallsubroutinehasnomaterial
performancedifferencebutcallingFMisslowerthanMethod.
Ifyouneedtoreadarecordfrombiginternaltable,youcanreaditviakeyorbinarysearch,
thenyoucangotointernaltablegrouptowhichoneisbettertoyoursituation.
TwogroupsinefficientSQLstatementsandinefficientABAPinternaltableoperationare
highlightedbasedonmyexperience.TheyareoftenculpritofbadABAPprogram
performancerelatedtocoding.Sofamiliarwithperformancecodingtechniquesunderthese
twogroupsshouldhavepriorityoverothergroups.
2HowtoaccessABAPperformanceTipsandTricks
ToaccessSAPABAPperformancetipsandtricks,youneedtoexecuteSAPtransaction
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
2/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
SAT/SE30,thenclickonbuttonTips&Tricks.
Figure1SE30/SATinitialscreen
IfyouclickbuttonTipsandTricksbuttonhighlightedinFigure1,performancetipsand
tricksforABAPobjectsscreenlikebelowFigure2wouldbedisplayed.
Figure2Se30/SATPerformanceTipsandTrickInitialscreen
IwouldcovermoredetailsrelatedtohighlightedgroupsSQLinterfaceandInternaltable
below.
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
3/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
2.1PreferredPerformancecodingtechniquesforSAPSQLinterface/databasetable
access
Thisgroupwouldexplainpreferredcodingtechniqueoutoftwodifferentwaysoftable
access.PleaserefertoTable2fordetails
Table2SQLinterfacepreferredSQLcodingstrategy
ITEM
Performance
Explanation
preferred
Select+checkVS.
Selectwithwhere
Useasmuchfieldsaspossibleinwhere
Selectwithwhere
conditions
clause:indexmightbepossiblewiththe
conditions
fieldsandfilterearliertoavoid
unnecessarydatatrafficbetweenDB
serverandapplicationserver
Select+exitVs.
Selectwithupto1
Selectwithupto1rowswouldincurless
SelectwithUpto1
rows
trips/trafficbetweenDBandApplication
rows
server.
Select+checkVS.
Selectusing
AvoidroundtripbetweenDBserverand
Selectusing
Aggregatefunction
applicationserver,reducetraffic
Select*Vs.Select
Selectwithalistof
Reduceroundtripandtrafficbetween
withalistoffields
fields
applicationserveranddatabaseserver
UpdateonerowVS
Updatewith
Reducenetworktraffic
updatespecifiedfield
specifiedfields
Selectwithoutindex
Selectwithindex
Aggregatefunction
VSSelectwithindex
UsinganIndexwouldreducenumberof
logicalDBreads,soitwouldbefaster
thanafulltablescanwhenlimited#of
recordsarefetched.
Selectwithoutbuffer
Selectwithbuffer
supportVSselectwith
Readingbuffercouldbeupto100time
fasterthanreadfromdbdisc.
buffersupport
SelectwithAppend
Selectintotable
statementVSselect
ReduceroundtripsbetweenDBand
applicationserver
intotable
Manyindividualinserts
Arrayinsert
VSArrayinsert
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
ReduceroundtripsbetweenDBand
applicationserver
4/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
Select+EndselectVS
Selectintotable+
Reduceroundtripsbetweendbserver
Selectintotable+
looptable
andapplicationserversaswellas
looptable
NestedSelect
networktraffic
Selectwithview
Reduceroundtripsbetweendbserver
StatementVSSelect
andapplicationserversaswellas
withview
networktraffic
NestedSelect
Selectwithjoin
Reduceroundtripsbetweendbserver
statementVSSelect
andapplicationserversaswellas
withJoin
networktraffic
UsingtwoSelectsVS
Selectwith
Reduceroundtripsbetweendbserver
Selectusinga
subquery
andapplicationserversaswellas
subquery
networktraffic
Infollowingsection,IwouldgothroughsomeSQLperformanceexamples.
2 . 1 . 1 S E L E CT + CHE CK V S S E L E CT WI TH WHE RE CO NDI TI O NS
IclickedSQLinterfacegroupandallchildgroupsunderSQLinterface,thenIclicked
SelectWhereVs.Select+Check,IgotscreenlikeFigure3.
Figure3ABAPperformanceexampleSELECT+CheckVsSelect+Whereclause
Thedisplayisdividedinto3portionsinFigure3,leftpanelnavigationtodifferentgroupand
ABAPcodeperformancetechniques,RightupperwindowisshowingtwosampleABAP
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
5/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
codesusingtwocodesolutionswhichachievesameresult.Rightbottomwindowexplains
whatistheperformancepreferredABAPcodingtechnique.
BasedonexplanationinFigure3,itisclearthatselectwithwhereconditionshasbetter
performancethanselect+check.Inanotherword,thesamplecodeatrightinfigure3
shouldhavebetterperformancethanABAPsamplecodeintheright.Isthattrue?Youcan
actuallytestthistogetafeelingbyclickingMeasureRuntimebuttoninFigure3.Upon
clickingit,IgotFigure4screen.
Figure4ABAPperformanceexampleSelect+checkvsselectwithwhereconditions
Inthisparticularcare,timespentbySelect+checkexamplecodeis10timeslongerthan
timespentbyselectwithwhereclauseexamplecode.
Inthesamefashion,youcannavigatetootherSQLcodingtechniquestogetafeelingof
performancedifferencecreatedbydifferentABAPcodingtechniquesviasamplecodes.
2 . 1 . 2 S E L E CT WI THO UT B UFFE R S UP P O RT V S S E L E CT WI TH B UFFE R S UP P O RT
Figure5showsthatReadingdatafromapplicationbufferis10timesfasterthanreadingdata
fromdatabasesystem.
Figure5ABAPperformanceexampleSelectwithoutbuffersupportvsSelectwithbuffer
support
2 . 1 . 3 S E L E CT I NTO TA B L E + L O O P A T TA B L E V S . S E L E CT E NDS E L E CT
SelectintotableismuchmoreefficientthanSelectEndselect.Selectintotableneeds
morememorytoholdtheresultset.Innormalsituation,thisisnotaconcern.When
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
6/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
memoryisaconcern,youcandividetheresultsetintosmallersets.
Figure6ABAPperformanceexampleSelectIntotable+loopattableVSSelect..ENDSelect.
2 . 1 . 4 A RRA Y / MA S S I NS E RT V S S I NG L E RO W I NS E RT
Array/MassInsertisalwaysbetterfromperformancepointviewsinceitcanreduce
unnecessaryroundtripsbetweendatabaseandapplicationserverbyutilizingfullcapacityof
datacommunicationbusbetweendatabaseandapplicationserver.Itcanalsoallow
database
Figure7ABAPperformanceexampleSinglelineinsertVSArrayInsert
2 . 1 . 5 NE S TE D S E L E CTS V S S E L E CT WI TH V I E W
SelectwithviewalwaysperformancesbetterthanNestedSelect.
Figure8ABAPperformanceexampleNestedSelectVSSelectwithView
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
7/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
2 . 1 . 6 NE S TE D S E L E CT V S S E L E CT WI TH J O I N
SelectwithjoinalwaysperformancesbetterthanNestedselected.
Figure9ABAPperformanceexampleNestedSelectVsSelectjoin
2.2PreferredPerformancecodingtechniquesforABAPinternaltableoperation
PleaserefertoTable3forsomeABAPcodetechniqueswhichareimportanttoapplication
performance.TheyareselectedfromwhatofferedbySAPSAT/SE30tipsandtricksbased
onmyperformanceexperience.
Table3SAT/SE30ABAPinternaltablehandlingperformancetipsandtricks
ITEM
Performance
Explanation
preferred
LinearsearchVS
Binarysearch
Binarysearch
Ifinternaltablesareassumedtohavemany
(>20)entries,alinearsearchthroughallentries
isverytimeconsuming.Trytokeepthetable
orderedandusebinarysearchorusedatableof
typeSORTEDTABLE.IfTABhasnentries,linear
searchrunsinO(n)time,whereasbinarysearch
takesonlyO(log2(n)).
SecondaryindexVs
Usingsecondary
Whenaninternaltableisaccessedwithdifferent
NoSecondary
indexforrepeated
keysrepeatedly,createyourownsecondary
accesses
index.Withasecondaryindex,youcanreplacea
linearsearchwithabinarysearchplusanindex
access.
LOOPinternaltable
Loopwhere
LOOPWHEREisfasterthanLOOP/CHECK
andCHECKVS
becauseLOOPWHEREevaluatesthespecified
LOOPWHERE
conditioninternally.Aswithanylogical
expressions,theperformanceisbetterifthe
operandsofacomparisonshareacommontype.
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
8/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
Theperformancecanbefurtherenhancedif
LOOPWHEREiscombinedwithFROMi1
and/orTOi2,ifpossible.
SortedtableVS
Sortedtablefor
Hashedtablesareoptimizedforsingleentry
HashedTable
repeated
access.Theentrieshavenospecificorder.
accesses.Hashed
Therefore,apartialsequentialaccesscannotbe
tableforsingle
optimized.Everyentrymustbecheckedtomatch
access
thecondition(fulltablescan).Sortedtablesare
orderedascendinglybytheirkeycomponents.If
apartialkeyoftheformk1=v1ANDANDkn
=vnwherek1..knmatchesaleftpartofthe
tablekey,theaccessisoptimizedbythekernel.
Inthatcase,onlythematchingentriesare
visited.
Copyingatablevia
Equaloperation
InternaltablescanbecopiedbyMOVEjustlike
loopVSequal
better
anyotherdataobject.
Ifaninternaltableitabhasaheaderline,the
tableitselfisaccessedbyitab[].
JointableLoop
Looptable1then
IfITAB1hasn1entriesandITAB2hasn2entries,
table1thenread
read2nd tablewith
thetimeneededforjoiningITAB1andITAB2
table2VSloop
anindex
withthestraightforwardalgorithmisO(n1*
table1thenread
log2(n2)),whereastheparallelcursor
table2withindex
approachtakesonlyO(n1+n2)time.The
aboveparallelcursoralgorithmassumesthat
ITAB2isasecondarytablecontainingonlyentries
alsocontainedinprimarytableITAB1.Ifthis
assumptiondoesnothold,theparallelcursor
algorithmgetsslightlymorecomplicated,butits
performancecharacteristicsremainthesame.
Infollowingsections,performancecodeexamplesfromSAT/SE30arecoveredforselected
topics.
2 . 2 . 1 RE A D I NTE RNA L TA B L E V I A K E Y V S RE A D I NTE RNA L TA B L E V I A B I NA RY S E A RCH
Figure10showItismoreefficienttoreadaninternaltableviabinarysearchifthetable
entriesishuge.Thisbenefitmightbemoresignificantifyouneedtoreadthetablemany
times.
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
9/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
Figure10ABAPperformanceexampleLinearagainstBinarysearchinaninternaltable
Readinganinternaltableusingasecondaryindexcouldbemoreefficientthanreadviaa
key.
Figure11ABAPperformanceexampleReadinternaltableusingindexVSnoindex
Readinganinternaltablewithloopwherestatementsismoreefficientthanloop+check
statements.
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
10/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
Figure12ABAPperformanceexampleLoopandCheckVSLoopwhere
Whenyouneedtoreadtheinternaltablemanytimes,usingsortedtableismoreefficient
thanusinghashedtable.
Figure13ABAPperformanceexampleSortedtableVSHashedtable
2 . 2 . 5 CO P Y I NTE RNA L TA B L E L O O P + A P P E ND A ND CO P Y V S =
Using=tocopytableismoreefficientthanusingLoop+appendtocopyaninternaltable.
Figure14ABAPperformanceexamplecopyinternaltable
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
11/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
2 . 2 . 6 JO I N I NTE RNA L TA B L E S L O O P TA B L E 1 A ND RE A D TA B L E 2 A G A I NS T L O O P TA B L E 1
A ND RE A D TA B L E 2 V I A I NDE X
Usingmethodofloopingtable1thanreadingtable2viaINDEXismoreefficientthanmethod
ofloopingtable1thenreadingtable2withoutindex.
Figure15ABAPperformanceexamplejoininternaltables
3TestingperformanceofyourownABAPcodes
IhaveseenABAPdevelopertocompareperformanceoftwodifferentsetsofABAPcode
whichachievethesamepurposeviaSE30.ItlookslikethatthiscanbedoneviaSAT/SE30
menupathEDIT>Editing>LEFThand/RightHandasshowedinFigure16.Idonothave
authorizationtodothisinthesystemIowned..Readerslikeyoucanexplorethismore
shouldyoubeinterestedinit.
Figure16SAT/SE30yourownsamplecodes
4FurtherInformation
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
12/13
20/12/2014
ABAPprogrammingperformancetipsandtricks|SAPapplicationperformance
ASAPABAPprogramperformancecanhavemanycontributingfactorslikesolutiondesign,
functionalconfigurationandprogramcodefromapplicationperformancepointview.An
applicationperformanceissuecanberootedfromdatabaseperformance,systemcapacity,
network,IOdesignaswell.SAPperformancetipsandtrickscannothelptoimproveABAP
programperformanceissuewhichisrootedfromsolutiondesign,functionalconfiguration,
databaseperformanceissueandetc.Itcanhelptoverifywhetheraprogramperformance
issueisrootedfromprogrammingtechniques.Inmyexperience,over50%ofABAPprogram
performanceissuesarerelatedtoprogramcode.SoitisimportantforaSAPdeveloperto
becomefamiliarwiththoseperformanceexamplesandperformancepreferredABAPcoding
techniques.
Again,notallperformanceexamplesfromSAPSAT/SE30arecoveredhere.Myintentionis
tocovermostcommon/criticalexamplesbasedonmyexperiences.YoucanrunSAP
SAT/SE30onlinetoreviewtheremainingABAPperformanceexamples.Also,SAT/SE30
coverscommonperformancesexamples.TherearemanywaystoputABAPstatement
togetherforthesamepurpose.ItisnottheexpectationthatSAT/SE30providesaexamples
foreachsituation.
SE30allowsyoutodoABAPruntimeanalysisbutitwouldnotprovidemuchdatatosupport
SQLperformance.MypreferredtooltodoABAPprogramruntimeanalysisisSAP
transactionST12whichIfindefficienttodoperformanceanalysisonABAPlogicoperation
anddatabaseaccess.ImightcomeoutapostonhowtouseSE30todoABAPruntime
analysisinthefuture.
IhavefollowingpostsrelatedtoSAPprogramperformance:howtoimproveaSAPABAP
programperformancehowtorunSAPST12todoaperformancetracehowtoanalyze
ABAPtracehowtoanalyzeSQLtrace
ThisentrywaspostedinSAPdevelopmentandtaggedSAPABAPprogramming
performancetipsandtricksSAPABAPprogramperformanceexamplesSAPABAP
performancecodingtechniquesbyeric.Bookmarkthepermalink[http://www.sap
perf.ca/abapprogrammingperformancetipsandtricks/].
http://www.sapperf.ca/abapprogrammingperformancetipsandtricks/
13/13