ABAP performance analysis with SAT transaction

Every once in a while, you will encounter ABAP programs taking too long to run. Your duty, as an ABAP developer, is to find the bottleneck. Sometimes it is as easy as debugging the program just once, or even just looking at the code. Sometimes not.. This is where SAT comes in. It is a useful tool which helps us to find out which statement or procedure is running for too long.

Here is a test report that will help us to get to know SAT..

Before running the report, we call transaction SAT..

Analysis tool starts with this screen. Before executing analysis, we might need some change with settings. Click copy button in settings section to create a new variant.

We are asked a new name for our settings variant. Same name ‘DEFAULT’ can be used since the user is changing. Confirm the dialog after you are done.

Now we are ready to change our new variant. Click edit button.

Duration and Type tab looks fine. If you have a report that runs for more than 30 minutes you can change maximum execution time.

Statements tab has more options. With default settings, SAT focuses on database operations and does not measure internal table operations. Sometimes read, loop and collect statements take considerable time if the code is not well-written.

So enable those options and click save.

Now we are ready to start analysis. Enter transaction code, program name or function module name and click execute.

After you click execute, your program starts to run. You will see all selection screens, dialogs and output as always and enter any input you like. SAT does not measure time passed waiting for user interaction. Our test report produces an ALV grid.

Hit back button to leave the report and SAT will build a result screen with two panes. Since right pane is the useful part, just close the left pane with cross icon.

Let’s look closer at the result report. Each row in the report is a statement in our program. Those statements might be database access or internal table operations as well as method, function or subroutine calls. First column (Hits) is the count of how many times the program reached that statement. You might have guessed that statements having a high hit count has run in a loop. Next two columns (Gross [microsec] and Net [microsec]) are the actual time in microseconds (one millionth of a second) spent on that statement. Gross time includes the time spent on inner statements while net time does not. Gross time of a loop is the whole time spent on the loop from start to finish. Net time is only processing time to determine which internal table rows will be looped over. So, a loop with a where condition on an unsorted table might raise net time. What is done inside the loop is irrelevant here. That just affects gross time. Similarly, gross time for a procedure (method, function, subroutine) is the whole time spent on it from start to finish. Net time is only entry and exit processing (like assigning or clearing memory areas for parameters and local variables) of the procedure. So, as a rule of thumb, you should look at gross time for procedures and net time for individual statements to evaluate the result. Next two columns, Gross [%] and Net [%] are like previous two columns, but they give percentile fraction of whole programs processing time instead of duration. You can see statement information on following columns. Double clicking on a row will bring us corresponding statement in ABAP editor.

Descending sort on column Net [%] will probably point us where to look first. This is an internal table read, it has run 100.000 times and took %80 of all time.

Double click on the row and examine the statement. We are accessing a large standard internal table without binary search.

Let’s fix our code. Sort the table and add BINARY SEARCH to read statement.

After running our report with SAT for a second time, we will see that fixed read statement is no longer on top of the list.

You can also compare results of different executions in evaluate tab of first screen in SAT.

Total time of each measurement can be seen in “Runtime” column. You can double click on any row to examine each analysis in detail. Keep in mind that those results will not remain there forever.

Experiment on performance: SELECT SINGLE vs FOR ALL ENTRIES, secondary index access

Experiment on performance series


Part II: SELECT SINGLE vs FOR ALL ENTRIES, secondary index access

I believe our previous test on SELECT SINGLE vs FOR ALL ENTRIES did not surprise many of you because I see a tendency towards FOR ALL ENTRIES in programs I encounter. In previous scenario, we were able to access the search table with primary key but this may not be the case every time. Let’s see what happens if we could not access the search table with primary key, but with secondary index. Continue reading “Experiment on performance: SELECT SINGLE vs FOR ALL ENTRIES, secondary index access”

Experiment on performance: SELECT SINGLE vs FOR ALL ENTRIES

Experiment on performance series

When all business requirements are met in a development, customer complaints always come down to performance. “Can’t this run any faster?” we always hear. Performance, in a technical point of view, is a broader concept that not just includes execution time, but also optimal use of system resources like memory and network load.  But powerful hardware of our age and requirement of end user satisfaction leaves us with a single option to have execution time (or speed) as the top priority performance aspect. So I will experiment on some known techniques for database access and internal table processing, and share the results here. Continue reading “Experiment on performance: SELECT SINGLE vs FOR ALL ENTRIES”

ABAP by numbers: Length of decimal type

Inequality between length and maximum digit count of packed decimal type causes great confusion even among seasoned developers. ABAPDOCU explains the relation with a fairly complicated formula:

Depending on the field length len and the number of decimal places dec, the following applies to the value range: (-10^(2len-1) +1) / (10^(+dec)) to (+10^(2len-1) -1) /(10^(+dec)) in increments of 10^(-dec)

Continue reading “ABAP by numbers: Length of decimal type”

Obligatory selection screen parameters

Almost every ABAP developer comes to a point where they require obligatory parameters along with user command logic in their selection screens. As you might already know, that’s a problem. Because obligatory parameters demand input on every action of user and interfere with user command logic, which results in a broken selection screen. Let’s see an example. Continue reading “Obligatory selection screen parameters”

ERROR_MESSAGE: Predefined exception for function modules and methods

No matter how many times mentioned before (thanks to Rahul GopinathAmit BeheraSrinivas Dummu and Mike), I still see sy-subrc check after a function module call without exceptions.

This is so wrong. According to ABAP keyword documentation:

If no exception is raised, a call sets sy-subrc to 0.

So in the above example, sy-subrc will always be equal to zero and condition will never be satisfied. This applies to method calls, too. Let’s experiment to make sure. Continue reading “ERROR_MESSAGE: Predefined exception for function modules and methods”

Hello ABAP world!

Greetings to fellow SAP ABAP developers from around the world. I have just decided to start a new ABAP blog (yes, yet another) and this first post is here just to share my excitement.

So why another ABAP blog?

Of course I know there are already many ABAP blogs and tutorial sites who are actually doing great job. They give us useful tips on solving problems. But I will not only focus on solving problems but another aspect of programming: quality of code. Continue reading “Hello ABAP world!”