Sunteți pe pagina 1din 32

CODEJAM: ABAP FOR SAP HANA

2 – STATIC CODE CHECKS AND SQL


MONITORING IN SAP NETWEAVER AS
ABAP

June 2015 – SAP SE


2

A. MOTIVATION

What makes SAP HANA so unique?

SAP HANA is an innovative in-memory data platform that is deployable on premise as an


appliance, in the cloud or as a hybrid solution. SAP HANA is the ideal platform for
performing advanced, real-time analytics while simultaneously handling real-time
transaction workloads. SAP HANA is unique in its ability to converge database and
application logic within the in-memory engine to transform transactions, analytics, text
analysis, predictive and spatial processing.

The endless variety of business scenarios make many different demands on the
performance and scalability of standard software in general. There are quality standards
that define criteria that guarantee good performance and scalability of components,
scenarios and processes.

What are the impact on custom code?

Custom code is a central part the business functionality. The question now is how customers
can smoothly migrate in the first step and optimize their code for SAP HANA in the second
step.

ABAP for SAP HANA


3

B. WHAT’S INSIDE THE DOCUMENT?

Which of my ABAP code must be changed to avoid potential


functional and performance issues and which of my business
processes have potential for optimization?

When you plan to migrate to SAP HANA, the amount of custom code in your system will
have an impact on total cost, time and the quality. Let’s look at the potential impact of
custom code, and discuss how to tune custom code to perform optimal on SAP HANA.
So questions are:

· Which of my ABAP code must be changed to avoid potential functional issues?


· Which of my ABAP code shall be optimized to ensure good performance?
· Which of my main business processes have potential for HANA so that I can speed up
those massively?
· And how can I find all this ABAP code easily and do the adaption efficiently?

In the following exercises you will familiarize yourself with how to:

· Prepare Custom Code for SAP HANA


· Use SQL Monitor to gain aggregated performance indicators
· Use Runtime Check Monitor to identify runtime issues leading to poor performance

ABAP for SAP HANA


4

C. PREPARE CUSTOM CODE FOR SAP HANA

ABAP Code Inspector & ABAP Test Cockpit

The migration of customer’s ABAP code to SAP HANA can be divided into two broad
categories:

· Functional adaptations of custom code


· SQL Performance optimization of custom code
For the first point, "Functional adaptations of customer codes" is in particular to detect
ABAP code that potentially relies on specific properties of the previous database and thus
analyzed and might be adjusted for example find native SQL in ABAP coding.
For the last point (of a prominent role in the analysis), there are two tests

· "Search problematic statement ... w / o ORDER BY"


· "Depooling / decluster-: Search for ... w / o ORDER BY"

There are tools available in the ABAP environment that can provide valuable help, in
particular to analyze code for functional correctness and performance.

· Extended Program Check (SLIN) to perform the extended program check


· ABAP Memory Inspector (S_MEMORY_INSPECTOR)
· SQL trace (ST05) to find out how open SQL statements are converted into native SQL
statements
· Check runtime behavior and performance by using the ABAP runtime analysis tool
(SAT) which is the ABAP Profiling tool in eclipse
· ABAP Code Inspector (SCI) tool for checking ABAP coding and DDIC objects, in
general all objects of the Object Repository, under the aspects of functional
correctness, performance, security, reliability
· And the ABAP Test Cockpit (ATC) that supports the execution and evaluation of the
most important tests which is integrated into the ABAP Workbench, into the
Transport Organizer and last but not least the ABAP Development Tools

ABAP Code Inspector

The ABAP Code Inspector can perform a whole range of static performance checks. The
existing rules and guidelines checked by Code Inspector are as valid for SAP HANA as they
are for other databases. With SAP NetWeaver 7.40, several additional checks were added
generally be divided into two main areas:

ABAP for SAP HANA


5

· Functional adaptations using Code Inspector check variant:


o FUNCTIONAL_DB
· SQL performance optimizations using Code Inspector check variant
o PERFORMANCE_DB

These check variant contains checks that are regarded as mandatory for the analysis of
ABAP custom code as part of an SAP HANA migration.

Detailed information can be found in SAP Note 1912445.

ABAP Test Cockpit

The ABAP Test Cockpit (ATC) was introduced as a holistic quality assurance tool. The ABAP
Test Cockpit integrates the ABAP Code Inspector (SCI), including the configuration of check
variants. The ATC offers more, in particular flexibly scheduling check runs, distribution of
results and in general support for quality management processes.
The checks performed by the ABAP Test Cockpit can be configured. Standard configuration
is that it reuses the ABAP Code Inspector DEFAULT variant. The check variant used may have
to be adjusted, e.g. FUNCTIONAL_DB and PERFORMANCE_DB to make sure all checks
relevant for SAP HANA are performed.

ABAP for SAP HANA


6

Exercise 1 - Use ABAP Test Cockpit to find code that must be


changed

Explanation Screenshot

1) Add the Favorite Package


TEST_A4H_TRAINING_SQLM
which will be used for the Code
Inspector checks
a) Right-click Favorite Package
choose Add a Package

b) Insert
TEST_A4H_TRAINING_SQ
LM and press OK

2) Execute Code Inspector variant


FUNCTIONAL_DB

a) Change the Code Inspector


variant by Right-click the
ABAP Project and select
Properties

ABAP for SAP HANA


7

Explanation Screenshot

b) Under ABAP
Development select ABAP
Test Cockpit, choose
Global Code
Inspector check
variant,
insert the global check variant
FUNCTIONAL_DB and press
OK

c) Right-click the package


TEST_A4H_TRAINING_SQLM,
choose Run As – ABAP Test
Cockpit (Ctrl+Shift+F2) to
execute the ATC

3) Execute Code Inspector variant


PERFORMANCE_DB

a) Change the Code Inspector


variant by Right-click the
ABAP Project and select
Properties

ABAP for SAP HANA


8

Explanation Screenshot

b) Under ABAP
Development select ABAP
Test Cockpit, choose
Global Code
Inspector check
variant,
insert the global check variant
PERFORMANCE_DB and
press OK

c) Execute the ATC-Run again

4) Analyze the ATC results

a) After the execution of the


ATC run the ATC Problems
view should be opened.

b) The best is to group the result


within the ATC Problems view
by Check by pressing the
little triangle, choose Group
By Check

ABAP for SAP HANA


9

Explanation Screenshot

c) You can switch the results by


selecting between the Code
Inspector variants
FUNCTIONAL_DB and
PERFORMANCE_DB to see
the Problematic Statements

d) Choose PERFORMANCE_DB to
see the Problematic
Statements found for this
Code Inspector variant

5) Get detailed information and


navigate to a source of a
problematic statement
a) Select for example the
Unsecure use of FOR
ALL ENTRIES –
Possible use of … to
see detailed information
about the check.

b) Double-click the occurrence


of the Unsecure use of
FOR ALL ENTRIES to

ABAP for SAP HANA


10

Explanation Screenshot
navigate to the source code
of this problematic statement

Please feel free to check any


other statements

6) Analyze the statement for


possible improvements based on
the information given in the
detailed pane of the ATC Problems
view

7) Possible solution
a) In order to make more stable
and more readable it is best
practice to embrace SELECT
… FOR ALL ENTRIES with
an explicit test for content by
using an IF statement

Summary

· ABAP Test Cockpit (ATC) is the new standard tool for static ABAP code checks
· In general existing ABAP code runs on SAP HANA as before. Only DB specific ABAP
code must be analyzed
· New static Code Inspector Checks and Runtime Checks are available which help to
find the code which must be analyzed
· ATC can be used now to prepare the custom ABAP code for HANA and to improve
the general quality of the code

ABAP for SAP HANA


11

· ATC availability starts with NW 702 SP12 / NW 731 SP5.


In older releases the Code Inspector can be used

In addition, please keep in mind, that there are five "Golden SQL Rules", which helps to
improve the performance of your ABAP programs. Two of them have higher priority, if you
are working with SAP HANA:

· Minimize the amount of transferred data


· Minimize the number of data transfers

ABAP for SAP HANA


12

D. USE SQL MONITOR TO ANALYZE SQL PERFORMANCE

SQL Monitor

Static performance checks mainly provide performance hints and recommendations. Static
checks cannot predict the performance benefit of a recommended correction. Therefore,
static checks are not sufficient as a single source for performance optimizations.
We need to add runtime data from the productive system to find the relevant code. In a
productive ABAP-based SAP system a huge number of various SQL requests are executed by
the most diverse business processes. To detect the performance hotspots and also identify
potential for optimization in the SQL profile, you require specialized SQL Monitoring Tools
and utilities running in a live ABAP system.

Covered by Static Checks Covered by SQL Monitor

* Not covered: Code generated at runtime, * Find the performance hotspots with the
dynamic code, too complex code SQL Monitor

The SQL Monitor allows you to monitor all SQL statements and operations that are
executed by running ABAP applications. The collected SQL Monitor data provides you with
aggregated performance indicators (number of executions, execution time, number of
effected rows, and so on) for all executed database operations.

ABAP for SAP HANA


13

In contrast to the standard Performance Trace tool (transaction ST05), the SQL Monitor
enables you to monitor the SQL activity system wide and over longer period of time. In
addition, you can expand the scope of the analysis to finding system-wide hotspots. The
reference to the ABAP context is always retained, except for mere DB monitoring. For each
SQL trace record, the entry point of the respective request (transaction code, submitted
report, RFC function module, and so on) and the affected ABAP source code position is
stored as well. This provides the first connection from the SQL statement to the affected
business process.

You can use the collected SQL performance data to answer questions such as these:

· Which database operation (SELECT, INSERT, UPDATE, DELETE) in the customer code
is executed most frequently in your system?
· Which database operation statements cause the longest runtime?
· Which database operation in the customer code reads the most data?
· What does the SQL profile of a report X or transaction Y look like?

ABAP for SAP HANA


14

Exercise 2 - Use SQL Monitor to gain aggregated performance


indicators

In this exercise you learn how to find performance issues grouped into different categories:

· Top Business Processes


o Which are the Top Business Processes taking most database time?

· Large time consumption


o Which statements, reports, transactions or batch jobs are the top candidates
and responsible for the large time consumption?
§ View results filtered By Request Entry Point while using Aggregation
"By Request" and ordered by Total DB Execution Time.
o How could the code be improved?

· Many executions
o Which SQL-statement is executed most often?
§ View results are aggregated over all Request Entry Points while using
Aggregation " By Source Code Position " and ordered by Total
Number of DB Execution
o How could the code be improved?

· Huge data transfer


o Find the statements that fetch and/or modify the largest number of database
records?
o How could the code be improved?

· Slow statement
o Find the SQLM record of a SELECT statement with largest value of DB
Maximum Execution Time (hint: since ordering results by DB Maximum
execution time cannot be preselected on the selection screen, leave Maximal
Number of Records empty to make sure the record is not excluded).
o How can this large value be explained?

ABAP for SAP HANA


15

Start SQLM – Display Data

Explanation Screenshot

1. Start transaction SQLM (SQL


Monitor)
a) Use shortcut Alt-F8,
insert SQLM and press
Enter

2. Select Snapshot
a) Select Display
Snapshots

b) Choose Display
Snapshot

ABAP for SAP HANA


16

Explanation Screenshot

c) Choose Snapshot SQLM


Snapshot [A4H
Fundamentals]
[SP08] from the list and
Press Enter

d) If you curios please feel


free to press F8 to get a
first overview of all data
available in the snapshot.

Please navigate back


afterwards!

Now let’s concentrate on the different categories!

ABAP for SAP HANA


17

Top Business Processes

Explanation Screenshot

Which are the Top Business Processes taking the most time on the database system?

1. Go back to the SQL


Monitor: Data Display
selection screen

2. Find the Top Business


Processes
a) To find the Top Business
Processes in the system
which are responsible for
the largest time
consumption keep the
Objects, Requests
and Tables area
empty.

b) Select "By Request" in


the Aggregation area

c) Press Execute to display


the collected runtime
information aggregated by
request and sorted by
total execution time.

ABAP for SAP HANA


18

Explanation Screenshot
3. Result: Top Business Processes
· ZR_A4H_BUSINESS_CA
SE_B (Batch Job)
· ZA4H_BC2
(Transaction)
· ZR_A4H_BUSINESS_CA
SE_A (ABAP-Program)

ABAP for SAP HANA


19

Large Time Consumption

Explanation Screenshot

Which statements, reports, transactions or batch jobs are the top candidates and responsible for the
large time consumption?

Due to convenience restrict the data analysis to the test package!

1. Go back to the SQL


Monitor: Data Display
selection screen and Choose
Aggregation By Request
and Total DB
Executions Time in the
Order By area and press
Execute

2. Navigate into the details by


clicking the DB Statement for
ZR_A4H_Business_CASE_B

3. The top record consumes most


of the time.

ABAP for SAP HANA


20

Explanation Screenshot
4. Navigate to the source code

5. How could the code be


improved?

6. Solution

Select–Statement can be
transformed using a field list

ABAP for SAP HANA


21

Many executions

Explanation Screenshot

Which SQL statement is executed most often?

1. Go back to the SQL


Monitor: Data Display
selection screen

a) Change the Aggregation


area to By Source
Code Position and
the Order By area to
Total Number of DB
Executions

b) Press Execute to display


the data

2. Display Results
a) First entry is showing the
highest number of
statements executed

3. Navigate to the source code

ABAP for SAP HANA


22

Explanation Screenshot

4. How could the code be


improved?

Method
get_open_amount_4_inv
c is being called by another
method get_open_amount
in a LOOP

5. Solution
Simply use an inner join to get
rid of the nested function calls
within the SELECT …
ENDSELET statement.

Please refer to class


zcl_a4h_sqlm_1_open_a
mnt_opt for a possible
solution.

ABAP for SAP HANA


23

Huge Data Transfer

Explanation Screenshot

Find the statements that fetch and/or modify the largest number of database
records?

1. Go back to the SQL


Monitor: Data Display
selection screen and Choose
Aggregation By Source
Code Position and
Total DB Records in the
Order By area and press
Execute

2. Display Result

3. Navigate to the source code.

4. How could the code be


improved?

ABAP for SAP HANA


24

Explanation Screenshot

5. Solution:

Add a group by clause to the


select statement to di the
aggregation in the database.


Slow Statement

Explanation Screenshot

Find SELECT statement with largest value of DB Maximum Execution Time

1. Go back to the SQL
Monitor: Data Display
selection screen and Choose
Aggregation By Source
Code Position and
Total DB Execution
Time in the Order By area
and press Execute

2. Display Result and navigate to


the details of
ZR_A4H_BUSINESS_CASE_
A

ABAP for SAP HANA


25

Explanation Screenshot

3. Scroll to the right, select


column DB Max T and sort the
data in descending order

4. Navigate to the source code

5. How can this large value be


explained?

The explanation here is that two concurrent reports where updating the same table!

ABAP for SAP HANA


26

Summary

· SQL Monitor collects performance data for each and every SQL executed in an ABAP
application
· SQL Monitor can run in a productive system without disturbing business processes
(performance overhead <3%)
· SQL Monitor allows to link the monitored SQL to the driving business process
· SQL Monitor can be used in the “old” productive system before doing the HANA
migration
· SQL Monitor availability is starting with NW 700 (see appendix for details)

ABAP for SAP HANA


27

E. USE OF THE RUNTIME CHECK MONITOR

Runtime Check Monitor

The Runtime Check Monitor allows you to execute a limited range of runtime checks. In
each specific check, you can collect runtime-relevant information during program execution.
You can use these specific runtime checks to perform a final, remaining cleanup of the ABAP
code – for example, following the corresponding static code checks.
The Runtime Check Monitor provides the following runtime checks:

· Empty table in FOR_ALL_ENTRIES clause


o This check records all events where the internal table itab in the clause ...FOR
ALL ENTRIES IN itab... within the SELECT statement is empty.
o You can use this check to identify issues leading to poor performance or high
memory consumption.
· Missing ORDER BY or SORT after SELECT
o This check records every SELECT in an unsorted internal table without the
clause ORDER BY or subsequent SORT and followed - either immediately or
later on - by a statement that assumes the internal table to be sorted.
o You can use this check to identify ABAP source code that occasionally may
not work as expected because it is based on assumptions that might not
apply at runtime.

ABAP for SAP HANA


28

Exercise 3 - Use Runtime Check Monitor to identify runtime issues


leading to poor performance

Explanation Screenshot

1. Start transaction
SRTCM (Runtime
Check Monitor)by
using shortcut Alt-
F8, insert SRTCM and
press Enter

Comment: Transaction SRTCM


targets administrative tasks
and transaction SRTCMD is
used for runtime data analysis
only

2. The Runtime Check


Monitor provides the
following runtime
checks:

· Empty table in
FOR_ALL_ENTRIES
clause

· Missing ORDER BY
or SORT after
SELECT

You can activate or


deactivate the runtime
checks.

To display already
collected data either
directly use transaction
SRTCMD or press
Display Results

ABAP for SAP HANA


29

Explanation Screenshot

3. On the Runtime Check


Monitor Selection
Screen:
· Choose Snapshot
· Click Select
· Select SRTCM
Snapshot [A4H
Fundamentals]
· Press Enter

4. Select runtime check


Empty table in
FOR ALL ENTRIES
clause and press F8

5. You will see at least one


line indicating that for
one source code
position an Empty
FOR ALL ENTRIES
table was executed
against the database.

The consequence of an
empty for all entries
table is a full table scan
on the database!
6. Navigate to the ABAP
Source Code
Fragment by simply
clicking on the include
name

ABAP for SAP HANA


30

Explanation Screenshot

7. How could the code be


improved?

8. Solution:

Simply check if the


driver table is empty.

9. Navigate back to
Runtime Check
Monitor.

Select the Missing


ORDER BY or SORT
after SELECT in the
Runtime Check
Selection area.

10. You will see at least one


line indicating that for
one source code
position a READ
BINARY SEARCH was
executed where the
previous select
statement did not used
an ORDER BY or SORT
clause.

ABAP for SAP HANA


31

Explanation Screenshot
11. Navigate to the ABAP
Source Code
Fragment by simply
clicking on the include
name

12. How could the code be


improved?

13. Solution:

Simply use an ORDER


BY clause.

ABAP for SAP HANA


32

F. KEY TAKEAWAYS

· In general existing ABAP code runs on SAP HANA as before. Only DB specific ABAP
code must be analyzed
· ABAP Test Cockpit can be used to find and adapt DB specific ABAP custom code
easily
· In general the well known golden Open SQL rules are still valid on SAP HANA - only
some priorities have shifted
· For effective SQL tuning and to find HANA potential in existing ABAP code new
monitoring tools like the SQL Monitor are available
· The preparation of your custom code can start before the migration to SAP HANA

ABAP for SAP HANA

S-ar putea să vă placă și