Skip to Content

Part 1: Introduction

This document describes relevant steps to maximize the effect of ABAP performance tuning of custom coding for an SAP System running on HANA DB.

We will focus on tools and guidelines delivered by SAP.

We will start with a procedure how to find candidates (reports, transactions) that show a significant potential for performance improvements optimizing ABAP coding.

In each section of this document we will discuss different aspects of the optimization starting with the identification of potential candidates and ending with tips and tricks from real live projects.

The sections are

  • The golden rules – Five performance guidelines for ABAP database operations
  • How to find candidates – Use ST03N
  • The toolbox – Code Inspector and ABAP Trace
  • Optimizing ABAP code – Use FOR ALL ENTRIES and JOINs
  • Tips and tricks – Some hints based on our experience
  • Code pushdown – Stored procedures and HANA Artifacts

Each of the section can be read individually, but to get most out of this document it is recommended to read them in sequence.

————————————————————————————————————————————————————-

Outlook

In the following section we will discuss the classical programming paradigms and their meaning for programming on SAP HANA.

————————————————————————————————————————————————————-

Part 2: The Golden Rules

There are five performance guidelines for ABAP database operations. Despite all changes in the Database technology that come with SAP HANA, these classic programming paradigms remain valid.

   

With this in mind, we will put one Key message on top of this chapter

  • All classical performance recommendations are still valid
    as general guidelines
  • On SAP HANA some of the recommendations have a higher
    performance and some of the classical design pattern are of least importance

Let us have a look at the rules and their meaning as a rule of thumb

Capture1.PNG

What does this mean for our ABAP code? We will know look at each rule what what they mean in the context of SAP HANA

Rule 1 : Keep the result set small

Capture.PNG

Rule 2 : Minimize amount of transferred data

Capture.PNG

Rule 3 : Avoide many small request and selecting not needed columns

Capture.PNG

Rule 4 : Define and use appropriate secondary indexes

Capture.PNG

Rule 5 : Keep unnecessary load away from the database

Capture.PNG

————————————————————————————————————————————————————-

Outlook

In the next section will will use Transaction ST03N (Workload Analysis) to analyse the workload on our system and to identify reports and transactions, that can benefit from code canges and gain performance from SAP HANA.

————————————————————————————————————————————————————-

Part 3: How to find reports, programs and transactions optimization

There are several ways to identify reports and transactions that will benefit from code rework.

   

  • Look at reports and transactions that are named by users
  • Review the EWA report
  • Follow the procedure described below

We will now describe how to use Transaction ST03N to identify reports and transactions that will potentially benefit from SAP HANA.

3.1    ST03N – Workload Analysis

With our approach we will gain most from SAP HANA if we focus on ABAP programs with high DB load. The tool of choice is transaction ST03N (Workload Analysis).

How to proceed? In the following we will show brief step-by-step procedure

Step 1:

Call transaction ST03N


Switch to Expert mode first.

In the Workload tree choose Total
Servers and select the last full month.

In the Analysis Views choose the Transaction Profile folder and choose Standard

Capture.PNG

Step 2:

Go to tab “All Data” and download the list to Excel.

You can now manipulate the data, e.g. apply filter and hide or delete not columns you are not interested in.

If you remove columns from the list, it is recommended to keep the following ones:

Capture.PNG

Step 3:

Now we can check where the runtime comes from.

Create two new colums in your Excel to calculate percentage of DB time and
percentage of change time. Use this formula

Capture.PNG

To reduce the number of lines in the result add a filter on Trans/Rep. and apply a textfilter with the restriction to all names in customer namespace. This will
limit your selection to all transaction and reports that can be changed by a programmer without the need to modify SAP standard code.

 

SAP will take care of its own code and provide changes with patches and notes. Certain scenarios will benefit from SAP Standard Accelerators on HANA (Side Car, e.g. CO/PA Accelerator).

 

Sort the list by

 

    1. Percentage DB time (ascending) and
    2. Percentage Change time (ascending).

 

Reports will benefit from HANA if DB time is mainly caused by

 

  • sequential reads ( -> column Total Seq. Read time (s) or T Seq.Read Time ) and the
  • time for changes is rather low ( -> column Total Time for Logical DB Changes (s) or T Changes ).

   

To identify these reports restrict the result list to reports/transactions with

 

  • DB time high ( >70% ) and
  • change time low ( <= 1% )

   

You can do this if you apply a filter on both columns using the values given above.

Finally, the result table should look like this

Capture.PNG

In our example above we have marked these lines that fulfil our requirement on DB time and Change time in yellow.

 

Now you have created a list of candidates for code optimization. In the next sessions we will have a more detailed look on ABAP programs using SAP tools to identify areas with potential, the possible code changes and the result of these changes.

————————————————————————————————————————————————————-

Coming next

In the next section we will have a look at some tools from SAP that will help us with the analysis of our ABAP code. With this information we can later do changes and also analyze pros and cons of our approach.

————————————————————————————————————————————————————-

Part 4: Analyze and optimize ABAP Code – static code analysis

4.1 SAP Code Inspector

SAP code Inspector is a tool designed to perform static code checks. For shure it will not find everything, but you will see it is a fine tool to find and eleminate common mistakes, that are hidden in your code. It is especially useful if you start working on code that was designed and written years ago and there is a need to find areas for improvement without spending time for a detailed analysis.

How does it work? We will guide you through the tool without going to all facts and features and will concentrate us on the checks that will help us on our journey towards performant ABAP code running on SAP HANA.

Now start SAP Code Inspector and create a new inspection.

Enter transaction code SCI (or /nSCI) and this will lead you to the initial screen

Capture.PNG

We will run a new Inspection, so enter a name and proceed.

Capture.PNG

Now choose the object you are interested in. We will analyze a single program, so enter the mandatory data.

You can also check multiple objects, even the contens of a transport request.

Now grab either a pre-defined variant or choose from the list below.

In the first step we will use the four test delivered with 7.40 to identify problematic SELECT statements.

Capture.PNG

Let’s have a brief look at the test we have flagged

Search problematic SELECT* statement

–> This test will find statements selecting all fields. This can be replaced with a field list

Search SELECT . . . FOR ALL ENTRIES-clauses to be transformed

–> Go further and find out, if this can be replaced using a (LEFT OUTER) JOIN

Search SELECT statement with DELETE statement

–> Try to avoid deleting single lines (within a loo), transfor this to an array operation

Search SELECTs in loops across modularization units

–> This will help you to find nested SELECTs hidden in modularization unigs, e.g. in FORMs or ROUTINEs

Now run the inspection and take a look at the result list. In our example, SAP Code Inspector has returned two areas of concern:

Capture.PNG

Select a line and double click on it to see the detailsCapture.PNG

Again choose one of the messages to see the details

Capture.PNG

In our case the system detects a SELECT * statement, and from the analysis less than 10% of all fields retreived are used. As this analysis is done by an algorithm, it is always wise to review the analysis and decide based on a code analysis, wich field should be in the field list.

Let’s go on, and jump to the affected lines of code. You can do this directly from the result

Capture.PNG

After this is reviewd and – if possible – fixed return to the result of the analysis and go to the second finding. Here we are informed of a nested SELECT.

Capture.PNG

Let us have a look at the new checks added to SAP Code Inspector with focus on efficient ABAP programming on SAP HANA.

In two sections SAP has added new checks

1. Section Performance Checks has four new checks

    1. Search problematic SELECT * statements
    2. Search SELECT .. FOR ALL ENTRIES-clauses to be transformed
    3. Search SELECT statement with DELETE statement
    4. Search SELECTs in loops across modularization units

   

2. Section Robust Programming has two new checks

    1. Search problematic SELECT * statements
    2. Search problematic statements for unsorted results of SELECT or OPEN CURSOR statements

What does this mean in detail, and what does the check for me? The inline documentation gives us more information: 

………………………………………………………………………………………………………………………………………….

Performance Check 1.1: Search problematic SELECT * statements

Search for

SELECT * FROM dbtab statements which should be transformed into SELECT comp1 comp2 … FROM dbtab.

This check searches for SELECT * FROM dbtab statements where less than a specified percentage of the fields are effectively used. The default value for the percentage is 20 percent. If less than 20 percent of the fields are used it is more adequate to select only the used fields.

If single subroutines are specified by the check set, only the coding in these routines is checked.

Check parameters:

    • Minimum table size category: with this parameter you can restrict the search on SELECT-statements that access database tables with a size category that is equal or larger than the parameter. The size category is maintained in the technical settings of a database table in the ABAP dictionary (SE11).
    • Minimum number of table fields: with this parameter you can restrict the search on SELECT-statements that access database tables with equal or more columns than the parameter.
    • Only search for these tables: here it is possible to restrict the search to accesses to the selected tables.
    • Percentage of fields: Percentage of used table fields to be considered as “few”
    • Evaluation level: The evaluation process start at the top level procedures of a compilation unit and follows the calls to other procedures. With this parameter you can specify the maximal evaluation depth.
    • Exclude buffered tables: Normally accesses to buffered tables are analyzed as well. With this parameter you can exclude it.
    • Not to be transformed selects: Display also information about SELECT-statements which should not be transformed.

Display detail information: If you switch on this parameter you get very detailed information about the access to the result of the select-* statements and the evaluation process. 

EFFORT-Parameters

    • EFFORT for one assignment
    • EFFORT for one column access

   

The check delivers the following result messages:   

    • FEW SELECT-Statement can be transformed, because less than the specified percentage of fields is used.
    • MANY SELECT-Statement should not be transformed, because more than the specified percentage of fields is used.
    • EXISTS SELECT-Statement can be transformed very easily, because it is used just for an existence check. The work area or any of its components are not used.
    • UNCLEAR The situation for the select statement is unclear because of one of two reasons:
      • The result of the SELECT-statement cannot be analyzed further on
      • The evaluation was aborted because the evaluation level has been exceeded.

   

If you have switched on to get detail information, there are the additional messages:   

    • SELECT A SELECT-* statement has been found,
    • COMP A component of the result of a SELECT-* statement is used.
    • ALL The complete result of a SELECT-* statement is used by the current statement.
    • NOEVAL The current state uses the result SELECT-* and has not been evaluated
    • LEVEL The evaluation has been aborted at the specified procedure.

   

The checks delivers the following test result parameters   

    • SEVERITY The severity is the number of columns of the data base table which are read but not used
    • EFFORT The effort is computed via the following formula:

Capture.PNG

…………………………………………………………………………………………………………………………………………………………………………….

Performance Check 1.2: Search SELECT .. FOR ALL ENTRIES-clauses to be transformed

Search for

SELECT … FOR ALL ENTRIES statements which can be joined with other SELECT statements

This check searches for SELECT … FOR ALL ENTRIES where the input for the for all entries table is the result of another SELECT statement. In this case the two statements can be joined into one statement with an improved performance.

The two SELECT statements can be in different subroutines.

If single subroutines are specified by the check set, only the coding in these routines is analyzed.

Buffered tables, except those with single record buffering, are excluded from the analysis. In this case two SELECT-statements are more adequate

General parameters:

    • Minimum table size category: with this parameter you can restrict the search on SELECT-statements that access database tables with a size category that is equal or larger than the parameter. The size category is maintained in the technical settings of a database table in the ABAP dictionary (SE11).
    • Only search for these tables: here it is possible to restrict the search to accesses to the selected tables.

Effort parameters:

    • Effort for one assignment: with this parameter you can determine the effort for an assignment of the internal table that was filled by the select statement to another table.
    • Effort for each call: with this parameter you can determine the effort of a call between the select and the select for all entries.

The check delivers the following result messages:

    • TRANSFORM The SELECT-FOR-ALL statement can be joined with another SELECT-statement. The position of the second statement is mentioned in the message text.
    • LEVEL The evaluation has been aborted at the current procedure, because the maximum evaluation level has been reached

If you have switched on to get detail information, there are the additional messages:

    • NoMoves Number of moves of the internal table
    • Effort The effort to correct this problem. It is calculated as follows:
    • Effort = Effort for each call * number of calls + Effort for one assignment * NoMoves + 10.
    • Severity The severity of this problem is a measure for the performance loss due to this problem.
    • It is always 1.

………………………………………………………………………………………………………………………………………….

Performance Check 1.3: Search SELECT statement with DELETE statement

Search for

SELECT .. INTO TABLE tab statements which are followed by a DELETE statement for the result table tab .

The checks delivers the following test result parameters

    • SEVERITY The severity is always 1
    • EFFORT The effort is the distance in lines between the
      SELECT and the DELETE statement

…………………………………………………………………………………………………………………………………………………………………………………………………………..

Performance Check 1.4: Search for SELECTs in loops across modularization units

Find database operations in nested loops across modularization units

This check searches for database operations that are nested inside any kind of loop (e.g. LOOP-loop, DO-loop, …). If in the loop there is a call to a modularization unit (PERFORM, CALL FUNCTION, CALL METHOD), then this call is tracked and it will be analyzed, whether there is a database operation in the called unit. This way, several levels of the call-stack are analyzed (for runtime reasons, there is an upper limit for the call-stack depth).

What you can do:
If a database operation is executed inside a loop for several entries of the internal table that is processed, please check whether it is possible to read or write the needed database lines with one database statement instead. For example, it could be possible to replace the
SELECT inside the LOOP with a SELECT … FROM dbtab FOR ALL ENTRIES IN itab.

General Parameters:

    • Minimum table size category: with this parameter you can restrict the search on those database operations that access database tables with a size category that is equal or larger than the parameter. The size category is maintained in the technical settings of a database table in the ABAP dictionary (SE11).
    • Call-stack depth for analysis: this value determines how many levels of the call-stack will be analyzed below the loop statement. The default value is 3, the maximum value is 10.
    • Exclude buffered tables: here it is possible to exclude accesses to buffered tables
    • Analyze only local procedures: here it is possible to restrict the evaluation to local procedures, which saves evaluation time
    • Analyze reading db operations: analyze reading database operations inside a loop, i.e. SELECT, OPEN CURSOR, FETCH, CLOSE, and the obsolete ones READ TABLE dbtab and LOOP AT dbtab.
    • Analyze writing db operations: analyze writing database operations inside a loop, i.e. DELETE, INSERT, UPDATE, and MODIFY
    • Analyze EXEC SQL statements: analyze exec sql statements inside a loop

Effort Parameters (determine the effort to correct a problematic statement)

    • Effort for db op in loop: with this parameter you determine the effort to remove a loop surrounding a database statement. The default value is 10.
    • Effort for each call: with this parameter you determine the effort to remove a loop surrounding a procedure call that contains a database statement. The default value is 20.

  The check delivers the following result messages:  

    • DBREAD_LOC A reading database operation was found inside a local loop.
    • DBREAD A reading database operation was found inside a non local loop
    • DBWRT_LOC A writing database operation was found inside a local loop.
    • DBWRITE A writing database operation was found inside a non local loop
    • EXEC_LOC An exec sql operation was found inside a local loop.
    • EXEC An exec sql operation was found inside a non local loop

  If you have switched on to get detail information, there are the additional messages:  

    • Table Name Name of the database table concerned
    • Nr Loops Number of loops around the database operation
    • Nr Calls Number of procedure calls around the database operation
    • Effort The effort to correct this problem. It is calculated as follows:
    • Effort = Effort for db op in loop +  Effort for each call * number of calls
    • Severity The severity of this problem is a measure for the performance loss due to this problem.
    • It is calculated: Severity = number of loops

…………………………………………………………………………………………………………………………………………..

Robust Programming 2.1: Deepooling/Declustering: Search SELECT for Pool/Cluster-Tables w/o ORDER BY

Search for SELECT and OPEN CURSOR statements for pool or cluster  tables where no ORDER BY clause is specified.

This situation is problematic because the order of the returned database entries changes if the data base table is modified into a transparent table.

Remark: SELECT SINGLE statement are not analyzed since they are not problematic.

Remark: If the result of the SELECT statement is moved into a sorted internal table, a special message is raised

Messages of the test can be suppressed via the pseudo comment “#EC CI_NOORDER

………………………………………………………………………………………………………………………………………….

Robust Programming 2.2: Search problematic statements for unsorted results of SELECT or OPEN CURSOR statements

This check searches for the following statements where the internal table is the result of a SELECT statement without ORDER BY clause. Without ORDER BY clause or other sorting measures the result of the select statement may be unsorted. So the statements may not work properly.

Check parameters:

    • Only local calls: With this parameter you can specify if external procedure call should be analyzed, too.
    • Local analysis depth: The evaluation process start at the top level procedures of a compilation unit and follows the calls to other procedures. With this parameter you can specify the maximal evaluation depth.
    • Non-local analysis depth: With this parameter you can specify the maximal evaluation depth into external programs.

The problematic statements are:

Capture.PNG

What you can do:

There are two (three) possibilities:

    1. Add an ORDER BY clause to the select statement
    2. Add a SORT statement for the internal table
    3. If no problem exists add the specified pseudo comment

Remark: The SELECT statement and the critical statement can be in different subroutines.

………………………………………………………………………………………………………………………………………….

If you want to learn more about SAP Code Inspector follow these links

http://wiki.sdn.sap.com/wiki/display/ABAP/Code+Inspector

http://www.sap.com/australia/campaign/es-newsletter-q4/code_inspector.epx

————————————————————————————————————————————————————-

Coming next

In the next section we will continue with will have a look at Transaction /nT05 (SQL Trace) and how SQL Trace will help us on our journey to performant ABAP on HANA programming.

————————————————————————————————————————————————————-

Part 5: DB Performance Analysis with SQL Trace

If you experience slow transaction step is mainly caused by one or more long running SQL statements. To get to the root cause of this problem, do an SQL trace of the process step.

For this start ST05 Aattention: The trace is only performed for the instance you are currently logged on, so check Transaction SM51/SM51 before you start). Call Transaction /nST05 and activate the SQL trace via the ‘Activate Trace with Filter’. In case you have to trace another user and not your own, add this information to this popup.

Remark: You should always use filter criteria, to (a) keep the number of collected data low and (b) avoid unneccessary load on the system. And always Deactivate Trace after you have finished collecting the required data.

Capture.PNG

If the configuration is done, execute the long running statement.

As soon as you have performed the trace, switch of the tracing (Deactivate Trace) and go to Display Trace. Choose your trace file and display the summarized list.

Capture.PNG

Sort the lis by e.g. Time to see the time consuming statements.

Capture.PNG

Select the one you want to get more information and click on the SELECT statement to see the details of the WHERE clause.

Capture.PNG

Click on the ‘Explain’ button to see the execution plan of the statement as it is executed by the DB. You can see, if and which index/indices have been used

In our example no index was choosen and a full table scan was done.

No take appropriate actions and find out, what can be done to optimize this statement.

————————————————————————————————————————————————————-

Coming next

In the next section we will continue with will have a look at Transaction /nSAT (ABAP Trace) and how ABAP Trace will help us on our journey to performant ABAP on HANA programming.

————————————————————————————————————————————————————-

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

  1. Markus Zoeller

    Hi All,

    is there a good recommendation or approach that describes the analysis to identify potentialy unnecessary “SecondaryIndices” when moving from classic DB (e.g. ORACLE) to HANA DB.

    Thanks and Regards

    Markus 

    (0) 
    1. Lars Breddemann

      The question is not so much whether there are potentially unnecessary sec. indexes, but rather: of all the sec. indexes in the system, which ones could potentially be useful?

      Since the indexing options, strategies and reasons for Oracle are fundamentally different than for SAP HANA, the recommendation is: get rid of all secondary indexes (especially those one more than one column) and review the performance of your application on SAP HANA.

      You might want to check SAP notes

      2160391 FAQ: SAP HANA Indexes
      2000002 FAQ: SAP HANA SQL Optimization

      for further reading on this.

      (0) 
  2. Denis Tislenko

    Thanks for the information, it helped a lot.

    I would just add, that not only pool and cluster tables are affected, but also transparent tables. And for transparent tables, not in all cases the Code Inspector finds this.

    (0) 

Leave a Reply