You are on page 1of 10


ST12­ABAP trace using the single transaction analysis

Hello Guest! (/home/login)­abap­trace­using­the­single­transaction­analysis/


incoming RFCs. for functional time distribution analysis. With ST12 the program hierarchies can be analyzed in the aggregated ABAP trace 'per call'. ST12 Trace combines ABAP and performance (SQL) trace into single transaction. The ABAP trace results are completely collected to database. to SAP backof ce. transaction ST05) and to make the tracing and analysis process faster and more convenient. and one click navigates directly into the ST05 trace display on the proper server. Transaction ST12 is used to to integrate ABAP and performance traces (SQL Enqueue RFC. Selected results form performance trace and other ndings can be saved as annotation texts into a trace analysis. call function/method. ABAP and performance traces can be activated on another server or even on all servers to catch e. ST12 makes it easy to keep valuable trace results and pass them on e. call screen or PAI PBO modules. ST12 allows to activate the ABAP trace for another user. These are easy to understand.g.01/12/2016 ST12­ABAP trace using the single transaction analysis SAPPractical. It is also able to estimate the time contribution of certain programs. and to optimize ABAP/CPU bound issues.sappractical. user exits and customer coding. Their hierarchies can branch and also merge again. with major functional enhancements especially for the ABAP trace part. Before you start: We need to understand the SAP system response times which is given below. In a joint switch on/off with the performance 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­abap­trace­using­the­single­transaction­analysis/ 2/10 . The second are calls to modularization units like perform. It should be used to detect top-down any performance hotspot. ABAP trace with ST12 is the central entry point for performance analysis. These are complex because they are hierarchical containers and resemble nested russian puppets.g. The ST12 ABAP Trace Summary quickly shows the contribution of known expensive functionalities.  This blog will show how to take a trace with ST12 and how to analyse the ST12 trace. Hello Guest! (/home/login)   ST12-ABAP trace using the single transaction analysis (/home/blogd/st12-abap-trace-using-the-single-transaction-analysis/) . 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. When and how to use ST12 ABAP trace? http://www.   For Performance trace ST12 remembers time-frame & server. Therefore the non-aggregated ABAP trace with its large trace le sizes is not needed and was omitted from ST12.

Step 1) Go to transaction code ST12 and give ABAP trace was recommended only to analyze gaps in the SQL trace or pure CPU issues. Now user raised a query about "why the transaction taking more than 5 minutes to complete printing". smart form also custom. Choose the 4th column(Net) and click descending button which is given below.sappractical.01/12/2016 ST12­ABAP trace using the single transaction analysis When and how to use ST12 ABAP trace? SAPPractical. CPU-expensive ABAP statements ABAP real-time Object overview : A report which in-turn call a smart form to display customer payments and this program. 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.0 so we improve both the response times ABAP(Internal table processing) and Database. http://www.­abap­trace­using­the­single­transaction­analysis/ 3/10 .2 seconds. Actually I gave smaller input selection in selection screen so the total execution time is 91. 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. If we check the marked rectangular in above screen there are internal table processing and database select query can be improved.  Please close all the session except two(Report execution and ST12). 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. If we see the above snapshot ABAP. Database and System time is shown and we could see ABAP run-time is 88.e. ABAP trace with ST12 can and should be used to  a) Identify top-down any performance hotspot and get an exact functional 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. If you are taking trace and the report is running by user also ne but make sure user is using in single session. So time taken is from Data selection and Internal table processing. after user selecting a particular line to click print button.0% and Database run-time is  12.

This method will prevent dump 02 Use Joins Joins will hit the databse at only once Result will be faster Reduc on of selected columns Avoid “*‐selec ons” and instead list the column names needed in the selec on. Before using For All Entries delete the duplicate records in the driver table. Use SELECT SINGLE instead. you can use the addi on CORRESPONDING FIELDS.unit calls other mod. We can analyse Per call or Per modularizaton unit(will give set of call inside ie. try to use all fields of an exis ng index for the database query.01/12/2016 ST12­ABAP trace using the single transaction analysis SAPPractical. This will restrict the sequen al search to as few data records as possible. whenever you only need some lines. "BELNR" and  "GJAHR" so the same elds can be passed(missing the eld "BUKRS" in read statement) and BINARY SEARCH can be used. There are 2. with a field included in the index accessed for Avoiding unwanted table the selec on. the robustness of the code is Memory saved and Time improved. The result table columns should be synchronous with the selec on structure for op mized Now system will take you to the respective program/object with the exact line­abap­trace­using­the­single­transaction­analysis/ 4/10 . There are 800 records exist in table INT_KNA1 which is looping and inside the read INT_BSEG is calling. If you have more fields in the result table but if the fields to be retrieved have been given iden cal names to the ones used for the table. access 03 04 05 06 Avoiding unwanted records Aggregates like MIN or MAX are always resolved on the http://www. "Number" says how many  mes the statement is executed. This does not cause addi onal run me. Especially expensive are unnecessary retrievals of columns with type STRING. Actually we have the key eld in INT_BKPF as "BUKRS". like perform. Existency checks Do not use COUNT(*) to find out whether there are records for specific selec on criteria. Simultaneously. If this is not possible. consuming Op mized query If at all possible.084 times but its taken high response time in this report.sappractical.771 records exist in table INT_BKPF which is looping and inside the read INT_BSEG is calling. call func on/method. This avoids unnecessary table access.2) Let us analyse Read Table INT_KNA1 READ TABLE INT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_BSAD-KUNNR. Perform F_GET_DATA) Below the information will be useful when you writing ABAP code S.   the information will give you overview of ABAP trace Hello Guest! (/home/login) Below  S. call screen or PAI PBO modules Gross "Gross  me(in microseconds)" says Total  me of which "Call" to execute "No.units minus the dura ons of simple statements that occur within this modulariza on unit AND that are explicitely measured 05 Gross(%) "Gross  me in %" says Gross / Total run me X 100 06 Net(%) "Net  me in %" says Net / Total run me X 100 07 Program(called program) Which program being called 08 Type Type can be like "DB".  The read statement called 11. "DB‐>" and "Sys. System load will reduced Reduc on of line items Use the WHERE‐clause to restrict the selec on and to minimize the amount of data returned to the ABAP system." 03 Now we will consider the ABAP(internal table processing) performance improvement Step 3. Note : If the internal table is standard table then we have to sort the table before using "BINARY SEARCH" Step 3." mes or simply we can say Gross  me is the summarized  me over all call execu ons 04 Net "Net(Microseconds)" says Net  me is the gross  me minus the  me when this mod.No Call Detailed explana on 01 Call Simply we can say which statement is executed 02 No. try to at least take the first index fields into account.  The read statement called 11. In this program there is an select statement which is highest response time(will see later).084 times but its taken high response time in this report. Use FAE instead of Ranges(where clause IN).1) Let us analyse Read Table INT_BSEG READ TABLE INT_BSEG INTO WA_BSEG WITH KEY  AUGBL = WA_BKPF-BELNR                                                                                                                           GJAHR = WA_BKPF-GJAHR. Use SELECT SINGLE/UP TO n ROWS.No Title Comments Advantage 01 Use For All Entries For all entries is a ABAP query.  In this case company code will not available(KUNNR is key eld in table KNA1 so adding  BINARY SEARCH will give better response time .

 We would like to point out. update func on modules 09 Each execu on of an open SQL‐statement comes with a certain overhead (parsing. These commands can be iden fied by the addi ons INTO TABLE for SELECTs or FROM TABLE for UPDATE statements.­abap­trace­using­the­single­transaction­analysis/ 5/10 . you o en need to determine the sum of the order posi on of a single order and on all available applica on servers. If the internal table contains duplicate entries. the database is accessed once for each line item in the internal table. It therefore makes sense to get rid of duplicates via DELETE ADJACENT DUPLICATES. As an alterna  07 VIEWS/JOINS  1) Standard tables are suitable for data which are rarely or not at all searched for specific criteria. Avoid Open SQL‐statements within loops at all cost! With these types of constructs you will have the overhead for the statement at each loop itera on. the statement is extremely cri cal from a performance perspec ve. Please keep the following in mind with FOR ALL ENTRIES: a. Depending upon the number of search requests and the table width and if the amount of data are very small. an INSERT is done. If the http://www. JOINS or the addi on FOR ALL ENTRIES. checking against the statement buffer in the DBMS etc. For each of these. READs which only use some of the first key fields should be done only with this table type.). 10 Nested SELECTs and SELECT‐commands in loops should be avoided. If. This is applicable especially if this calcula on is done rarely (e. make use of VIEWS. on the other hand..sappractical. however. If you have many new data records to insert. if it is not too large – to first load the data into an internal table and then do the aggrega on from there. just once per day).   2) Sorted tables are suitable if the data o en need to be searched via (par al) keys. then it is not worth the costs to create and to keep current the addi onal key‐structures needed for the other table types. If no searches are needed.000) of orders it makes sense to have the DB‐system determine this aggregate. If the internal table referenced with FOR ALL ENTRIES is empty. that as far as it is known today. all items will be loaded.   3) Hashed tables are perfectly suited to search for unambiguous keys in dic onary like constructs. but if it cannot be guaranteed that the key fields are unambiguous. If you need data of 50 orders. it is possible that the related data records will be loaded twice from the database. SAPPractical. Example: to calculate the average amount of a large number (>100.01/12/2016 ST12­ABAP trace using the single transaction analysis Aggregate Aggregates like MIN or MAX are always resolved on the database server and the table buffering is therefore circumvented. HANA based database queries do have their strengths especially for aggrega ons and that their usage is therefore explicitly encouraged for HANA. an UPDATE is tried first and if this is not successful. you should not get them in 50 individual selects but you should retrieve them via one statement which supports the so called array‐fetch. Can be used if the database is doing the calcula on in ABAP is usually the be er op on HANA pla orm 08 Updates The command UPDATE SET makes it possible to restrict the list of fields to be updated (instead of upda ng the complete record).e. this will not happen with n database access but it will be 2n where n = the number Number of DB‐access execu ons of line items in the internal table. Do not use MODIFY ! Within an applica on it should be clear if data records were created or if exis ng ones were updated. This command should be preferred if Try to use all updates using possible. Developers should therefore Hello Guest! (/home/login) check how large the data volume for the aggregate will be and if it could make sense – i. Even with the addi on FROM TABLE. Then it will pass only one or a few items instead of hundreds of thousands back to the applica on server for calcula ng the average amount in ABAP. This can poten ally cause a high load on the DB system if it is accessed from several installa ons and applica on servers. b. Each command should therefore retrieve as much data as possible at once.g. In addi on.

 appending lines from a par al results table to an overall results table should be done with the command pa ern APPEND LINES OF… TO instead of doing the same thing with a LOOP AT and single APPEND TO. As the command indicates. always provide the needed sort fields. If a table needs to be sorted by user and date. Similar to DB‐access there are single and mass opera ons for internal tables.sappractical. If the unambiguousness of the entries regarding the key fields can be guaranteed. 17 Field Symbols Rou nely make use of field symbols when accessing internal tables Passing Parameters Use as few parameters as possible which are passed by reference.No Title Detailed explana on 01 Execu ons Total Number of Execu ons a SQL is executed for a table http://www. This means to use WITH TABLE KEY for READ TABLE and to query as many of the key fields – in their proper sequence – as possible with “=” in a LOOP AT WHERE construct. 16 If you are only interested in the existence but not the content of a table row and if it is not needed for READ TABLE TRANSPORTING NO subsequent processing. E. the complete row will be compared field by field even if only two fields are needed from a process perspec ve. 15 DELETE ADJACENT DUPLICATES Before using the command DELETE ADJACENT DUPLICATES you should always ensure that the table has been sorted by the same fields so that duplicate entries are actually­abap­trace­using­the­single­transaction­analysis/ 6/10 . and if the search term always uses the complete key (all the fields of the key are checked against the corresponding value) this table type is Hello Guest! (/home/login) usually the best. Without such a key. always use READ TABLE FIELDS TRANSPORTING NO FIELDS.. This improves the legibility of the code and standard table types more o en than not do not have a table key defined. this should always be done with a suitable (par al) key. use the command SORT table BY USER DATE even if the table structure starts with these fields and even if the sequence of the results regarding the requested fields is the same. SORTED or HASHED If a table of type SORTED or HASHED is accessed. only adjacent table rows are Go to Trace analyses full screen list 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. Otherwise. Make use of the passing by value only where it is mandated technically SAPPractical. Whenever possible. SORT Command When using the SORT command. If this is done.sappractical. the mass opera ons should be used because they are performance op mized as compared with mul ple single opera (http://www. the internally built key‐ structures will be used to find the corresponding entries as quickly as  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.01/12/2016 ST12­ABAP trace using the single transaction analysis Choose the table type unambiguous keys in dic onary like constructs.sappractical. the complete table line is used as the key and all the fields of the 3 PERFORMANCE 21 table are checked during sor ng which leads to a considerable loss of performance. Similar to the SORT command you should always provide the fields which are to be considered.

so before using for all entries use sort and delete adjacent duplicates which will prevent Table identical selects. Since the BSEG is an cluster so the back end http://www. Average Processing  me per Record = Time per Execu on / Records per Execu 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­abap­trace­using­the­single­transaction­analysis/ 7/10 . 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. Note: We could see the table is RFBLG but we have not used in this table and we have used BSEG table. There might be a chance the same select might be wri en in different places with the similar where clause and which can be avoided Hello Guest! (/home/login) Percentage of Redundant iden cal selects 04 Dura on Execu on Time of SQL in microseconds means total dura on of en re table records selec on 05 Records Total number of records processed from Database table 06 Time/Exec Time per Execu on = Dura on / Execu ons 07 Rec/Exec Records per Execu on = Records / Execu ons 08 Avg Time/ Total Number of Execu ons a SQL is executed for a table 02  Redundant # 03 Percentage iden cal statements Redundant iden cal selects will give you the count for how many calls made to Database with the same record. However we need to check the execution plan of SQL.01/12/2016 ST12­ABAP trace using the single transaction analysis 01 Execu ons SAPPractical.

the execution plan is given described above. SAPPractical. Action taken after our trace analysis a) Deleted duplicate rows from the table INT_BKPF b) Copied INT_BSEG into ING_BSEG1 and deleted duplicate records based on KUNNR­abap­trace­using­the­single­transaction­analysis/ 8/10 .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.sappractical.  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.01/12/2016 ST12­ABAP trace using the single transaction analysis tables are different.

The trace then lasts until this user context/transaction is nished. 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'.com/home/blogd/perform-an-rfc-trace-from-transaction-st12/ ( ( d) Removed the select query J_1BBRANCH to outside the loop and used read statement After all the changes trace is collected and trace comparison is given below. 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. In slight difference to the SQL trace it does not trace everything under the username.sappractical.sappractical. '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. List of task type is given below Please read the link about RFC trace http://www.01/12/2016 ST12­ABAP trace using the single transaction analysis c) Sort command used for both INT_BSEG and INT_KNA1 The 'Workprocess' allows to activate traces for selected workprocess If you are interested to learn SAP Database Performance Problems please read the link http://www. 'Work­abap­trace­using­the­single­transaction­analysis/ 9/10 .

      36   0   11 0 3 0 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. please share (Facebook/LinkedIn/Google+) to click below links so it will reach to others.sappractical.sappractical.sappractical.01/12/2016 ST12­ABAP trace using the single transaction analysis performance-problems/ ( (  If you like this blog.eld-exit/) 4/23/2016 10:03:20 PM­abap­trace­using­the­single­transaction­analysis/ 10/10 Additionally below the links will be useful for SAP Performance tuning Hello Guest! (/home/login)  (http://www.