SAP ABAP Performance Analysis
SAP ABAP Performance Analysis
1. ST05 is the performance trace. It contains the SQL Trace plus RFC, enqueue and buffer trace. Mainly
the SQL trace is is used to measure the performance of the select statements of the program.
2. SE30 is the Runtime Analysis transaction and can be used to measure the application performance.
3. SAT transaction is the replacement SE30. It provides same functionality as SE30 plus some additional
features.
4. ST12 transaction (part of ST-A/PI software component) is a combination of ST05 and SAT. Very
powerful performance analysis tool used primarily by SAP Support.
5. One of the best tools for static performance analyzing is Code Inspector (SCI). There are many options
for finding common mistakes and possible performance bottlenecks.
1. Database
a. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
b. Design the Query to use as many index fields as possible from left to right in the WHERE statement
c. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot
d. Avoid using nested SELECT statement and SELECT within LOOPs, better use JOINs or FOR ALL ENTRIES.
Use FOR ALL ENTRIES when the internal table is already there. Try JOINs if the SELECT statements are
right behind each other.
e. Avoid using ORDER BY in SELECT statements if it differs from used index (instead, sort the resulting
internal table), because this may add additional work to the database system which is unique, while
there may be many ABAP servers
f. INDEX: Creation of Index for improving performance should not be taken without thought. Index
speeds up the performance
but at the same time adds two overheads namely; memory and insert/append performance. When
INDEX is created, memory is used up for storing the index and index sizes can be quite big on large
transaction tables! When inserting a new entry in the table, all the indices are updated. More indices,
more time. More the amount of data, bigger the indices, larger the time for updating all the indices
g. Avoid Executing an identical Select (same SELECT, same parameter) multiple times in the program
h. Avoid using join statements if adequate standard views exist.
2. Table Buffer
a. Defining a table as buffered (SE11) can help in improving the performance but this has to be used with
caution. Buffering of tables leads to data being read from the buffer rather than from table. Buffer sync
with table happens periodically, only if something changes. If this table is a transaction table chances are
that the data is changing for particular selection criteria, therefore application tables are usually not
suited for table buffering. Using table buffering in such cases is not recommended. Use Table Buffering
for configuration data and sometimes for Master Data
b. Avoid using complex Selects on buffered tables, because SAP may not be able to interpret this
request, and may transmit the request to the database. The code inspector tells which commands
bypass the buffer.
3. Internal Table
b. Use assign (field symbol) instead of into in LOOPs for table types with large work areas
c. Use READ TABLE BINARY SEARCH with large standard tables speed up the search. Be sure to sort the
internal table before binary search.
4. Miscellaneous
a. PERFORM: When writing a subroutine, always provide type for all the parameters. This reduces the
overhead which is present when the system determines on its own each type from the formal
parameters that are passed.
The effect of FOR ALL ENTRIES needs to be observed first by running a test program and analyzing SQL
trace. Certain options set by BASIS can cause FOR ALL ENTRIES to execute as an 'OR' condition. This
means if the table being used FOR ALL ENTRIES has 3 records, SQL Trace will show 3 SQLs getting
executed. In such a case using FOR ALL ENTRIES is useless. However of the SQL Trace shows 1 SQL
statement it's beneficial since in this case FOR ALL ENTRIES is actually getting executed as an IN List.
JOINS are recommended to be used till 5 joins. If the JOIN is being made on fields which are key fields in
both the tables, it reduced program overhead and increases performance. So, if the JOIN is between two
tables where the JOINING KEYS are key fields JOIN is recommended over FOR ALL ENTRIES.
You can use for all entries to reduce the database hits, and use non-key fields.
FROM LIKP AS A
ON A~kunnr = B~KUNNR.
w_likp2-KUNAG = w_likp-KUNAG.
ENDLOOP.
FROM kna1
ENDIF.
Avoid use of nested loops
When a nested loop has to be used, use a condition for the inner loop. Otherwise in the production
environment it may be possible that the loop takes a lot of time and dumps.
loop at itab1.
....
endloop.
end loop.
Another option is to use READ with BINARY SEARCH for the second table.
if sy-subrc = 0.
idx = sy-tabix.
exit.
endif.
....
endloop.
endif.
endloop.
Parallel Cursor :
---------------------------
But, the cost, in terms of performance, is higher when we use the nested loops. This cost would become
a key issue when working with huge tables
e.g. BKPF & BSEG, VBAK & VBAP, MKPF & MSEG. Sometimes, this cost increases and reaches to the point
where program fails to finish the execution.
We have the concept of Parallel Cursor exists in ABAP to overcome this hurdle and reduce this cost.
In parallel cursor, we first try to see if there is any entry exist in the second table inside the LOOP
construct of first table.
We use the READ .. WITH KEY .. BINARY SEARCH to check if the entry exist in the second table.
We use this record number SY-TABIX to LOOP on the second table using LOOP .. FROM index.
Sample Program :-
REPORT ztest_np_parallel_cursor.
it_vbap BY vbeln.
BINARY SEARCH.
lv_tabix = sy-tabix.
* End the LOOP, when there is no more record with similar key
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
we have seen a technique how to speed up the performance of the nested LOOP constructs in ABAP. we
will see another variance of the Parallel cursor
technique. In this technique, we will exit out the inner LOOP when both keys are not matching by saving
the LOOP index in a variable. This index variable would be
used in the LOOP construct to start the LOOP. Initially, this index variable would be set to 1. Statistics
shows that this new technique is powerful over the
technique as shown in the previous post which uses the READ TABLE.
it_vbap BY vbeln.
ASSIGNING <lfs_vbap>.
* Save index & Exit the loop, if the keys are not same
lv_tabix = sy-tabix
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
----------------------------------------------------------------------
You can add the fixed value to any domain by registering the object. But registration and object
modification would need to be handled explicitly when system
would be upgraded or support pack is applied. To overcome this issue, you should consider Fixed Value
Append if you want to add the fixed values to the standard domain.
If you already have a value append, you would see the popup. Choose Create in that case.
4 Enter the name of the Fixed Value Append in the subsequent “small” popup .
5 . In the subsequent screen, you would see similar screen to this where all the value fields are open
for change. Enter the desired values and save .
6 If you want to see the Existing entries, you can press the button “Show Domain Values” and the
values would be displayed
7 When you activate the Fixed Value Append, the values would appear in the domain with
highlighted “blue” color with the fixed value Append column.
Enhancement Framework:
Enhancement is used when you need to enhance the any standard SAP delivered functionality by
introduced new code. There are certain ways to achieve the enhancements:
Core Modification – You obtain the access key by registering the object with SAP and
make the necessary changes. This is more dangerous and thus least preferable among
other techniques. What makes it more dangerous is when SAP provides any OSS note,
or while upgrade, there is a great chance of losing the functionality if you don’t perform
proper SPAU activities.
User Exits – You find SAP delivered Subroutines (PERFORM) which begins with
USEREXIT_ in the std SAP programs. Those Subroutines would be collected in a
program. To implement the user exit, you would need to also register the object once.
They are little bit safer from upgrade point of view as they are in a separate included.
Customer Exits – You find SAP provided function exits with CALL CUSTOMER FUNCTION
‘001’. This would be a FM with an include. This include would not be delivered by SAP.
If you need your new functionality, you need to create the include and implement your
code. You would need to create Customer Enhancement Project in CMOD using the
Enhancement which houses the Exit function SMOD.
BADI (Business Add Ins) – are the based on Object Oriented Concept. Similarly Std
SAP would provide you the BADI calls. You would need to create the BADI
implementation based on the BADI definition. Then you can add your code in the
implementation which is essentially a method in the class. You can implement the same
BADI multiple times, if the BADI is multiple implementations.
Enhancement Implementation:
In order to put your code in to any of the enhancement, you would need to create an implementation
for that. If you found an explicit point, you can create the implementation for that point. You
implement the logic in your implementation. At run time, system determines how many active
implementations exist in the system for that point and executes them.
Enhancement Framework – Explicit Enhancement-POINT Implementation :
Points are predefined hooks available in Std SAP code which you can implement. At runtime, based
on the Switch status of the Implementation, the implementations would be called.
Press the Spiral button on the toolbar to bring up the Enhancement mode. Once you are in
Enhancement, the Editor would be open for change with kind of maze on left.
2. Create an Enhancement
Put Cursor on the Enhancement Name and choose option Edit > Enhancement Operations >
Create Implementation.
The same option is also available in context menu (right click)
If all options in Enhancement Operations in Main Menu and in context Menu are not selectable, you
must not be in the Enhancement Mode.
3. Choose or use Implementation: - System would bring you a popup to choose existing
Enhancement implementation. If you implementing a new functionality, I suggest you create the new
Implementation by pressing the Create Icon. Many times, developers get confused as system brings
the std implementation names as well. They select them to implement their functionality and system
would ask for the Access key. So, they get frustrated and confused. Enter the details of the Enh Imp
name and description. In subsequent popup enter the Package and TR if you don’t select Local
objects.
Once Enh Imp is created, you are back to the popup to select the Enh Imp. Scroll down to find your
Enh Imp which you just created. Select and continue. If you are later version of ECC 6, your selected
Enh Imp would be automatically selected.
Remove Implementation
If the you wish to remove the implementation, you need to follow two step approaches.
1. Undo the implementation first. Choose Context Menu > Enhancement Implementation >
Undo Implementation.
2. Activate the Implementation. If you don’t activate, the object will not be detached from the
program.
3. Go to SE80. Choose Other objects > Enhancements. Choose option Enhancement
Implementation and enter the name. Choose Delete to remove it completely from system
Multiple Implementations
There could be multiple Implementations of the same enhancement point. Like one shown in this
example. If the implementation is attached to the Switch and if the switch is active, the system would
execute those implementations. Implementations without any switch are also active at the same
time.
If you are in the change mode of one of the implementation, Enhancement Framework will not allow
you to create another one right there. You need to go out of the change mode. I generally, go out of
the program and start the process again.
Debug the Implementation: - Once you have implemented the enhancement implementation, you
would be able to see it in action. To be able to debug it:
If you have implemented at the correct location, debugger will stop. If not, either you are running
wrong transaction or you had implemented the wrong enhancement option.
When debugger comes up, it would be at your 1st break-point. You would notice that your
implementation is not displayed in the program. Don’t get alarmed or confused. You notice a small
spiral at the beginning of the line. This Spiral shows that there is an active implementation at that
location. That implementation would be called by the program when control reaches to that point.
As you can see in this image, there is a second ENHANCEMENT-POINT which doesn’t have any
active implementation. Thus there is no Spiral button in front of that.
When you step over to your breakpoint, you would be now within your implementation.
Implementation Include
As you can notice, this implementation is in its own including. When you create the implementation
for enhancement options, system generates this include to house the code. At runtime, system
determines if there is any active implementation needs to be called or not. If there is, it would display
that Spiral icon and call the implementation from that generated include.
System generated include name as ZTEST_NP_MAT_DOC_LINE_CHANGE==E for the implementation
ZTEST_NP_MAT_DOC_LINE_CHANGE. The include name is 31 characters long. 30 chars are the
name of the Implementation and filler as = for name shorter than 30 char, and 31st char as E.
Enhancement Section has same properties as the Enhancement Point, with “default” code. The
SECTION is also a hook available in Std SAP Codes which can be implemented. Section can also
be INCLUDE BOUND and STATIC.
If you compare the SECTION with the POINT, the POINT doesn’t offer any default implementation
where as SECTION offers default logic between ENHANCEMENT-SECTION and END-ENHANCEMENT-
SECTION. This default logic is the logic, what system expects to execute. The existing default logic
may not make any more sense if the implementation would be created. Thus the designers would
have created SECTION instead of the POINT.
All the steps to create an implementation for the SECTION is same as Implementing a POINT:
1 . Get into the Enhancement Mode
2. Create a New Implementation Putting cursor on Enhancement SECTION and menu option Edit >
Enhancement Operations > Create Implementation.
4. Select you implementation once created.
4 Implement the Logic – Once the implementation is created, you can see that the default logic is
copied .
Once you have created the implementation and you wish to change – get into the Enhancement
mode. Use the Edit or Context menu to select the option Enhancement Operation > Change
Implementation. Activate the Implementation.
Remove Implementation:
If the you wish to remove the implementation, you need to follow two step approaches.
1. Undo the implementation first. Choose Context Menu > Enhancement Implementation >
Undo Implementation.
2. Activate the Implementation. If you don’t activate, the object will not be detached from the
program.
3. Go to SE80. Choose other objects > Enhancements. Choose option Enhancement
Implementation and enter the name. Choose Delete to remove it completely from system.
Implicit Enhancement points exist at various places in the ABAP programs. Unlike the Explicit
enhancements, these points are not defined in the programs.
Since implicit enhancement options are integrated and by default available make it very powerful
option when you want to enhance any functionality in ABAP Enhancement Framework. To
implement the explicit enhancement, it has to be provided in the program as a POINT or a
SECTION. Since Implicit is available at many places, makes it widely useable.
Let’s walk through one scenario – You have a subroutine to populate the specific field on the
document. This subroutine is providing you a XYZ value. That value is valid for most of the business
units. But for one specific unit, you want to have ABC instead of XYZ. To achieve this, you can
implement the Implicit Enhancement option available at the end of the subroutine, provided there is
no explicit point, or customer exit, or BADI.
To see this flexibility – compare it with the same scenario where you don’t have implicit options. You
register the object (remember, you don’t have any exits in the subroutine), implement the code;
make sure that code is there always after a support pack or OSS note or full system upgrade. With
the flexibility of implicit options, you don’t need to worry about upgrade. The implementation would
be there after any upgrade or support pack.
Available at
Implicit enhancement options are available at various places:
E.g. for a Subroutine F_GET_DATA, the implicit enhancements are available just after the FORM
F_GET_DATA (at beginning) and just before the ENDFORM (at end).
To display the implicit options, Select Menu options Edit > Enhancement Operations > Show Implicit
Enhancement Options.
Once you use the option “show the implementations”, system would show all the possible places
where you can implement the implicit enhancement.
Once you able to see the Enhancement Options, you can create the implementation for that.
To be able to create implementation, put cursor on the Enhancement Option (line showing with
“””””””) and select menu option Edit > Enhancement Operation > Create Implementation. If you don’t
see the implicit options, you need to use the Show implicit Options function.
Once you reach to this point, the process for creating implementation is similar to creating
implementation for the explicit enhancement point.
Declaration vs Code Popup:-
If you are implementing the enhancement point which is within the Subroutine or FM or Method,
system would bring you this popup.
Here is both of the options mean:
Declaration – When you choose this type, the implementation would be created and
treated as Static implementation. Means, it would be always available in all the clients.
Code– When you choose this option; the implementation would be Dynamic
implementation. It would be only called based on switch’s status if the switch is assigned.
In the newer version of SAP, I believe ECC 6 EP 6 onwards, there is this help available on the
popup. The help says:
An enhancement implementation for an implicit enhancement option can be bound into the source
code by the Enhancement Framework in two ways:
- As an unconditional call, for declarations and definitions: In such “static” enhancements, you can
add and replace data declarations, for example. Calling the
enhancements takes place independently of the client. The enhancement is visible in all clients of
the
system.
- As a conditional call, for source code: The enhancements implemented here are called
“dynamically” – that is, depending on the current
switches settings.
Notes:
- Definitions of subroutines, methods, and local classes cannot be implemented in “dynamic”
enhancement implementations, but only in “static” ones
- Data declarations should be implemented in “static” enhancement implementations.
- At runtime, “dynamic” calls do not ensure the same performance as “static” calls.
Enhancement framework offers unique way to enhance the class and interface. You can enhance
the method of the class using the implicit enhancement points. This is exactly same as the
enhancement points on the subroutines / Function Modules. The points are available at the
beginning of the method and end of the method.
Class enhancement has more power than implicit points. As part of the class enhancement, you can
create
Pre Exit – This implementation would be called before the original method call
Post Exit – This implementation would be called after the method call
Overwrite Exit – This implementation would replace the original method call with the
newly implemented method
Parameter enhancement – Additional parameters to the method signature
Additional Attributes – Additional Attributes
Additional Methods – Additional new methods within the class
Once you are in the enhancement mode, you will see the table control open for changes. You can
add the new methods, new attributes etc. in the Enhancement Mode.
You can’t create the exit methods for the methods inherited from the super class. But you can create
the exit methods for the redefined methods.
Enhance A Class:
4. Select menu Edit > Enhancement Operations > Insert Pre-Method. Here you will find functions
to create and remove each of the three exits.
5. Click on the editor icon to enter your code.
To add the new method parameter, head to the method signature. Here you would find that the table
control is open for changes. You can add the parameters. The parameters would be Optional as
they are new and would not be called from different places where method is called.
Adding New Attributes
Similarly, you can add the new attribute. The attribute could be as same as the any other attribute
Many times the enhancement in the source code is not quite enough. You may need to add
the new parameters in the FM signature, either Importing or exporting.
Enhancement to FM Signature allows you to add new parameter to the FM signature. You
can use this new parameter to make decision in your source code enhancements.
You might think – If you add the new parameter as importing parameter and what if callers
wont pass that parameter, which is true in most of the cases. As you are extending the
standard FMs and those FMs would be called somewhere in the system. Ignoring that
parameter would lead to runtime time errors in the std FM calls. To avoid this Enhancement
Framework, would create the new parameters as Optional. You can’t make them as
mandatory.
To be able to create the Enhancement to the FM signature,
1 Display FM in SE37
2 Go to the tab where you want to add the new parameter
3 Select Menu Function Module > Enhance Interface .
5 Create the new Parameter. When you create the new parameter, it is by default set to
Optional which is not changeable.
6 Finally you can use this new parameter in the source code enhancements.
Table Enhancement Category:-
To be able to enhance the table properly, you would need to understand Table
Enhancement Category for that table. Before we jump how we can enhance the table in the
Enhancement Framework, it is important that you get grip on the enhancement category.
so, lets deep dive into it.
Where to Find
Enhancement Category is available for all Table and structures. You can find the
Enhancement Category in Data Dictionary.
1. Enter Table or Structure name and Display
2. Menu Extras > Enhancement Category
Not Classified – This is the default option when any new table is created. This
means no specific guidelines was given by the designer to enhance the table or not.
Cannot be Enhanced – This tells you that the table designer decided that you must
not enhance this table. Thus when you try to enhance the table, system will prompt
you the message that it won’t be simply possible.
Can be Enhanced (Character-Type) – This options denote that the table can be
enhanced with Character Type fields only – i.e. Character, Numeric, Date and Time.
If you try to add the field Type P (packed) – a field for amount, system will not allow
the table activation during the table enhancement.
Can be Enhanced (Character-Type & Numeric) – This option points that the table
can be enhanced with the Character and Numeric type fields, but must not contain
the deep data types like Tables, References, Strings, XStrings etc.
Can be Enhanced (Deep) – If you have this option, you can enhance table with any
type of the fields.
When you create the table and don’t select appropriate option and leave the Not Classified,
system would display a warning while activating the table.
Tables or Structures can be enhanced as part of the Enhancement Framework using the
Append structure option available in Data Dictionary.
4 In the popup, you would see the existing Append structures
From the Popup, you can also delete the existing Append structure.
Search helps are integrated for easy access into almost all fields in standard SAP.
Enhancing the Search help would improve the user experience without actually changing
any of the existing objects. You can add the new search help to the existing search help by
changing the standard search help as well. If you do so, you would need to pay extra
attention at time of upgrade or support pack installation.
To eliminate this problem, you can extend the existing search help using the Append
Search help without changing – registering – the underlying standard object.
Follow these steps to create the Search Help:
1 Display the Search Help in SE11
2 Choose option Go To > Append Search Help .
3 In the Append Search Help popup, choose the create icon and enter the Search help
name.
4 Create a new search help. Head over to the Included Search help and create the new
search help. If you have existing, you can just mention it. For testing purpose, I have
created this search help ZTEST_NP_DEBI_C.
5 Link the included search help to the Appended search help. Once you create and activate
the included search help, you need to now link the search help to the appended search help
using the Parameter Assignment.
When you press yes, system proposes the assignment based on the fields used:
If you don’t perform the Parameter assignment, you would get this warning message.
Without the assignment, the search help will not able to transfer the data back and fourth
between the main search help to the included search help. In this test case, the link would
establish DEBI > ZTEST_NP_DEBI > ZTEST_NP_DEBI_C.
Extension Index :