You are on page 1of 10

01/12/2016

ST12ABAPtraceusingthesingletransactionanalysis

SAPPractical.com

Hello Guest! (/home/login)

http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/

1/10

01/12/2016

ST12ABAPtraceusingthesingletransactionanalysis

SAPPractical.com
Hello Guest! (/home/login)

ST12-ABAP trace using the single transaction analysis


(/home/blogd/st12-abap-trace-using-the-single-transaction-analysis/)
- in SAP BASIS (/home/blog/SAP BASIS)

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

When and how to use ST12 ABAP trace?

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)

b) Find customer modi cations and user exits

c) Detect issues in the call hierarchy and


d) Search for localized technical tuning potential, i.e. CPU-expensiveABAP statements
ABAP real-time Object overview : A report whichin-turncall asmart formto display customer payments and this program,smart formalso
custom. Now user raised a query about "why the transaction taking more than 5 minutes tocompleteprinting".So I have asked to user whether a
report itself taking time to display or time taken is from printing? Actually this report have an selection screen which is given below

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

"Gross me(inmicroseconds)"saysTotal meofwhich"Call"toexecute"No."


mesorsimplywecansayGross meisthesummarized meoverallcall
execu ons

04

Net

"Net(Microseconds)"saysNet meisthegross meminusthe mewhenthis


mod.unitcallsothermod.unitsminusthedura onsofsimplestatementsthat
occurwithinthismodulariza onunitANDthatareexplicitelymeasured

05

Gross(%)

"Gross mein%"saysGross/Totalrun meX100

06

Net(%)

"Net mein%"saysNet/Totalrun meX100

07

Program(calledprogram)

Whichprogrambeingcalled

08

Type

Typecanbelike"DB","DB>"and"Sys."

03

Now we will consider the ABAP(internal table processing) performance improvement


Step 3.1) Let us analyse Read Table INT_BSEG
READTABLEINT_BSEGINTOWA_BSEGWITHKEYAUGBL=WA_BKPF-BELNR
GJAHR=WA_BKPF-GJAHR.
The read statement called 11,084 times but its taken high response time in this report, There are2,771 records exist in table INT_BKPF which is
looping and inside the read INT_BSEG is calling. Actually we have the key eld in INT_BKPF as "BUKRS", "BELNR" and "GJAHR" so the same elds
can be passed(missing the eld "BUKRS" in read statement) and BINARY SEARCH can be used.
Note : If the internal table is standard table then we have to sort the table before using "BINARY SEARCH"
Step 3.2) Let us analyseRead Table INT_KNA1
READTABLEINT_KNA1INTOWA_KNA1WITHKEYKUNNR=WA_BSAD-KUNNR.
The read statement called 11,084 times but its taken high response time in this report, There are800 records exist in table INT_KNA1 which is
looping and inside the read INT_BSEG is calling. In this case company code will notavailable(KUNNR is key eld in table KNA1 so
addingBINARYSEARCH will give better response time .
We can analyse Per call or Per modularizaton unit(will give set of call inside ie.Perform F_GET_DATA)
Below the information will be useful when you writing ABAP code
S.No

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

Now we will consider the database performance improvement


Note : If you would like to analyse the performance issue(Database) without taking trace please read the link
http://www.sappractical.com/home/blogd/sap-abap-performance-tuning/ (http://www.sappractical.com/home/blogd/sap-abap-performancetuning/)
Go to Trace analysesfull screenlist and select the row and click "SQL trace summary"

The report is already sorted by duration(microseconds)


Below the information will give you overview of SQL trace
S.No

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

Execu onTimeofSQLinmicrosecondsmeanstotaldura onofen retable


recordsselec on

05

Records

TotalnumberofrecordsprocessedfromDatabasetable

06

Time/Exec

TimeperExecu on=Dura on/Execu ons

07

Rec/Exec

RecordsperExecu on=Records/Execu ons

08

AvgTime/R.

AverageProcessing meperRecord=TimeperExecu on/RecordsperExecu on

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

tables are different.

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

c) Sort command used for bothINT_BSEG andINT_KNA1

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.

List of task type is given below

Please read the link about RFC trace http://www.sappractical.com/home/blogd/perform-an-rfc-trace-from-transaction-st12/


(http://www.sappractical.com/home/blogd/perform-an-rfc-trace-from-transaction-st12/)
The 'Workprocess' allows to activate traces for selected workprocess

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

How to create or generate a test inbound queue in sap (/home/blogd/how-to-create-or-generate-a-test-inbound-queue-in-sap/)


8/13/2016 12:17:40 AM

SQL Performance Monitoring-SAP SQLM Part3 (/home/blogd/sql-performance-monitoring-sap-sqlm-part3/)


5/26/2016 11:22:26 AM

SQL Performance Monitoring-SAP SQLM Part2 (/home/blogd/sql-performance-monitoring-sap-sqlm-part2/)


5/25/2016 3:18:27 PM

SQL Performance Monitoring-SAP SQLM PART1 (/home/blogd/sql-performance-monitoring-sap-sqlm-part1/)


4/25/2016 2:29:32 PM

How to implement SAP ABAP eld exit (/home/blogd/how-to-implement-sap-abap- eld-exit/)


4/23/2016 10:03:20 PM

http://www.sappractical.com/home/blogd/st12abaptraceusingthesingletransactionanalysis/

10/10

You might also like