鶹TVվ

Scroll Top

ABAP Database SQL Analysis Using The Performance Trace – Part 1

Tony CecchiniAnthony Cecchini is the President of Information Technology 鶹TVվ (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 17 years of experience in SAP R/3 business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at [email protected].

 

Performance ProblemsCome in a Variety of Flavors

There are many reasons for slow execution of a transaction or areport. Sometimes there are general system problems. Sometimes usersuse the program in a way it was not designed for. Sometimes the natureof the application and workload calls for parallel processing. Andsometimes the source of the performance issue can be traced back to your ABAP code, mainly the construction of your OPEN SQL Definition.

While there are many reasons other than database performance that could be causing the performance problem, this blog series will focus on just this aspect. If you’ve ruled out deficiencies in the system setup, mishandling byusers, or the need for parallel processing, then you need to revisit yourcode and see if the source of your performance problem is hiding there in your SQL commands.

Lets agree now thatall programs perform numerous accessesto the database, so thisshould be considered thoroughly.For example, selections that are not supportedby a suitable index can have long (very long!)runtimes. This not only potentially impacts therunning programs themselves, but is also an encumbranceto all users, as they have only limited accessto the database if it is blocked by some long-runningselections.

Analyzing Database AccessActivities with Performance Trace

If you found (or have assumed) that the long runtimeis caused by database accesses, use the PerformanceTrace tool (transaction ST05) for further analysis.With Performance Trace you can record all accessesto the database coming from the instance.

As you can see in the steps below, you typically startthe trace in one session (1), start the program youwant to test in another session (2), switch off the traceafter the end of the program (3), and then analyze therecorded data (4).

ST05 Sequence of Steps

Let’s take a look atthe start screen of the PerformanceTrace tool.Before we examine the details ofusing this tool, it is important to note the followingconsiderations:

– Performance Trace records only the informationcoming from the work processes on the sameinstance. Consequently, if you are using RemoteFunction Calls (RFCs) or asynchronous updatesin your program, the database accesses from thesemodules will not be recorded if they are executedon other instances.

– Performance Trace can be used by only oneuser at a time on each instance. Before usingthe trace, please make sure that it is currentlyswitched off and not already in use. You can see this by the “Trace Statusat the bottom of the start screen.

ST05 start screen

 

– The trace information is written to a file of afixed size. If the size limit of the file is reached,the oldest data is overwritten. Therefore, itis possible that the trace information of a long runningprogram will be incomplete and you willonly see the most recent data. Data from older tracesremain in the trace file only until the space isrequired for new trace information.

As you can see in the screen shot above, there are five differenttrace modes for the performance trace:

SQL Trace covers all database accesses.
Enqueue trace covers all enqueue operations.
RFC Trace covers all RFC communications fromand to the instance
Buffer trace covers all accesses to the tablebuffers on the instance.
HTTP Trace coversresponse time end to end, time spent for execution on the server, Bytes sent and recieved, andtime for data transfer both sent and received. (e.g. If you were connected via CITRIX and wanted to trace)

For the analysis of database accesses, it is sufficientto activate just the SQL trace. The enqueue,RFC, and buffer traces are useful for a performanceanalysis if you know (or suspect) that enqueuerequests, RFCs, or accesses to the table buffers aretaking more time than they should.When you start the trace, you can select whetheror not you want to record data from all programsrunning under your user name on the instance (ActivateTrace button) or if you want to define some filters(Activate Trace with filter button).

st05 activate

The screen shot belowshows your options for narrowing thedata to be traced. You can select data from programsrunning under another user’s name, select or excludecertain tables, restrict the data to a specific workprocess (e.g., if you start the trace when the programis already running), etc…

st05 restricted

By pressing the Deactivate Trace button in the startscreen of ST05 the trace is stopped. WithDisplay Trace,your options for filtering the datato be displayed is shown. You can select the type of informationto be displayed (SQL, enqueue, RFC, buffer);you can specify the timeperiod in which the data was recorded (by default it isthe period of the last recorded trace); you can selectthe name of the user whose data should be displayed;and you can select the tables you want to see (ornot see). You can select the number of trace records to display (default is usually 5,000). There are many restrictions you can enforce besides the ones I am describing. Please consult the SAP help.

st05 display restrictions

Now with a click of the green checkCode Inspectorwe see the results below.

st05 trace list

Let’s take a look at how to interpret all ofthis performance data.The columns shown (from left toright) have the following meanings and the items highlighted in red, are the most important when discussing performance.

HH:MM:SS.MS — The time at which theoperation was executed
Duration— The duration of the operation
Program— The name of the ABAP program
ObjectName— The name of the affected table
Op.— The database operation
Curs— The used cursor
Array— The number of records that can betransferred in one step from the database
Recs— The number of records that were read orsent to the database (e.g., when inserting data)
RC— The return code from the database
Conn— The name of the database connection
Statement— The statement as it arrives at thedatabase

Sometimes the line that indicates the duration ofthe operation is shaded in red, which means that theduration time exceeds 100 ms. Please understand that this doesnot necessarily mean there is a performance problemwith this access, as you always have to take the numberof processed records into consideration for context. Forexample, reading 1,000 records in 200 ms is a good result, but reading only 5 records in 80 ms is not very good. That said, in the abovecase, where theduration time is high although the response time perrecord is not, you should still check whether this highnumber of records is really required — perhaps youdo not really all these records returned and can reduce the result set returned, thus boosting performance as well.

Memory Analysis

As a rule of thumb, a processing time ofup to 2-5 ms per record is okay, and thus need notbe a major concern to you at this time, even if it can bepotentially be faster.

 

In the column Program, you see the name of theABAP program where the access was coming from.In order to navigate to the code belonging toit, place the cursor on the line with the statement inquestion and select the ABAP display button ABAP sourceor use the menu path Goto → Display ABAP Source, or even hit F5 key.

 

ST05 display ABAP Source

 

ST05 ABAP source

 

The column ObjectName contains the name ofthe database table affected. If you want to see someinformation from the DDIC (the Data dictionary) for aparticular table, place the cursor on a line containingthat table and select the DDIC info button ST05 DDIC Button, or use the menu path Goto →DDIC information, or hit F6 key.

ST05 DDIC Display

 

st05 ddic display

 

The column Rec tells you how many databaserecords were read and transferred to the applicationserver in one step (FETCH operation). Sometimesthe result of the query consists of more records thancan be transferred in one step. In this case, youwould see several lines with repeated FETCH operations. In the example below, you can see I was executing a VA03 (Sales Order Display) for S/O # 4988. You would expect to see a REC of 1 and we do, as this Sales Order does exist.

ST05 VA03 Trace

In the final column (Statement) you see thestatement as it was handed over to the database.This usually looks a little different from the originalABAP statement because it was transformed bythe Open SQL layer on the instance. The completestatement is displayed when you place the cursoron the line with the statement in question and selectthe details button , or follow the menu path Edit → Choose, or hit the F2 key. At the bottom of the statement you can see the values that were used for each variable in the WHERE statement, as well as their data type and length within the parenthesis (e.g CH, 3 is data type CHAR and a length of 3).

ST05 VA03 SQL Display

ST05 VA03 SQL Display

 

Summary and what’s next…

OK, we learned about the Database Performance Trace. We learned how to execute it via the transaction ST05, and the normal sequence of events when taking a trace snapshot. We saw how to filter what we wanted to trace, as well as filter the display once a trace has been taken. We also took a deep dive into the Trace results, learned about the columns and some nice shortcuts into the code, DDIC information, and SQL statement passed to the back-end DBMS. In the next Blog, we dig in and see how to find a performance issue with this trace tool.

ITP logo

If you enjoyed this blog, ABAP Database SQL Analysis Using The Performance Trace – Part 1, please fill out the form below to sign up for our newsletter. We deliver SAP Technical tips & tricks, SAP news, and the current month’s BLOG right to your inbox!

Related Posts

Related Posts