How to run SAP transaction ST05 to trace a SAP program execution and review trace

SAP transaction ST05 can be used to trace execution of SAP program/job to catch performance statistics related to SQL statement execution, SAP enqueue operation, SAP RFC activities, SAP Buffer access and HTTP activities. So you can analyze trace to validate performance or identify performance bottleneck. SAP ST05 allows you to enter a SQL statement and analyze its’ execution plan without executing a program.

This post talks about

  • How to use SAP ST05 to do a trace such as SQL trace?
    • How to start ST05 transaction?
    • How to check ST05 trace status?
    • How to start/activate desired ST05 trace?
    • How to stop/deactivate a ST05 trace and display trace?
  • How to save, display/navigate through SAP ST05 trace?
    • How to understand information in the detailed trace screen.
    • How to understand SQL summarize SQL statement.
  • Other ST05 Trace lists and Call Stack trace.
  • How to enter SQL statement and verify execution plan?

If a SAP system has more than one instance/server, SAP ST05 can trace a program/job only when the program/job is executed in the server where SAP ST05 is turned on. Depends on your SAP ST05 version, your screen might looks a little bit difference from what is showed here but usage of each screen and information showed in each screen should be similar.

  1. How to use ST05 to do a SQL/Enqueue trace?

To trace an end-to-end SAP ABAP program execution: Run ST05 -> Check trace status -> start/activate trace with or without filter -> execute the SAP program -> stop/deactivate trace after the SAP program finishes.

  1. How to start ST05 transaction?

You can access SAP SQL tracing tool by typing “/nST05” transaction code into command window of your SAP screen with a “return/enter” key, Then initial screen of SAP ST05 similar to Figure 1 would appear.

Figure 1 ST05 SQL trace initial screen

Figure 1 – shows 5 steps of conducting a ST05 performance trace.

1.2 How to check trace status to know it is ready to turn on a ST05 trace?

ST05 transaction is an exclusive transaction – which means that there should not exist any ‘active’ trace on the SAP server/instance where you are going to do a trace. SE30 ABAP trace and ST12 ABAP trace (Not ST12 SQL/performance trace) can go parallel with ST05. If message like “All Traces are switched off ” is showed up in ST05 Initial screen like Figure 1, the system is ready for you to turn on the trace on the SAP server/instance.

Figure 2 ST05 status – not “ready” for new trace status

If ST05 initial screen showed that at least one traces is activated like what showed in Figure 2, it is not ready for you to do a trace on the server at the moment. In such situation, you can try one of following options

  1. Wait for completion of existing tracing.
  2. Try another server to do test and trace if possible.
  3. Ask other user to exit from the existing trace.
  4. You can proceed with your trace by deactivating active trace on “right” situations.

If a system has two or more application servers, two or more ST05
tracing can be turned on at the same time – each on one of application servers.

  1. How to start/activate desired ST05 trace?

To activated desired trace, you need to specify type of ST05 trace you need, filter and limited the trace to specific business process and start the trace.

1.3.1 Select ST05 trace type

SAP ST05 can do several types of trace – not all traces are relevant to a SAP program and not all relevant traces needs to be turned on dependent on the SAP program being traced.

To tell ST05 that what traces are expected, you can check or uncheck needed trace in “Select Trace” section showed in Figure 1. More than one trace at the same time based on your performance analysis requirement can be checked. Most of time, SAP ST05 is used to do SQL trace and/or ENQUEUE trace in my SAP experience.

1.3.2 Select SAP program/process to be traced

Normally many programs/processes like Figure 3 are running in one SAP server/system, we need to tell SAP ST05 which business process to be traced.

Figure 3 SM50 many running programs/processes

SAP ST05 provides several options for you to enter filters to make ST05 trace more specific. Highlighted columns in Figure 3 are related to the predesigned ST05 filters which can be used to limit ST05 trace to specific job/transactions. If you do not specify filters, many headaches await you like a big trace file, overwritten trace file etc.

To enter the filters, you can click “activate trace with filter” button in Figure 1, then screen similar to Figure 4 would be showed up for you to enter filter to be able to trace specific process.

Figure 4 – ST05 Trace Restriction/Filter and start trace

User name is the SAP userID under which the program is going to run or has been running. Transaction/program name is the business transaction which we need to put trace on. Process number is SAP work process number where a business transaction is running with. Table name is the table which a transaction/program would access. Table 1 lists common filters and their explanation.

Table 1 – ST05 Filters and explanation

ST05 Filter Entered Explanation
User name Enter a user name to trace all activities happened under this specific user.
Transaction name Enter a transaction name to trace all executions of the transaction.
Program name Enter a program name to trace all execution of the program.
Process number Enter a SAP work process number to trace all activities which is executed in the SAP work process. This is to put a trace on an already- running process such as an active SAP background job. There is no way to know number of SAP work process which SAP would use to execute a SAP program unless the system has only 1 process of each type. So if end-to-end trace is needed, using an exclusive user-id might be a better choice.
Table Names Enter one or table names to trace all operations involved that particular table.
User + Transaction Trace all execution of that particular transaction under the specified user. If same user executes the same transaction two times at the same time, two executions would be captured into trace as well.
User + Process Number Trace all activities executed in the specified SAP work process as long as it is under the specific user.

 

In Figure 4, ST05 is instructed to collect SQL trace and Enqueue trace for all activities happened under a specific user in current SAP server.

If there is only one transaction running under your SAP logon and that is what you would like SAP ST05 to trace, you can simply click “Activate Trace” in Figure 1 after trace type is selected.

1.3.3 Start the ST05 trace

After desired filter is entered, you can start the ST05 trace by clicking the continue button showed in Figure 4. Your screen could looks like Figure 5, This means your trace request is started. Please check trace status to make sure that your trace request is accepted by SAP system. If you are doing an end-to-end trace on an online program execution, now the program can be executed.

Figure 5 – SAP ST05 Traces started

If you see message similar to what showed in Figure 6, then your trace is not started due to an active ST01 trace. You need to deactivate the trace using SAP transaction ST01 first to continue.

Figure 6 – ST05 Trace conflict with ST01

SAP ST05 cannot detect ST01 trace earlier in the way it detect other ST05 trace or ST12 trace.

1.4 How to stop/deactivate SAP ST05 trace?

You need to stop /deactivate the trace after business transaction being traced is completed or after desired duration. To stop trace, you click button “Deactivate Trace” showed in Figure 5. After ST05 trace is stopped, the ST05 screen is like what showed in Figure 7

Figure 7 – ST05 Trace stopped

2 How to save, display/navigate through SAP ST05 trace?

After Step 1.4, you have a SQL trace. Now you can save your trace for future review or you can review your trace now. Most important ST05 screens are trace list screen which is available for all ST05 trace, Summarized SQL statement screen and SQL execution plan screen which are applicable for SAP ST05 SQL trace only. You can also access Call stack screen. ns

2.1 How to save/delete a SAP ST05 Trace?

Following the menu path “Performance Trace -> Save Trace”, the ST05 would ask you to give a file name to save your trace. Under the same menu, ST05 provides options to delete saved trace as well.

The reason to save a trace is to avoid the trace being overwritten by subsequent trace activities.

2.2 How to display a SAP ST05 Trace?

You can display a ST05 trace by clicking “Display Trace” button in Figure 7. You can use menu path “Performance Trace -> Displayed Saved Trace” to display a previous saved ST05 trace

Following the click, SAP ST05 would present a screen similar to Figure 8 to allow you to specify what trace records would be selected and displayed.

Figure 8 Filters to display trace

You can make following choices:

  1. Trace type – if you have collected several traces at the same time, you can analyze one trace such as SQL trace at a time.
  2. Trace window –If you have traced a long time, you can specify a smaller period of that tracing for review or review the period you are interested
  3. Further restriction – If you are doing trace based on SAP transaction code and several users are running that transaction during the trace period, you can review the trace records related to specified SAP user by entering his USR ID here.

After needed input is provided, you can click “continue” button in Figure 8 to display trace records. If number of trace records which meets your above choice is more than 5,000 records, then a pop-up window similar to Figure 9 would show up.

Figure 9 – more ST05 trace record meets your selection

You can click “yes” to display all records or no to display just 1st 5,000 records depends on your situation. For example, if your program is keeping executing a same set of SQL again and again, 1st 5,000 records might be enough. It takes time and system resource to display all records. In worst cases, ST05 can get timeout/memory error due to huge number of records collected.

How many trace records would be collected depends on two factors – trace period and program design. If a program is long running but with a few database accesses, SQL trace on such program would have a few records.

In normal case, SAP ST05 would present “Trace List” screen similar to Figure 10.

Figure 10 – ST05 Trace List screen

SAP ST05 displays all trace records according to the time sequence when it is captured by default. You can return to Figure 8 screen by clicking one of two SAP screen navigation buttons in Figure 10 so you can select to review another trace. allow you to exit current SAP screen and return to previous SAP screen.

Pay attention to menu item “Trace list” (red circled in Figure 10), you can access several other ST05 screens. I normally use “Summarized SQL Statements” screen first. If “summarized SQL statements” screen shows a lot of “Identical selection”, I might go back to “Trace List” screen” to review “List Identical Select Statements” screen. Referring to Figure 11 for the menu path for those additional ST05 screens

Figure 11 – ST05 Trace List dropdown Menu

To get “Summarized SQL statements” screen similar to Figure 12, you can click “Trace List”->”Summarize Trace by SQL Statement”.

Figure 12 – SAP ST05 Summarized SQL statements

To get “Identical Select statements” screen similar to Figure 13, you can click “Trace list” -> “Display Identical Selects”

Figure 13 – SAP ST05 Identical Select Statements

Sometimes, SAP ST05 might send you a pop-up window with message “File end of performance trace file detected -> See long text” instead of display the trace list. If you see message like this, this normally means that trace has not captured anything or something unexpected happens. This can be your error(wrong input) or sap/system problem. You got to redo the trace.

2.3 SAP ST05 Trace List screen

SAP trace list screen layout is shared by all SAP ST05 traces. The same column in Trace list screen might mean something different in different trace.

2.3.1 SAP ST05 Trace List Screen – Understanding trace records

Please refer to Table 2 to understand fields/columns of trace records.

Table 2 – SAP ST05 Trace record explanation

Column Explanation
Time when trace record was created.
Duration of the recorded operation in the same row.

  • SQL trace: duration of SQL operation.
  • Enqueue trace: duration of a lock operation.
  • RFC trace: Duration of RFC operation.
Name of program which is related to the statement of the row.
Depending on the type of trace, the object to which the trace statement refers is specified here.

  • SQL trace:   Name of the table or DB procedure.
  • Enqueue trace: Name of the lock object.
  • RFC trace:       Abbreviated name of the instance on which the function module is executed.
Type of operation executed:

  • SQL trace: FETCH, OPEN etc
  • RFC trace: CLIENT or SERVER
  • Enqueue: ENQUEUE, DeQUEUE or DEQAll etc.
Cursor # (SQL trace only), blank for other traces
maximum number of rows requested from or sent to the database (SQL trace only), “0” for other traces
Depends on trace type.

  • SQL trace – Number of records returned or changed or inserted.
  • Enqueue trace – number of granules.
  • RFC trace – number indicates type of the RFC trace records. 1 – completed
Return code for the operation. Operation success indicator.

  • SQL Trace: return code of Database system.
  • Enqueue Trace: 0 – success, 2 – collision, 8 internal error.
  • RFC trace: 0 – success.
Name of database connection
Operation details.

  • SQL trace: SQL statements.
  • Enqueue trace: Lock mode, table, lock argument.
  • RFC Trace: Source, target, client/server, FM, bytes sent or received.

 

2.3.2 SAP ST05 Trace list screen – associated operations

SAP has built in many operations/functions for you to review and analysis performance in Trace List screen. Please refer to Table 3 for list of functions and how to execute a function.

Table 3 – SAP ST05 trace list – Associated operations

Icon/Button Explanation How to use this
Display details about operation Select a line/row in the trace list screen, then click this.
Display Dictionary data Select a line/row in the trace list screen, then click this.
Display SQL execution plan Select a line/row in the trace list screen, then click this.
Display SQL source code Select a line/row in the trace list screen, then click this.
Display Call stack/Hierarchy Select a line/row in the trace list screen, then click this.
Analyzed SQL statement Select a line/row in the trace list screen, then click this.
Replace “placeholder” in SQL
statement with value
Select a line/row in the trace list screen, then click this.
Display details of trace record Select a line/row in the trace list screen, then click this.
Sort Trace list Click on the row header like duration, then click this.
Search in the Trace list Click this icon, then enter search string( table name etc) to continue.
Filter display Click this icon, then select a column (like object), enter data like table name etc.

 

2.4 SAP ST05 Summarized SQL statements screen

Unlike Trace list screen, summarized SQL statement screen is only applicable to SQL trace. If you would like to review SAP program’s SQL performance or tuning SQL performance, i would suggest that you start with this screen. If you would like to validate a SQL change, the summarized SQL statement screen can help as well, of course, you need two summarized SQL statements screen – one is before change and one is after change.

2.4.1 SAP ST05 Summarized SQL Statements screen – Understanding Summarized SQL statement

You need to understand the screen first before we can take next step to analyze SQL performance. Table 4 is to help you to understand the summarized SQL screen of SAP st05 SQL trace.

Table 4 – SAP ST05 Summarized SQL statement field explanation

Column Explanation
Total number of executions of the statement by database engine – not logical execution based on source.
= number of the SQL execution hit the same table record – 1.
Percentage of statements that are identical. For example, if you read the same order from order table 10 times for different fields at different time, total number of execution would be 10, total number of redundancy would be 9. % would be 90%.
Summarized duration of all executions for the SQL statement.
Number of processed records for all executions.
Average execution time per SQL statement execution.
Average number of rows (records) processed per SQL statement execution
Average processing time required per record/row.
Minimum processing time required per record/row.
Record length of the table.
Type of buffer if table is buffered. FUL – bully buffered, DeFul – fully buffer is possible but not enabled.
Table type.
Name of table or database procedure.

 

2.4.2 SAP ST05 Summarized SQL Statements screen – Associated Operations

In ST05 Summarized SQL statement screen, SAP has built in many operations/functions for you to review and analysis performance. Please refer to Table 5 for a list of common operations/functions and their operations.

Table 5 ST05 Summarized SQL statements – associated operation

Icon/Button Explanation How to execute to the function
Display all trace records for the summarized statements Select a line/row in the screen, then click this.
Display SQL statements Select a line/row in the screen, then click this.
Display Dictionary data Select a line/row in the screen, then click this.
Display SQL execution plan Select a line/row in the screen, then click this.
Display SQL source code or calling positions if SQL is called from different location of program Select a line/row in the screen, then click this.
Analyzed SQL statement Select a line/row in the screen, then click this.
Different views of a row Select a line/row in the trace list screen, then click this.
Sort Trace list Click on the row header like duration, then click this.
Search in the Trace list Click this icon, then enter search string( table name etc) to continue.
Filter display Click this icon, then select a column (like object), enter data like table name etc.
Dowload/save list as word document or html document etc Click this icon, choose select download file type, then follow screen instruction.

 

Most accessed function is “display SQL execution plan” – this would be covered in below section.

You can review SAP ABAP source code related to a particular SQL as well. Figure 14 shows navigation steps from summarized SQL statements to SAP program source code. It also demonstrates that one SQL in summarized SQL statements screen can have multiple call locations/positions. In SQL Trace list, it would take you directly to the source code after you click “review source code” icon/button. Reviewing source code can help you to understand why the SQL has been executed so many times etc., for example, the SQL might be inside a ABAP loop.

Figure 14 ST05 trace – From summarized SQL statement to source code

2.5 ST05 SQL Trace – SQL execution plan screen

When a ST05 SQL trace shows that a SQL is expensive with a few executions, The SQL and its’ execution plan has to be reviewed. You can access execution plan of a SQL in “Trace list screen” and “summarized SQL statements” screen etc. To get execution plan for a SQL, you select the SQL by placing cursor on the line/row, then you click “Explain” button/icon, SAP ST05 display would be changed and you would see screen similar to Figure 15 showing execution plan for specified SQL.

Figure 15 ST05 Trace – SQL execution plan

From Figure 15, you can review further information on the table and index status, index details for the index being used, SQL table Access Predicates and records filters. Based on the review, you might like to take further action like table/index rebuilt or statistics updates etc. which can be accessed from SQL execution plan screen as well. I clicked the table name and index name in Figure 14, I got Figure 16 showing Table index information and detailed index information. Rebuilding of table and index and updating of table statistics are done by a separate SAP program or Database tool.

Figure 6 – ST05 Trace Table & index info as well as current index details

I have to stop short of Explaining data in Figure 15 like index selectivity (Number of Distinct fields), Clustering factor to keep this post short.

3 Other ST05 Trace lists and Call Stack trace

Here only Enqueue trace list and RFC trace list are showed here so you know what they looks like.

3.1 SAP ST05 Enqueue trace list

When SAP locking is an issue to performance, you can take an enqueue trace for performance analysis. Figure 17 is a part of SAP enqueue trace list.

Figure 17 ST05 Enqueue Trace list screen

If you double click the statement, you would see screen similar to Figure 18

Figure 18 ST05 Enqueue trace record detail

Please pay attention to the red circle fields in Figure 18. They can tell what user and process is blocking current lock request. This is important to identify root cause of SAP enqueue( SAPLSENA ) issue.

3.2 SAP ST05 RFC trace list

RFC trace can tell you what RFC is executed during the program execution. If you need to do such trace, you can get trace list screen similar to Figure 19.

Figure 19 – ST05 trace – RFC trace list

This would help to identify which RFC call is bottleneck of the performance so improvement plan can be worked on.

3.3 SAP ST05 Call stack

If you read status message carefully in Figure 1, there are three messages ” All trace “, “Call stack deactivated” and “Progress display off”. Call stack or Call Hierarchy is a calling tree so you know which subroutine is executing the operation such as SQL execution and who is calling the subroutine and so on. When Call Stack is deactivated, SAP ST05 would not track the call hierarchy. Call hierarchy can help you understand the business logic/process related to an operation like SQL execution. When Progress display is on, then SAP ST05 would show you progress status of formatting trace records when you try to display “trace list”.

If SAP ST05 is expected to log call hierarch, you need to activate call stack tracing before you click “activate” or “Activate Trace with Filter” button in Figure 1. To turn on the stack trace, follow the menu path “Performance trace ->Activate Stack Trace”. After trace is completed, you just click the row and then click the “Call stack” button to know the hierarchy of the call in Trace list screen. Figure 20 is a call stack sample screen from ST05 SQL trace list.

Figure 20 – ST05 Call stack list

4 How to use ST05 to enter an SQL statement and verify SQL execution plan?

You might need to verify index execution plan across SAP landscape or verify whether a table statistics update etc. has made any difference to SQL execution plan. For example, if one SQL in a program has production performance issue due to table access and the program is working fine in testing environment, you might want to check SQL execution plan difference between two boxes. Of course, you can execute the program in two boxes with ST05 trace to find this out. But SAP ST05 has a quick way for you to verify SQL execution plan in different boxes such as testing box and production box.

In Figure 1, you can click button “Enter SQL statement”, following screen would appear for you to enter SQL statement for analysis.

Figure 21 ST05 – Enter SQL statement

Following is the SQL statement I need to verify –

SELECT “REGIO”, “LAND1” FROM “KNA1” WHERE “MANDT”=:A0 AND “KUNNR”=:A1

Figure 22 – ST05 Analysis SQL statement – Entered SQL statement

After I clicked “Explain” button, Execution plan of above SQL in the system is displayed as showed in Figure 23.

Figure 23 – ST05 analysis SQL statement – execution plan

You can manipulate the where clause of the SQL statement like adding other fields from the table to see how execution plan would change or playing with database hints. You can copy a SQL from SQL cache and paste here or load a SQL from a local file instead of typing.

5 Further information

SAP transaction ST12 can be used to do both SQL and ABAP trace. It is my preferred SAP performance tracing tool. But if you would like to do only SQL trace, SAP transaction ST05 can be easier and can be quickly launched. ST05 tool can tell you whether there is a trace conflict. While ST12 cannot tell you this unless another user is using ST12 tracing tool based on current version of ST12. ST05 allows you to enter SQL and do SQL execution plan verification and analysis directly. ST12 allows you to do this only when you are reviewing an existing SQL trace.

This post is on how to do a trace and navigation. If you would like to know how to tune SAP SQL performance, please refer to my post How to analyze SQLTrace to tune SAP program performance. I also have a post talking about how to analyze ABAP trace to tune ABAP program performance. For overall process of tuning SAP ABAP program performance, you can refer to my post SAP ABAP program performance tuning process .

SAP transaction ST05 can be used to trace execution of SAP program/job to catch performance statistics related to SQL statement execution, SAP enqueue operation, SAP RFC activities, SAP Buffer access and HTTP activities. So you can analyze trace to validate performance or identify performance bottleneck. SAP ST05 allows you to enter a SQL statement and analyze its’ execution plan without executing a program.

This post talks about

  • How to use SAP ST05 to do a trace such as SQL trace?
    • How to start ST05 transaction?
    • How to check ST05 trace status?
    • How to start/activate desired ST05 trace?
    • How to stop/deactivate a ST05 trace and display trace?
  • How to save, display/navigate through SAP ST05 trace?
    • How to understand information in the detailed trace screen.
    • How to understand SQL summarize SQL statement.
  • Other ST05 Trace lists and Call Stack trace.
  • How to enter SQL statement and verify execution plan?

If a SAP system has more than one instance/server, SAP ST05 can trace a program/job only when the program/job is executed in the server where SAP ST05 is turned on. Depends on your SAP ST05 version, your screen might looks a little bit difference from what is showed here but usage of each screen and information showed in each screen should be similar.

  1. How to use ST05 to do a SQL/Enqueue trace?

To trace an end-to-end SAP ABAP program execution: Run ST05 -> Check trace status -> start/activate trace with or without filter -> execute the SAP program -> stop/deactivate trace after the SAP program finishes.

  1. How to start ST05 transaction?

You can access SAP SQL tracing tool by typing “/nST05” transaction code into command window of your SAP screen with a “return/enter” key, Then initial screen of SAP ST05 similar to Figure 1 would appear.

Figure 1 ST05 SQL trace initial screen

Figure 1 – shows 5 steps of conducting a ST05 performance trace.

1.2 How to check trace status to know it is ready to turn on a ST05 trace?

ST05 transaction is an exclusive transaction – which means that there should not exist any ‘active’ trace on the SAP server/instance where you are going to do a trace. SE30 ABAP trace and ST12 ABAP trace (Not ST12 SQL/performance trace) can go parallel with ST05. If message like “All Traces are switched off ” is showed up in ST05 Initial screen like Figure 1, the system is ready for you to turn on the trace on the SAP server/instance.

Figure 2 ST05 status – not “ready” for new trace status

If ST05 initial screen showed that at least one traces is activated like what showed in Figure 2, it is not ready for you to do a trace on the server at the moment. In such situation, you can try one of following options

  1. Wait for completion of existing tracing.
  2. Try another server to do test and trace if possible.
  3. Ask other user to exit from the existing trace.
  4. You can proceed with your trace by deactivating active trace on “right” situations.

If a system has two or more application servers, two or more ST05
tracing can be turned on at the same time – each on one of application servers.

  1. How to start/activate desired ST05 trace?

To activated desired trace, you need to specify type of ST05 trace you need, filter and limited the trace to specific business process and start the trace.

1.3.1 Select ST05 trace type

SAP ST05 can do several types of trace – not all traces are relevant to a SAP program and not all relevant traces needs to be turned on dependent on the SAP program being traced.

To tell ST05 that what traces are expected, you can check or uncheck needed trace in “Select Trace” section showed in Figure 1. More than one trace at the same time based on your performance analysis requirement can be checked. Most of time, SAP ST05 is used to do SQL trace and/or ENQUEUE trace in my SAP experience.
A great book on SAP performance – SAP Performance Optimization Guide: Analyzing and Tuning SAP Systems, SAP Basis, SAP Administration

1.3.2 Select SAP program/process to be traced

Normally many programs/processes like Figure 3 are running in one SAP server/system, we need to tell SAP ST05 which business process to be traced.

Figure 3 SM50 many running programs/processes

SAP ST05 provides several options for you to enter filters to make ST05 trace more specific. Highlighted columns in Figure 3 are related to the predesigned ST05 filters which can be used to limit ST05 trace to specific job/transactions. If you do not specify filters, many headaches await you like a big trace file, overwritten trace file etc.

To enter the filters, you can click “activate trace with filter” button in Figure 1, then screen similar to Figure 4 would be showed up for you to enter filter to be able to trace specific process.

Figure 4 – ST05 Trace Restriction/Filter and start trace

User name is the SAP userID under which the program is going to run or has been running. Transaction/program name is the business transaction which we need to put trace on. Process number is SAP work process number where a business transaction is running with. Table name is the table which a transaction/program would access. Table 1 lists common filters and their explanation.

Table 1 – ST05 Filters and explanation

ST05 Filter Entered Explanation
User name Enter a user name to trace all activities happened under this specific user.
Transaction name Enter a transaction name to trace all executions of the transaction.
Program name Enter a program name to trace all execution of the program.
Process number Enter a SAP work process number to trace all activities which is executed in the SAP work process. This is to put a trace on an already- running process such as an active SAP background job. There is no way to know number of SAP work process which SAP would use to execute a SAP program unless the system has only 1 process of each type. So if end-to-end trace is needed, using an exclusive user-id might be a better choice.
Table Names Enter one or table names to trace all operations involved that particular table.
User + Transaction Trace all execution of that particular transaction under the specified user. If same user executes the same transaction two times at the same time, two executions would be captured into trace as well.
User + Process Number Trace all activities executed in the specified SAP work process as long as it is under the specific user.

In Figure 4, ST05 is instructed to collect SQL trace and Enqueue trace for all activities happened under a specific user in current SAP server.

If there is only one transaction running under your SAP logon and that is what you would like SAP ST05 to trace, you can simply click “Activate Trace” in Figure 1 after trace type is selected.

1.3.3 Start the ST05 trace

After desired filter is entered, you can start the ST05 trace by clicking the continue button showed in Figure 4. Your screen could looks like Figure 5, This means your trace request is started. Please check trace status to make sure that your trace request is accepted by SAP system. If you are doing an end-to-end trace on an online program execution, now the program can be executed.

Figure 5 – SAP ST05 Traces started

If you see message similar to what showed in Figure 6, then your trace is not started due to an active ST01 trace. You need to deactivate the trace using SAP transaction ST01 first to continue.

Figure 6 – ST05 Trace conflict with ST01

SAP ST05 cannot detect ST01 trace earlier in the way it detect other ST05 trace or ST12 trace.

1.4 How to stop/deactivate SAP ST05 trace?

You need to stop /deactivate the trace after business transaction being traced is completed or after desired duration. To stop trace, you click button “Deactivate Trace” showed in Figure 5. After ST05 trace is stopped, the ST05 screen is like what showed in Figure 7

Figure 7 – ST05 Trace stopped

2 How to save, display/navigate through SAP ST05 trace?

After Step 1.4, you have a SQL trace. Now you can save your trace for future review or you can review your trace now. Most important ST05 screens are trace list screen which is available for all ST05 trace, Summarized SQL statement screen and SQL execution plan screen which are applicable for SAP ST05 SQL trace only. You can also access Call stack screen. ns

2.1 How to save/delete a SAP ST05 Trace?

Following the menu path “Performance Trace -> Save Trace”, the ST05 would ask you to give a file name to save your trace. Under the same menu, ST05 provides options to delete saved trace as well.

The reason to save a trace is to avoid the trace being overwritten by subsequent trace activities.

2.2 How to display a SAP ST05 Trace?

You can display a ST05 trace by clicking “Display Trace” button in Figure 7. You can use menu path “Performance Trace -> Displayed Saved Trace” to display a previous saved ST05 trace

Following the click, SAP ST05 would present a screen similar to Figure 8 to allow you to specify what trace records would be selected and displayed.

Figure 8 Filters to display trace

You can make following choices:

  1. Trace type – if you have collected several traces at the same time, you can analyze one trace such as SQL trace at a time.
  2. Trace window –If you have traced a long time, you can specify a smaller period of that tracing for review or review the period you are interested
  3. Further restriction – If you are doing trace based on SAP transaction code and several users are running that transaction during the trace period, you can review the trace records related to specified SAP user by entering his USR ID here.

After needed input is provided, you can click “continue” button in Figure 8 to display trace records. If number of trace records which meets your above choice is more than 5,000 records, then a pop-up window similar to Figure 9 would show up.

Figure 9 – more ST05 trace record meets your selection

You can click “yes” to display all records or no to display just 1st 5,000 records depends on your situation. For example, if your program is keeping executing a same set of SQL again and again, 1st 5,000 records might be enough. It takes time and system resource to display all records. In worst cases, ST05 can get timeout/memory error due to huge number of records collected.

How many trace records would be collected depends on two factors – trace period and program design. If a program is long running but with a few database accesses, SQL trace on such program would have a few records.

In normal case, SAP ST05 would present “Trace List” screen similar to Figure 10.

Figure 10 – ST05 Trace List screen

SAP ST05 displays all trace records according to the time sequence when it is captured by default. You can return to Figure 8 screen by clicking one of two SAP screen navigation buttons in Figure 10 so you can select to review another trace. allow you to exit current SAP screen and return to previous SAP screen.

Pay attention to menu item “Trace list” (red circled in Figure 10), you can access several other ST05 screens. I normally use “Summarized SQL Statements” screen first. If “summarized SQL statements” screen shows a lot of “Identical selection”, I might go back to “Trace List” screen” to review “List Identical Select Statements” screen. Referring to Figure 11 for the menu path for those additional ST05 screens

Figure 11 – ST05 Trace List dropdown Menu

To get “Summarized SQL statements” screen similar to Figure 12, you can click “Trace List”->”Summarize Trace by SQL Statement”.

Figure 12 – SAP ST05 Summarized SQL statements

To get “Identical Select statements” screen similar to Figure 13, you can click “Trace list” -> “Display Identical Selects”

Figure 13 – SAP ST05 Identical Select Statements

Sometimes, SAP ST05 might send you a pop-up window with message “File end of performance trace file detected -> See long text” instead of display the trace list. If you see message like this, this normally means that trace has not captured anything or something unexpected happens. This can be your error(wrong input) or sap/system problem. You got to redo the trace.

2.3 SAP ST05 Trace List screen

SAP trace list screen layout is shared by all SAP ST05 traces. The same column in Trace list screen might mean something different in different trace.

2.3.1 SAP ST05 Trace List Screen – Understanding trace records

Please refer to Table 2 to understand fields/columns of trace records.

Table 2 – SAP ST05 Trace record explanation

Column Explanation
Time when trace record was created.
Duration of the recorded operation in the same row.

  • SQL trace: duration of SQL operation.
  • Enqueue trace: duration of a lock operation.
  • RFC trace: Duration of RFC operation.
Name of program which is related to the statement of the row.
Depending on the type of trace, the object to which the trace statement refers is specified here.

  • SQL trace:   Name of the table or DB procedure.
  • Enqueue trace: Name of the lock object.
  • RFC trace:       Abbreviated name of the instance on which the function module is executed.
Type of operation executed:

  • SQL trace: FETCH, OPEN etc
  • RFC trace: CLIENT or SERVER
  • Enqueue: ENQUEUE, DeQUEUE or DEQAll etc.
Cursor # (SQL trace only), blank for other traces
maximum number of rows requested from or sent to the database (SQL trace only), “0” for other traces
Depends on trace type.

  • SQL trace – Number of records returned or changed or inserted.
  • Enqueue trace – number of granules.
  • RFC trace – number indicates type of the RFC trace records. 1 – completed
Return code for the operation. Operation success indicator.

  • SQL Trace: return code of Database system.
  • Enqueue Trace: 0 – success, 2 – collision, 8 internal error.
  • RFC trace: 0 – success.
Name of database connection
Operation details.

  • SQL trace: SQL statements.
  • Enqueue trace: Lock mode, table, lock argument.
  • RFC Trace: Source, target, client/server, FM, bytes sent or received.

2.3.2 SAP ST05 Trace list screen – associated operations

SAP has built in many operations/functions for you to review and analysis performance in Trace List screen. Please refer to Table 3 for list of functions and how to execute a function.

Table 3 – SAP ST05 trace list – Associated operations

Icon/Button Explanation How to use this
Display details about operation Select a line/row in the trace list screen, then click this.
Display Dictionary data Select a line/row in the trace list screen, then click this.
Display SQL execution plan Select a line/row in the trace list screen, then click this.
Display SQL source code Select a line/row in the trace list screen, then click this.
Display Call stack/Hierarchy Select a line/row in the trace list screen, then click this.
Analyzed SQL statement Select a line/row in the trace list screen, then click this.
Replace “placeholder” in SQL
statement with value
Select a line/row in the trace list screen, then click this.
Display details of trace record Select a line/row in the trace list screen, then click this.
Sort Trace list Click on the row header like duration, then click this.
Search in the Trace list Click this icon, then enter search string( table name etc) to continue.
Filter display Click this icon, then select a column (like object), enter data like table name etc.

2.4 SAP ST05 Summarized SQL statements screen

Unlike Trace list screen, summarized SQL statement screen is only applicable to SQL trace. If you would like to review SAP program’s SQL performance or tuning SQL performance, i would suggest that you start with this screen. If you would like to validate a SQL change, the summarized SQL statement screen can help as well, of course, you need two summarized SQL statements screen – one is before change and one is after change.

2.4.1 SAP ST05 Summarized SQL Statements screen – Understanding Summarized SQL statement

You need to understand the screen first before we can take next step to analyze SQL performance. Table 4 is to help you to understand the summarized SQL screen of SAP st05 SQL trace.

Table 4 – SAP ST05 Summarized SQL statement field explanation

Column Explanation
Total number of executions of the statement by database engine – not logical execution based on source.
= number of the SQL execution hit the same table record – 1.
Percentage of statements that are identical. For example, if you read the same order from order table 10 times for different fields at different time, total number of execution would be 10, total number of redundancy would be 9. % would be 90%.
Summarized duration of all executions for the SQL statement.
Number of processed records for all executions.
Average execution time per SQL statement execution.
Average number of rows (records) processed per SQL statement execution
Average processing time required per record/row.
Minimum processing time required per record/row.
Record length of the table.
Type of buffer if table is buffered. FUL – bully buffered, DeFul – fully buffer is possible but not enabled.
Table type.
Name of table or database procedure.

2.4.2 SAP ST05 Summarized SQL Statements screen – Associated Operations

In ST05 Summarized SQL statement screen, SAP has built in many operations/functions for you to review and analysis performance. Please refer to Table 5 for a list of common operations/functions and their operations.

Table 5 ST05 Summarized SQL statements – associated operation

Icon/Button Explanation How to execute to the function
Display all trace records for the summarized statements Select a line/row in the screen, then click this.
Display SQL statements Select a line/row in the screen, then click this.
Display Dictionary data Select a line/row in the screen, then click this.
Display SQL execution plan Select a line/row in the screen, then click this.
Display SQL source code or calling positions if SQL is called from different location of program Select a line/row in the screen, then click this.
Analyzed SQL statement Select a line/row in the screen, then click this.
Different views of a row Select a line/row in the trace list screen, then click this.
Sort Trace list Click on the row header like duration, then click this.
Search in the Trace list Click this icon, then enter search string( table name etc) to continue.
Filter display Click this icon, then select a column (like object), enter data like table name etc.
Dowload/save list as word document or html document etc Click this icon, choose select download file type, then follow screen instruction.

Most accessed function is “display SQL execution plan” – this would be covered in below section.

You can review SAP ABAP source code related to a particular SQL as well. Figure 14 shows navigation steps from summarized SQL statements to SAP program source code. It also demonstrates that one SQL in summarized SQL statements screen can have multiple call locations/positions. In SQL Trace list, it would take you directly to the source code after you click “review source code” icon/button. Reviewing source code can help you to understand why the SQL has been executed so many times etc., for example, the SQL might be inside a ABAP loop.

Figure 14 ST05 trace – From summarized SQL statement to source code

2.5 ST05 SQL Trace – SQL execution plan screen

When a ST05 SQL trace shows that a SQL is expensive with a few executions, The SQL and its’ execution plan has to be reviewed. You can access execution plan of a SQL in “Trace list screen” and “summarized SQL statements” screen etc. To get execution plan for a SQL, you select the SQL by placing cursor on the line/row, then you click “Explain” button/icon, SAP ST05 display would be changed and you would see screen similar to Figure 15 showing execution plan for specified SQL.

Figure 15 ST05 Trace – SQL execution plan

From Figure 15, you can review further information on the table and index status, index details for the index being used, SQL table Access Predicates and records filters. Based on the review, you might like to take further action like table/index rebuilt or statistics updates etc. which can be accessed from SQL execution plan screen as well. I clicked the table name and index name in Figure 14, I got Figure 16 showing Table index information and detailed index information. Rebuilding of table and index and updating of table statistics are done by a separate SAP program or Database tool.

Figure 6 – ST05 Trace Table & index info as well as current index details

I have to stop short of Explaining data in Figure 15 like index selectivity (Number of Distinct fields), Clustering factor to keep this post short.

3 Other ST05 Trace lists and Call Stack trace

Here only Enqueue trace list and RFC trace list are showed here so you know what they looks like.

3.1 SAP ST05 Enqueue trace list

When SAP locking is an issue to performance, you can take an enqueue trace for performance analysis. Figure 17 is a part of SAP enqueue trace list.

Figure 17 ST05 Enqueue Trace list screen

If you double click the statement, you would see screen similar to Figure 18

Figure 18 ST05 Enqueue trace record detail

Please pay attention to the red circle fields in Figure 18. They can tell what user and process is blocking current lock request. This is important to identify root cause of SAP enqueue( SAPLSENA ) issue.

3.2 SAP ST05 RFC trace list

RFC trace can tell you what RFC is executed during the program execution. If you need to do such trace, you can get trace list screen similar to Figure 19.

Figure 19 – ST05 trace – RFC trace list

This would help to identify which RFC call is bottleneck of the performance so improvement plan can be worked on.

3.3 SAP ST05 Call stack

If you read status message carefully in Figure 1, there are three messages ” All trace “, “Call stack deactivated” and “Progress display off”. Call stack or Call Hierarchy is a calling tree so you know which subroutine is executing the operation such as SQL execution and who is calling the subroutine and so on. When Call Stack is deactivated, SAP ST05 would not track the call hierarchy. Call hierarchy can help you understand the business logic/process related to an operation like SQL execution. When Progress display is on, then SAP ST05 would show you progress status of formatting trace records when you try to display “trace list”.

If SAP ST05 is expected to log call hierarch, you need to activate call stack tracing before you click “activate” or “Activate Trace with Filter” button in Figure 1. To turn on the stack trace, follow the menu path “Performance trace ->Activate Stack Trace”. After trace is completed, you just click the row and then click the “Call stack” button to know the hierarchy of the call in Trace list screen. Figure 20 is a call stack sample screen from ST05 SQL trace list.

Figure 20 – ST05 Call stack list

4 How to use ST05 to enter an SQL statement and verify SQL execution plan?

You might need to verify index execution plan across SAP landscape or verify whether a table statistics update etc. has made any difference to SQL execution plan. For example, if one SQL in a program has production performance issue due to table access and the program is working fine in testing environment, you might want to check SQL execution plan difference between two boxes. Of course, you can execute the program in two boxes with ST05 trace to find this out. But SAP ST05 has a quick way for you to verify SQL execution plan in different boxes such as testing box and production box.

In Figure 1, you can click button “Enter SQL statement”, following screen would appear for you to enter SQL statement for analysis.

Figure 21 ST05 – Enter SQL statement

Following is the SQL statement I need to verify –

SELECT “REGIO”, “LAND1” FROM “KNA1” WHERE “MANDT”=:A0 AND “KUNNR”=:A1

Figure 22 – ST05 Analysis SQL statement – Entered SQL statement

After I clicked “Explain” button, Execution plan of above SQL in the system is displayed as showed in Figure 23.

Figure 23 – ST05 analysis SQL statement – execution plan

You can manipulate the where clause of the SQL statement like adding other fields from the table to see how execution plan would change or playing with database hints. You can copy a SQL from SQL cache and paste here or load a SQL from a local file instead of typing.

5 Further information

SAP transaction ST12 can be used to do both SQL and ABAP trace. It is my preferred SAP performance tracing tool. But if you would like to do only SQL trace, SAP transaction ST05 can be easier and can be quickly launched. ST05 tool can tell you whether there is a trace conflict. While ST12 cannot tell you this unless another user is using ST12 tracing tool based on current version of ST12. ST05 allows you to enter SQL and do SQL execution plan verification and analysis directly. ST12 allows you to do this only when you are reviewing an existing SQL trace.

This post is on how to do a trace and navigation. If you would like to know how to tune SAP SQL performance, please refer to my post How to analyze SQLTrace to tune SAP program performance. I also have a post talking about how to analyze ABAP trace to tune ABAP program performance. For overall process of tuning SAP ABAP program performance, you can refer to my post SAP ABAP program performance tuning process .


One thought on “How to run SAP transaction ST05 to trace a SAP program execution and review trace”

Leave a Reply