ST12-ABAP Trace Using The Single Transaction Analysis
ST12-ABAP Trace Using The Single Transaction Analysis
ST12ABAPtraceusingthesingletransactionanalysis
SAPPractical.com
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
1/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
SAPPractical.com
Hello Guest! (/home/login)
3/6/2016 6:12:35 PM
Introduction to ST12 trace: Transaction code ST12 is similar to a combination of the standard ABAP and SQL trace transactions SE30 and
ST05.Transaction ST12 is used to to integrate ABAP and performance traces (SQL Enqueue RFC, transaction ST05) and to make thetracing and
analysis process faster and more convenient. ABAP trace with ST12 is the central entry point for performance analysis. It should be usedto
detect top-down any performance hotspot, for functional time distribution analysis, and to optimize ABAP/CPU bound issues.
This blog will show how to take a trace with ST12 and how to analyse the ST12 trace.
Before you start: We need to understand the SAP system response times which is given below.
ST12 Trace combines ABAP and performance (SQL) trace into single transaction, with major functional enhancements especially for the ABAP trace
part. In a joint switch on/off with the performance trace, ST12 allows to activate the ABAP trace for another user. ABAP and performance traces
can be activated on another server or even on all servers to catch e.g. incoming RFCs.
ST12 makes it easy to keep valuable trace results and pass them on e.g. to SAP backof ce. The ABAP trace results are completely collected to
database.
For Performance trace ST12 rememberstime-frame& server, and one click navigates directly into the ST05 trace display on the proper server.
Selected results form performance trace and other ndings can be saved as annotation texts into a traceanalysis.
The ST12 ABAP Trace Summary quickly shows the contribution of known expensive functionalities. It is also able to estimate the time contribution
of certain programs, esp. user exits and customer coding.
With ST12 the program hierarchies can be analyzed in the aggregated ABAP trace 'per call'. Therefore the non-aggregated ABAP trace with its large
trace le sizes is not needed and was omitted from ST12.
ABAP trace for beginners
ABAP traces measures two different things. The rst are certain simple and possibly expensive ABAP statements like database accesses and
statements on internal tables. These are easy to understand. The second are calls to modularization units like perform, call function/method, call
screen or PAI PBO modules. These are complex because they are hierarchical containers and resemble nested russian puppets. Their hierarchies
can branch and also merge again.
When and how to use ST12 ABAP trace?
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
2/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
SAPPractical.com
ABAP
trace was recommended only to analyze gaps in the SQLtrace or pure CPU issues. ABAP trace with ST12 can and should beused to
a) Identify top-down any performance hotspot and get an exactfunctional time distribution
Hello Guest! (/home/login)
When user executes this report then there is an ALV display, after user selecting a particular line to click print button. So time taken is from Data
selection and Internal table processing.
Note : Before activating a trace you have to run the report/transaction twice or thrice since the record selection is rst time then obviously
database response time will be bit high and it wont be any processing(internal table) time differences in ABAP.
Please close all the session except two(Report execution and ST12), If you are taking trace and the report is running by user also ne but make sure
user is using in single session.
Step 1) Go to transaction code ST12 and give comment, User name and Start trace
Step 2)Run your report/transaction and click 'End traces & collect' in ST12
Step 3)In ST12 bottom side you could see Full screen button and click it
Now select the row and click 'ABAP trace' in toolbar.Choose the 4th column(Net) and click descending button which is given below.
Actually I gave smaller input selection in selection screen so the total execution time is 91.2 seconds. If we see the above snapshot ABAP, Database
and System time is shown and we could see ABAP run-time is 88.0% and Database run-time is 12.0 so we improve both the response times
ABAP(Internal table processing) and Database. If we check the marked rectangular in above screen there are internal table processing and
database select query can be improved.
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
3/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
SAPPractical.com
Now system will take you to the respective program/object with the exact line number. In this program there is an select statement which is highest
response time(will see later).
the information will give you overview of ABAP trace Hello Guest! (/home/login)
Below
S.No
Call
Detailedexplana on
01
Call
Simplywecansaywhichstatementisexecuted
02
No.
"Number"sayshowmany mesthestatementisexecuted.likeperform,call
func on/method,callscreenorPAIPBOmodules
Gross
04
Net
05
Gross(%)
06
Net(%)
07
Program(calledprogram)
Whichprogrambeingcalled
08
Type
Typecanbelike"DB","DB>"and"Sys."
03
Title
Comments
Advantage
01
UseForAllEntries
ForallentriesisaABAPquery.UseFAEinsteadof
Ranges(whereclauseIN).BeforeusingForAllEntries
deletetheduplicaterecordsinthedrivertable.
Thismethodwillprevent
dump
02
UseJoins
Joinswillhitthedatabseatonlyonce
Resultwillbefaster
Reduc onofselectedcolumns
Avoid*selec onsandinsteadlistthecolumnnames
neededintheselec on.Especiallyexpensiveare
unnecessaryretrievalsofcolumnswithtypeSTRING.
Theresulttablecolumnsshouldbesynchronouswith
theselec onstructureforop mizedresults.Ifyouhave
moreeldsintheresulttablebutiftheeldstobe
retrievedhavebeengiveniden calnamestotheones
usedforthetable,youcanusetheaddi on
CORRESPONDINGFIELDS.Thisdoesnotcauseaddi onal
run me.Simultaneously,therobustnessofthecodeis MemorysavedandTime
improved.
consuming
Op mizedquery
Ifatallpossible,trytousealleldsofanexis ngindex
forthedatabasequery.Ifthisisnotpossible,trytoat
leasttaketherstindexeldsintoaccount.Thiswill
restrictthesequen alsearchtoasfewdatarecordsas
possible.
Systemloadwillreduced
Reduc onoflineitems
UsetheWHEREclausetorestricttheselec onandto
minimizetheamountofdatareturnedtotheABAP
system.UseSELECTSINGLE/UPTOnROWS,whenever
youonlyneedsomelines.
Existencychecks
DonotuseCOUNT(*)tondoutwhetherthereare
recordsforspecicselec oncriteria.UseSELECTSINGLE
instead,withaeldincludedintheindexaccessedfor Avoidingunwantedtable
theselec on.Thisavoidsunnecessarytableaccess.
access
03
04
05
06
Avoidingunwantedrecords
AggregateslikeMINorMAXarealwaysresolvedonthe
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
4/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
Aggregate
AggregateslikeMINorMAXarealwaysresolvedonthe
databaseserverandthetablebueringistherefore
circumvented.Thiscanpoten allycauseahighloadon
theDBsystemifitisaccessedfromseveralinstalla ons
andapplica onservers.Developersshouldtherefore
Hello Guest! (/home/login)
checkhowlargethedatavolumefortheaggregatewill
beandifitcouldmakesensei.e.,ifitisnottoolarge
torstloadthedataintoaninternaltableandthendo
theaggrega onfromthere.Wewouldliketopointout,
however,thatasfarasitisknowntoday,HANAbased
databasequeriesdohavetheirstrengthsespeciallyfor
aggrega onsandthattheirusageisthereforeexplicitly
encouragedforHANA.Example:tocalculatetheaverage
amountofalargenumber(>100,000)ofordersitmakes
sensetohavetheDBsystemdeterminethisaggregate.
Thenitwillpassonlyoneorafewitemsinsteadof
hundredsofthousandsbacktotheapplica onserverfor
calcula ngtheaverageamountinABAP.Thisis
applicableespeciallyifthiscalcula onisdonerarely
(e.g.justonceperday).If,ontheotherhand,youo en
needtodeterminethesumoftheorderposi onofa
singleorderandonallavailableapplica onservers,
Canbeusedifthedatabaseis
doingthecalcula oninABAPisusuallythebe erop on HANApla orm
08
Updates
ThecommandUPDATESETmakesitpossibletorestrict
thelistofeldstobeupdated(insteadofupda ngthe
completerecord).Thiscommandshouldbepreferredif Trytouseallupdatesusing
possible.
updatefunc onmodules
09
Eachexecu onofanopenSQLstatementcomeswitha
certainoverhead(parsing,checkingagainstthe
statementbuerintheDBMSetc.).Eachcommand
shouldthereforeretrieveasmuchdataaspossibleat
once.E.g.Ifyouneeddataof50orders,youshouldnot
getthemin50individualselectsbutyoushouldretrieve
themviaonestatementwhichsupportsthesocalled
arrayfetch.Thesecommandscanbeiden edbythe
addi onsINTOTABLEforSELECTsorFROMTABLEfor
UPDATEstatements.AvoidOpenSQLstatementswithin
loopsatallcost!Withthesetypesofconstructsyouwill
havetheoverheadforthestatementateachloop
itera on.DonotuseMODIFY!Withinanapplica onit
shouldbeclearifdatarecordswerecreatedorifexis ng
oneswereupdated.Inaddi on,thestatementis
extremelycri calfromaperformanceperspec ve.Even
withtheaddi onFROMTABLE,thedatabaseisaccessed
onceforeachlineitemintheinternaltable.Foreachof
these,anUPDATEistriedrstandifthisisnot
successful,anINSERTisdone.Ifyouhavemanynew
datarecordstoinsert,thiswillnothappenwithn
databaseaccessbutitwillbe2nwheren=thenumber
NumberofDBaccessexecu ons oflineitemsintheinternaltable.
10
NestedSELECTsandSELECTcommandsinloopsshould
beavoided.Asanalterna ve,makeuseofVIEWS,JOINS
ortheaddi onFORALLENTRIES.Pleasekeepthe
followinginmindwithFORALLENTRIES:a.Ifthe
internaltablereferencedwithFORALLENTRIESis
empty,allitemswillbeloaded.b.Iftheinternaltable
containsduplicateentries,itispossiblethattherelated
datarecordswillbeloadedtwicefromthedatabase.It
thereforemakessensetogetridofduplicatesvia
DELETEADJACENTDUPLICATES.
SAPPractical.com
07
VIEWS/JOINS
1)Standardtablesaresuitablefordatawhicharerarely
ornotatallsearchedforspeciccriteria.Ifnosearches
areneeded,thenitisnotworththecoststocreateand
tokeepcurrenttheaddi onalkeystructuresneededfor
theothertabletypes.Dependinguponthenumberof
searchrequestsandthetablewidthandiftheamount
ofdataareverysmall.
2)Sortedtablesaresuitableifthedatao enneedtobe
searchedvia(par al)keys,butifitcannotbe
guaranteedthatthekeyeldsareunambiguous.READs
whichonlyusesomeoftherstkeyeldsshouldbe
doneonlywiththistabletype.
3)Hashedtablesareperfectlysuitedtosearchfor
unambiguouskeysindic onarylikeconstructs.Ifthe
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
5/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
Choosethetabletype
unambiguouskeysindic onarylikeconstructs.Ifthe
unambiguousnessoftheentriesregardingthekeyelds
canbeguaranteed,andifthesearchtermalwaysuses
thecompletekey(alltheeldsofthekeyarechecked
againstthecorrespondingvalue)thistabletypeis
Hello Guest! (/home/login)
usuallythebest.
SORTEDorHASHED
IfatableoftypeSORTEDorHASHEDisaccessed,this
shouldalwaysbedonewithasuitable(par al)key.This
meanstouseWITHTABLEKEYforREADTABLEandto
queryasmanyofthekeyeldsintheirproper
sequenceaspossiblewith=inaLOOPATWHERE
construct.Ifthisisdone,theinternallybuiltkey
structureswillbeusedtondthecorrespondingentries
asquicklyaspossible.
SimilartoDBaccessthereare
singleandmassopera onsfor
internaltables.
Wheneverpossible,themassopera onsshouldbeused
becausetheyareperformanceop mizedascompared
withmul plesingleopera ons.E.g.,appendinglines
fromapar alresultstabletoanoverallresultstable
shouldbedonewiththecommandpa ernAPPEND
LINESOFTOinsteadofdoingthesamethingwitha
LOOPATandsingleAPPENDTO.
SORTCommand
WhenusingtheSORTcommand,alwaysprovidethe
neededsortelds.Thisimprovesthelegibilityofthe
codeandstandardtabletypesmoreo enthannotdo
nothaveatablekeydened.Withoutsuchakey,the
completetablelineisusedasthekeyandalltheelds
ofthe3PERFORMANCE21tablearecheckedduring
sor ngwhichleadstoaconsiderablelossof
performance.Ifatableneedstobesortedbyuserand
date,usethecommandSORTtableBYUSERDATEeven
ifthetablestructurestartswiththeseeldsandevenif
thesequenceoftheresultsregardingtherequested
eldsisthesame.
15
DELETEADJACENTDUPLICATES
BeforeusingthecommandDELETEADJACENT
DUPLICATESyoushouldalwaysensurethatthetablehas
beensortedbythesameeldssothatduplicateentries
areactuallyeliminated.Asthecommandindicates,only
adjacenttablerowsarecompared.SimilartotheSORT
commandyoushouldalwaysprovidetheeldswhich
aretobeconsidered.Otherwise,thecompleterowwill
becomparedeldbyeldevenifonlytwoeldsare
neededfromaprocessperspec ve.
16
Ifyouareonlyinterestedintheexistencebutnotthe
contentofatablerowandifitisnotneededfor
READTABLETRANSPORTINGNO subsequentprocessing,alwaysuseREADTABLE
FIELDS
TRANSPORTINGNOFIELDS.
17
FieldSymbols
Rou nelymakeuseofeldsymbolswhenaccessing
internaltables
PassingParameters
Useasfewparametersaspossiblewhicharepassedby
reference.Makeuseofthepassingbyvalueonlywhere
itismandatedtechnically
SAPPractical.com
11
12
13
14
18
Title
Detailedexplana on
01
Execu ons
TotalNumberofExecu onsaSQLisexecutedforatable
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
6/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
01
Execu ons
SAPPractical.com
TotalNumberofExecu onsaSQLisexecutedforatable
02
Redundant#
03
Percentageiden calstatements
Redundantiden calselectswillgiveyouthecountforhowmanycallsmadeto
Databasewiththesamerecord.Theremightbeachancethesameselectmight
bewri enindierentplaceswiththesimilarwhereclauseandwhichcanbe
avoided
Hello Guest! (/home/login)
PercentageofRedundantiden calselects
04
Dura on
05
Records
TotalnumberofrecordsprocessedfromDatabasetable
06
Time/Exec
07
Rec/Exec
08
AvgTime/R.
a) Check the Ident%-Above the snapshot shows 75% select queries are duplicate which means the same record selected multiple times and which
can be avoided. Select the row and click Statement Details
Select the calling Source Code Locations and click "ABAP" which is marked in yellow(above snapshot)
Note : Current program used for all entries(BKPF) and there is an duplicate lines, so before using for all entries use sort and delete adjacent
duplicates which will prevent Table identical selects.
However we need to check the execution plan of SQL.
Note: We could see the table is RFBLG but we have not used in this table and we have used BSEG table. Since the BSEG is an cluster so the back end
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
7/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
SAPPractical.com
Okay
below
but still
the Identical selects are high so we can follow the same step which is
Hello
Guest!
(/home/login)
lets go to second table KNA1, the execution plan is given
described above.
From the above snapshot the CPU-Costs are less but still there is an change to improve the SQL execution time.
Note : You can check the Last statistics date if its older than 2 months(Depends) then you can ask BASIS team to update the table statistics.
Action taken after our trace analysis
a) Deleted duplicate rows from the tableINT_BKPF
b) CopiedINT_BSEG into ING_BSEG1and deleted duplicate records based on KUNNR
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
8/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
SAPPractical.com
d) Removed the select queryJ_1BBRANCH to outside the loop and used readstatement
After all the changes trace is collected and trace comparison is given below.
Hello Guest! (/home/login)
Earlier it was around 92 seconds(before code change) now it is 2 seconds(after code change)
ST12 trace can be collected for 'User/Tasks', 'Work Process, 'Current Mode' and 'Schedule(For Workprocess and for User/Tasks'
The 'User/Tasks' scenario allows to activate the ABAP trace for the next action under a certain user name and tasktype (DIA BTC RFC UPD) on any
application server or systemwide. In slight difference to the SQL trace it does not trace everythingunder the username, but the trace is switched on
for only one user context that does the next roll-in and that has the proper user and tasktype. The trace then lasts until this user
context/transaction is nished.
If you are interested to learn SAP Database Performance Problems please read the linkhttp://www.sappractical.com/home/blogd/sap-databaseperformance-problems/ (http://www.sappractical.com/home/blogd/sap-database-performance-problems/)
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
9/10
01/12/2016
ST12ABAPtraceusingthesingletransactionanalysis
performance-problems/ (http://www.sappractical.com/home/blogd/sap-database-performance-problems/)
Additionally
below the links will be useful for SAP Performance tuning
SAPPractical.com
http://www.sappractical.com/home/blogd/general-performance-advice-for-sap-abap-open-sql-/
(http://www.sappractical.com/home/blogd/general-performance-advice-for-sap-abap-open-sql-/)
Hello Guest! (/home/login)
http://www.sappractical.com/home/blogd/sap-index-rebuilding/ (http://www.sappractical.com/home/blogd/sap-index-rebuilding/)
If you like this blog, please share (Facebook/LinkedIn/Google+) to click below links so it will reach to others.
36
11
COMMENTS
LEAVE A COMMENT
Your name
Your email address
Calibri
15
Submit comment
RECENT POSTS
http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/
10/10