Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ABAPPerformanceandTuningABAPDevelopmentSCNWiki
GettingStarted
CommunityWIKI
SAPCommunity
Welcome,Guest
Login
Store
Register
ABAPDevelopment
ABAPPerformanceandTuning
CreatedbyGuest,lastmodifiedbyMatthewBillinghamonNov20,2013
Whattoolscanbeusedtohelpwithperformancetuning?
WhatarethestepstooptimisetheABAPCode?
WhatisthedifferencebetweenSELECTSINGLEandSELECT...UPTO1ROWS?
WhichisthebetterJOINSorSELECT...FORALLENTRIES...?
DoesSAPpublishguidesandcookbooksonperformancemonitoringandtesting?
#Avoiduseofnestedloops
Whattoolscanbeusedtohelpwithperformancetuning?
ST05istheperformancetrace.ItcontaintheSQLTraceplusRFC,enqueueandbuffertrace.MainlytheSQLtraceisisusedtomeasuretheperformanceoftheselectstatementsoftheprogram.
SE30istheRuntimeAnalysistransactionandcanbeusedtomeasuretheapplicationperformance.
SATtransactionisthereplacementoftheprettyoutdatedSE30.ProvidessamefunctionalityasSE30plussomeadditionalfeatures.
ST12transaction(partofSTA/PIsoftwarecomponent)isacombinationofST05andSAT.VerypowerfulperformanceanalysistoolusedprimarilybySAPSupport.
OneofthebesttoolsforstaticperformanceanalyzingisCodeInspector(SCI).Therearemanyoptionsforfindingcommonmistakesandpossibleperformancebottlenecks.
backtotop
WhatarethestepstooptimizetheABAPCode?
1.DATABASE
a.UseWHEREclauseinyourSELECTstatementtorestrictthevolumeofdataretrieved.Veryimportant!!
b.DesignyourQuerytoUseasmuchindexfieldsaspossibleinyourWHEREstatement
c.UseINNER(orOUTERundersomecircumstances)JOINinyourSELECTstatementtoretrievethematchingrecordsatoneshot
d.AvoidusingnestedSELECTstatementandSELECTwithinLOOPs,betteruseJOINsorFORALLENTRIES.UseFORALLENTRIESwhentheinternaltableisalreadythereortheendof
someprocessing.TryJOINsiftheSELECTarerightbehindeachother
e.AvoidusingINTOCORRESPONDINGFIELDSOFTABLEduringbufferedaccess.Otherwiseusethemostappropriatefortheprogram.
f.AvoidusingSELECT*andSelectonlytherequiredfieldsfromthetable.
g.AvoidusingORDERBYinSELECTstatementsifitdiffersfromusedindex(instead,sorttheresultinginternaltable),becausethismayaddadditionalworktothedatabasesystem
whichisunique,whiletheremaybemanyABAPservers
h.INDEX:CreationofIndexforimprovingperformanceshouldnotbetakenwithoutthought.Indexspeedsuptheperformancebutatthesametimeaddstwooverheadsnamelymemoryand
insert/appendperformance.WhenINDEXiscreated,memoryisusedupforstoringtheindexandindexsizescanbequitebigonlargetransactiontables!Wheninsertingnewentryinthe
table,alltheindex'sareupdated.Moreindexmoretime.Moretheamountofdata,biggertheindices,largerthetimeforupdatingalltheindices
i.AvoidExecutinganidenticalSelect(sameSELECT,sameparameter)multipletimesintheprogram.Bufferinyourabapcode.
j.Avoidusingjoinstatementsifadequatestandardviewsexistnoperformanceimpact
2.TABLEBUFFER:
a.Definingatableasbuffered(SE11)canhelpinimprovingtheperformancebutthishastobeusedwithcaution.Bufferingoftablesleadstodatabeingreadfromthebufferratherthanfrom
table.Buffersyncwithtablehappensperiodically,onlyifsomethingchangeswhichishappenrarely.Ifthistableisatransactiontablechancesarethatthedataischangingfora
particularselectioncriteria,thereforeapplicationtablesareusuallynotsuitedfortablebufferung.Usingtablebufferinginsuchcasesisnotrecommended.UseTableBufferingfor
configurationdataandsometimesforMasterData..
b.AvoidusingcomplexSelectsonbufferedtables,becauseSAPmaynotbeabletointerpretthisrequest,andmaytransmittherequesttothedatabaseThecodeinspectortellswhich
commandsbypassthebuffer
3.Internaltables
a.UseHASHEDtableswhereeverpossible.OtherwiseSORTEDtables.STANDARDtablesshouldbethelastchoice.
b.UseassigninsteadofintoinLOOPsfortabletypeswithlargeworkareas,ifthedataisbeingmodified.
c.WhenindoubtcalltransactionSE30andcheckyourcode.
d.IfyoumustuseaSTANDARDtableandyouareusingaREAD,sortthetableappropriatelyandusetheadditionBINARYSEARCHtospeedupthesearch.
4.Miscellaneous
a.PERFORM:Whenwritingasubroutine,alwaysprovidetypeforalltheparameters.Thisreducestheoverheadwhichispresentwhensystemdeterminesonit'sowneachtypefromthe
formalparametersthatarepassed.Italsomakesformorerobustprogramming.
backtotop
WhatisthedifferencebetweenSELECTSINGLEandSELECT...UPTO1ROWS?
SELECTSINGLEandSELECTUPTOnROWSreturnthefirstmatchingrow/rowsforthegivencondition.Itmaynotbeunique,iftherearemorematchingrowsforthegivencondition.
WithORACLEdatabasesystem,SELECTSINGLEisconvertedintoSELECT...UPTO1ROWS,thustheyareexactlythesameinthatcase.TheonlydifferenceistheABAPsyntaxpreventsfrom
usingORDERBYwithSELECTSINGLE,butitisallowedwithSELECT...UPTO1ROWS.Thus,ifseveralrecordsmaybereturnedandwewanttogetthehighestrecordforexample,SELECT
SINGLEcannotbeused,butSELECT...UPTO1ROWSWHERE...ORDERBY...maybeused.
backtotop
WhichisthebetterJOINSorSELECT...FORALLENTRIES...?
InmostscenariosINNERJOINperformsbetterthanFORALLENTRIES,andshouldbeusedfirst.OnlyifthereareperformanceissuesshouldFORALLENTRIESbeconsidered,andcareful
measurementstakenbeforeandaftertovalidatewhethertherereallyareperformancegains.
https://wiki.scn.sap.com/wiki/display/ABAP/ABAP+Performance+and+Tuning#ABAPPerformanceandTuningDoesSAPpublishguidesandcookbooksonperforma
1/4
11/8/2016
ABAPPerformanceandTuningABAPDevelopmentSCNWiki
TheeffectofFORALLENTRIESneedstobeobservedfirstbyrunningatestprogramandanalyzingSQLtrace.CertainoptionssetbyBASIScancauseFORALLENTRIEStoexecuteasan'OR'
condition.ThismeansifthetablebeingusedFORALLENTRIEShas3records,SQLTracewillshow3SQL'sgettingexecuted.InsuchacaseusingFORALLENTRIESisuseless.HoweveroftheSQL
Traceshows1SQLstatementit'sbeneficialsinceinthiscaseFORALLENTRIESisactuallygettingexecutedasanINList.
JOINSarerecommendedoverFORALLENTRIES.Thereisnoreallimittothenumberoftablesthatcanbejoinedhowevergreatercomplexitycanmakemaintenanceharder,andifthereareproblems
withthejoin,makeithardertoresolvethem.IftheJOINisbeingmadeonfieldswhicharekeyfieldsinboththetables,itreducedprogramoverheadandincreasesperformance.
Insomescenarios,youarepresentedwithaninternaltable.Inthesesituations,youmayhavenochoicebuttouseFORALLENTRIES.
Hereisacodewithjoin:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
SELECTA~VBELNA~KUNNRA~KUNAGB~NAME1
INTOTABLEI_LIKP
FROMLIKPASA
INNERJOINKNA1ASB
ONA~KUNNR=B~KUNNR.
*Forwithlimiteddatausingforallentries:
*MinimizeentriesinI_likpbydeletingduplicatekunnr.
LOOPATI_LIKPINTOW_LIKP.
W_LIKP2KUNAG=W_LIKPKUNAG.
APPENDW_LIKP2TOI_LIKP2.
ENDLOOP.
SORTI_LIKP2BYKUNNR.
DELETEADJACENTDUPLICATESFROMI_LIKP2COMPARINGKUNNR.
*GETDATAFROMkna1
IFNOTI_LIKP2[]ISINITIAL.
SELECTKUNNRNAME1
INTOTABLEI_KNA1
FROMKNA1
FORALLENTRIESINI_LIKP2
WHEREKUNNR=I_LIKP2KUNNR.
ENDIF.
backtotop
UserCollectStatementtodoSumintheinternaltable.
Insteadofusinglogictodosummationusecollectstatement.COLLECTisespeciallyefficientwithHASHEDtables.
Avoiduseofnestedloops
Forexample:ifthereisalooplikethis.Conditionadded,otherwisethereisnooptimization:
1
2
3
4
5
6
7
8
9
LOOPATITAB1.
LOOPATITAB2WHEREF1=ITAB1F1.
....
ENDLOOP.
ENDLOOP.
intheproductionenvironmentitmaybepossiblethatsuchalooptakesalotoftimeanddumps.
Insteadwecanuse...BINARYSEARCHadded,otherwisenoimprovement!!!BetterstilluseaHASHEDorSORTTABLE.
1
2
3
4
5
6
7
8
9
10
11
SORTITAB2BYF1.
LOOPATITAB1.
READTABLEITAB2WITHKEYF1=ITAB1BINARYSEARCH."f1isanyfieldofitab1
IFSYSUBRC=0.
IDX=SYTABIX.
LOOPATITAB2FROMIDX.
IFITAB2F1<>ITAB1F1.
EXIT.
ENDIF.
....
ENDLOOP.
https://wiki.scn.sap.com/wiki/display/ABAP/ABAP+Performance+and+Tuning#ABAPPerformanceandTuningDoesSAPpublishguidesandcookbooksonperforma
2/4
11/8/2016
12
13
ABAPPerformanceandTuningABAPDevelopmentSCNWiki
ENDIF.
ENDLOOP.
Ifyouhaveasortedtabletheinternaltablecanbereadlikethis:
1
2
3
4
5
6
7
8
9
10
11
TYPES:BEGINOFITAB,
F1TYPEMARAMATNR,
....
*NOTONLYTHEKEYFIELD!!
ENDOFITAB.
DATA:ITAB2TYPESORTEDTABLEOFITABWITHUNIQUEKEYF1.
LOOPATITAB1.
LOOPATIATB2WHEREF1=ITAB1."f1isanyfieldofitab1
....
ENDLOOP.
ENDLOOP.
tuning
performance
1ChildPage
ABAP4TuningChecklist
9Comments
Guest
WhyisitnecessarytouseCHECKinsteadofIF/ENIF?Itismoredifficulttoread.
Guest
IwouldnotrecommendusageofFORALLENTRIESforlargetables.IfusingFORALLENTRIESthanSAPBASISshouldchangeapplicationserverdefaultparametersof
rsdb/max_blocking_factor=a
rsdb/min_blocking_factor=b
rsdb/max_in_blocking_factor=c
rsdb/min_in_blocking_factor=d
SeeSAPHINT881083.Ifpossibleusejoinsinstead!FORALLENTRIESwastenetworkbandwidth,applicationserverCPUanddatabaseserverIOandCPU.
Guest
ihavenoticedinsapstandardprogramusingselectandendselectwhichaccordingtocodingstandardsshouldnotbeused.
cananyonetellmewhySAPusesit?
Regards,
GURU
SandraRossi
GURU,select...endselectcanbefoundinoldprogramsbecausewhenSAPcreatenewstatementsintheabapkernel,itwouldbedangerousandexpensivetorewritealltheprogramswhich
wereusingtheoldstatementstheyreplace.Youwillfindthesameissueformanymanystatements(andtechnologies,likelogicaldatabaseforexample)
AndresSarcevic
IjustconfirmedthatSELECTCOUNT(*)UPTO1ROWS...WHERE...isthebesttocheckexistance:
SELECTSINGLECOUNT(*)...WHERE...measure:318
SELECTSINGLEkeyINTO...WHERE...measure:177
SELECTCOUNT(*)UPTO1rows...WHERE...measure:141
SELECT...INTO...WHERE...ENDSELECT...measure:170
YuriZiryukin
TobehonestIfindthispageabitpoor.Toofewinformationforsuchanimportantarea.
Guest
Imustsaywhileusingforallentriesmakesureofdeletingduplicateentriesfromkeytable..
itwilleffecttheperformancetoomuch
https://wiki.scn.sap.com/wiki/display/ABAP/ABAP+Performance+and+Tuning#ABAPPerformanceandTuningDoesSAPpublishguidesandcookbooksonperforma
3/4
11/8/2016
ABAPPerformanceandTuningABAPDevelopmentSCNWiki
SivaramaKrishnaPabbraju
WhataboutLikestatementinselectquery?
>IntableMARA,wehaveastandardindex'MPN'forfieldsMFRPNandMFRNR.
Inmostofthecases,wewillhaveaselectstatementlikeSELECT(FIELDS)FROMMARAWHEREMFRPN=LV_MFRPN.
InthiscaseifIusesomethinglikeSELECT(FIELDS)FROMMARAWHEREMFRPN=LV_MFRPNANDMFRNRLIKE'%'.
Doesthisimproveperformance?HerebymentioningMFRNRintheselectquerywearematchingthefieldsofIndex.Willthisworkforperformance?
>SimilarlySELECT(FIELDS)FROMVBAPWHEREVBELN=LV_VBELNANDPOSNRLIKE'%'.Willitdobetterthan
SELECT(FEILDS)FROMVBAPWHEREVBELN=VBELN?
MarulaSiddaswamyHM
WhatistheVolumeofdataforwhichweneedtogoforBinarysearchandfortheHashtable?
ContactUs
Privacy
SAPHelpPortal
TermsofUse
LegalDisclosure
Copyright
FollowSCN
https://wiki.scn.sap.com/wiki/display/ABAP/ABAP+Performance+and+Tuning#ABAPPerformanceandTuningDoesSAPpublishguidesandcookbooksonperforma
4/4