Undoubtedly, the most important tool in a ABAP programmers toolbox is the ABAP debugger, but here in this tutorial we are not going to focus on that, rather we will focus on “Tools for Analysis”. In a later article I will focus on “Tools for Troubleshooting”.
Tools for Analysis
ABAP Code Inspector (TCODE – SCI)
With the help of the code inspector you can check your ABAP code for performance, security, syntax, error proneness and Statistical information. You can perform different code checks using this tool on a single object (simple check on programs, function modules or classes) or a set of objects (special check on set of objects).
Example of Checking a single object:
Calling code inspector for single objects is very easy, to call it from programs go to Program (SE38) then from the menu choose Check=> Code Inspector
From Function Modules go to Function Modules – SE37 then from the menu choose Check=> Code Inspector.
And from a class go to Class (SE24) then from the menu choose Check=> Code Inspector.
After calling the code inspector your ABAP code will be checked using the Default Check Variant deliver as standard for the Code Inspector, but you can create your own Check Variant. When the code inspector finishes its inspection you will get the results in hierarchal order.
This hierarchy contains list of checks on each category i.e. Performance, Security, Syntax, and General. By going down the hierarchy we can see the ‘Messages’ which contain the source code position and a short explanatory text.
To get the detailed information for each check that was performed click on the information icon besides the message.
And by double clicking on the message text you can go to the inspected line of code.
Checking object set: We will learn how to use code inspector to check Object Set in the separate tutorial dedicated on that.
We have seen a simple way to analyse our program for Performance, Security, Syntax, Error proneness, and Statistical information using code inspector. It is important to understand some of the limitations of the Code Inspector:
- Inability to handle ABAP Joins and Database Views.
- Inability to detect LOOPS in called MODULES.
ABAP Runtime Analysis (TCODE – SE30)
With the help of the ABAP Runtime Analysis tool you can check the performance of any ABAP Reports, Function modules or Classes. Using this tool you can interrogate the execution time of your code and evaluate your program on an ABAP code, Database and System level.
To start the ABAP Runtime Analysis go to transaction code SE30 and then select the radio button based on what we want to evaluate. In this example we will learn how to evaluate a program using the ABAP Runtime Analysis tool, but the process is the same for Classes and Function modules. Select the program radio button and enter the name of your Program.
Now, click on the Execute button. After pressing the Execute button you will see the selection screen of your report and in the status bar you can see the message as ‘Measurement Started’.
Now provide the required values in the Selection Screen of report and hit the F8 button.
After finishing the execution return back to the initial screen of the ABAP Runtime Analysis by pressing the back button.
You will see the following message at the status bar.
When you return back to the Runtime Analysis screen you will find some new parameters added in this screen as shown below.
Click on the Evaluate button and you will see the overview of the Runtime Analysis Evaluation in a graphical format.
As mentioned before the total time is evaluated in three parts ABAP, DATABASE and SYSTEM.
From the total time we can say whether our program is fast or slow but to dig deeper and work out how to optimize performance, take a look at the percentages. This will give us a good starting point as where to begin further interrogation.
The important measured values are ‘No.’ (column 1), ‘Gross’ (column 2), and ‘Net’ (column. 4). They tell us how often an operation was executed (column 1), and how much time it required, either as a total including sub-operations (Gross time – column 2), or without sub-operations (Net time column – 4). Remember that the times are measured in microseconds (ms) and that the shown times are the total times, not the times per execution.
Performance Analysis (TCODE – ST05)
With the help of the Performance Analysis tool we can perform SQL Trace, Enqueue Trace, RFC Trace and Table buffer Trace. Using SQL Trace we can monitor database access, Enqueue Trace help us to record locking activities, RFC Trace provides information about remote calls between instances and Table Buffer trace is nothing but the memory trace. All of this is recorded in a trace file for you to view and analyse.
To start the Performance Analysis tool go to transaction code ST05. Here you can see the Trace screen with all the Trace Options. By default the SQL Trace check box is selected.
Now, in a new session open your report program which you want to trace. After preparing your report for execution i.e. providing all the selection screen parameters, return to the Performance Analysis screen and click on the ‘Activate Trace’ push button.
Now, return to your report and hit the F8 button to execute.
When the report has successfully executed, go again to the Performance Analysis screen and click on the “Deactivate Trace” push button.
Now we can view the Trace results by clicking on the “Display Trace” push button.
Once you press the Display Trace push button, you will see a dialog window where you can set restrictions to display the trace file contents.
After entering your restrictions click enter to view the Trace List.
In the top row Trace List displays Transaction, Work process Number, Process Type, Client and User. In the Trace List you can see the runtime duration for each of the statements in milliseconds & microseconds, name of the database table accessed, operation which is performed on the database, number of records processed, complete statement and its return Code.
By selecting a row and the clicking on the Explain tab we can see the detail execution plan of that statement.
In the screenshot below you can see the ‘Estimated Costs = 3’, but for optimum performance this value must be ‘1’. This tools is used very often and I recommend you master it to help improve and optimize your program executions.
Summary: In this tutorial we have seen how easy it is to analyse our ABAP code by using these SAP provided tools. These tools will definitely help us in optimizing our ABAP code, enhance their performance thereby reducing the total workload on our system.
In the next article on ABAP Programming With The ABAP Workbench, we will learn to use tools which will help us troubleshooting ABAP code quickly and efficiently.