Sie sind auf Seite 1von 50

TUNE YOUR CUSTOM ABAP CODE

GET READY FOR SAP HANA!


CD262

Stefan Bresch, Boris Gebhardt, Jens Lieberum and Johannes


Marbach / SAP

TABLE OF CONTENTS
ABAP Test Cockpit .................................................................................................................................... 4
ATC Online Check ................................................................................................................................... 5
Handling Findings I: READ .. BINARY SEARCH .................................................................................... 10
Handling Findings II: DELETE ADJACENT DUPLICATES ..................................................................... 15
Handling Findings III: Empty FOR ALL ENTRIES Tables ....................................................................... 18
SQL Monitor SQLM ................................................................................................................................... 22
Slow Request........................................................................................................................................... 23
Many Executions ..................................................................................................................................... 28
Huge Data Transfer ................................................................................................................................. 31
Slow Statement........................................................................................................................................ 35
SQL Performance Tuning Worklist ............................................................................................................ 39
Selection Screen Configuation ................................................................................................................ 40
Analyzing Results I: Non-Local Nested SQL Statements........................................................................ 43
Analyzing Results II: SQL Statements Transfering Large Numbers of Records ..................................... 47

Do you have a lot of custom ABAP code which drives your central business processes? Do you want to
leverage SAP HANA and do you want to know what this means for your custom code? Do you have some
doubts if the SQL performance and general quality of your custom code is already outstanding? If yes, then
this is your session. You will see step by step how you get your custom code ready for SAP HANA and in
parallel how this brings the performance and quality of your custom code on a new level right now. This is a
hands-on session with many demos - you will experience new ABAP Test Cockpit Checks, a brand new SQL
monitor and much more. Get ready for SAP HANA!

BEFORE YOU START


In the Hands-on session CD262 you have the opportunity to select your exercises depending on your
personal area of interest. However, you find the solutions to all exercises as reference this way you can
also see the solution of the exercises you did not finish.
Due to time constraints during the Hands-on session, it is recommended that you first take a look at the
different exercises and then decide which ones you want to work through first.
Exercise 1: ABAP Test Cockpit (ATC)
15 minutes
Exercise 2: SQL Monitor (SQLM)
15 minutes
Exercise 3: SQL Performance Tuning Worklist (SWLT)
15 minutes

Login Information
To logon to the system, use the following credentials.
Username: CD262_XX (replace XX with your group number)
Password: welcome

ABAP TEST COCKPIT


Estimated time: 15 minutes

Objective
In this exercise you are supposed to execute the ABAP Test Cockpit (ATC) online check on an example
program and deal with the emerging findings.
What you will learn

How to trigger the ATC online check


How to deal with different kinds of functional findings
How to trigger the ATC recheck

Exercise description
Please perform the following steps:

ATC Online Check


Locate your example program ZCD262_E1_XX (remember to replace XX with your group
number).
Execute the ATC online check on the program using the Code Inspector variant CD262.
Handling Findings I: READ .. BINARY SEARCH
Locate and inspect the findings related to a READ .. BINARY SEARCH / BREAK-POINT
statement.
Fix the issues and perform a recheck.
Handling Findings II: DELETE ADJACENT DUPLICATES
Locate and inspect the finding related to a DELETE ADJACENT DUPLICATES statement.
Fix the issue and perform a recheck.
Handling Findings III: Empty FOR ALL ENTRIES Tables
Locate and inspect the finding related to an Empty FOR ALL ENTRIES Table.
Fix the issue and perform a recheck.

ATC Online Check


Explanation

Screenshot

1. Enter /nse80 in the Transaction


box and confirm your entry by
pressing the Enter key in order to
start up the ABAP Development
Workbench.

2. Select Program from the dropdown list in the repository browser.

Explanation

3. Enter ZCD262_E1_XX in the box


(replace XX with your group number)
and confirm your entry by pressing
the Enter key.

Screenshot

Explanation

Screenshot

4. Double-click the program name


and inspect the source code that
opens up in the editor on the righthand side.

Explanation

5. Right-click the program name to


bring up the context menu and select
Check > ABAP Test Cockpit
with....

6. Switch to the Options tab and


enter CD262 in the field Code
Inspector Check Variant.

Screenshot

Explanation

Screenshot

7. Start the ATC check by clicking


Execute Checks or pressing F8.

Your result list should look like this. If


you are faced with different findings,
chances are that you picked the
wrong Code Inspector check variant.
For this exercise you need to use the
variant CD262.

Handling Findings I: READ .. BINARY SEARCH


Explanation

1. Select the READ .. BINARY


SEARCH finding and click
to
bring up the detail view. Alternatively
you can also double-click the line.

2. Click the Check Message hotspot


link to bring up the documentation.

10

Screenshot

Explanation

Screenshot

3. The What you can do section at


the bottom provides hints on how to
fix the issue.

11

Explanation

4. Close the documentation popup


and click Display Object in order to
navigate to the source code.

5. Double-click the first line to get to


the SELECT statement.
As this finding consists of two parts
(the SELECT and the READ ..
BINARY SEARCH) you are first
presented the call stack.

12

Screenshot

Explanation

Screenshot

6. Click Display <-> Change

You can also press Ctrl+F1.


If you are prompted to create a new
task, just confirm.

7. Fix the issue by adding an


additional ORDER BY clause to the
SELECT statement.
8. While you're at it, you can as well
remove the BREAK-POINT
statement.

9. Click Activate
Ctrl+F3.

or press

10. Click Back


or press F3 to
navigate back to the call stack and
repeat the action to return to the
result list.

11. Click Check Again


the ATC check.

to repeat

13

Explanation

12. Notice that the READ .. BINARY


SEARCH finding is gone.
13. The BREAK-POINT statement
was also recognized by the ATC and
is gone as well.

14

Screenshot

Handling Findings II: DELETE ADJACENT DUPLICATES


Explanation

Screenshot

1. Select the DELETE ADJACENT


DUPLICATES finding and click
to bring up the detail view. As before,
you can as well just double-click the
line.

2. Click Display Object in order to


navigate to the source code.

15

Explanation
3. Double-click the last line to get to
the DELETE ADJACENT
DUPLICATES statement.
As in the previous exercise this
finding consists of two parts (the
SELECT and the DELETE
ADJACENT DUPLICATES) and so
you are first presented the call stack.

4. Click
or press Ctrl+F1 to
switch to editing mode.

5. Fix the issue by adding an ABAP


SORT statement.

6. Click Activate
.
You can also press Ctrl+F3.
7. Click Back
.
You can also press F3.

16

Screenshot

Explanation

8. Click Check Again


the ATC check.

Screenshot

to repeat

9. Notice that the finding is gone.

17

Handling Findings III: Empty FOR ALL ENTRIES Tables


Explanation

1. Select the FOR ALL ENTRIES


finding and click
to bring up the
detail view. Alternatively you can
also double-click the line.

2. Click the Check Message hotspot


link to bring up the documentation.

18

Screenshot

Explanation

Screenshot

3. The Proposed Solution section


offers hints on how to fix the issue.

19

Explanation

4. Close the documentation popup


and click Display Object in order to
navigate to the source code.

5. Click
or press Ctrl+F1 to
switch to editing mode.

20

Screenshot

Explanation

Screenshot

6. Add an IF statement to ensure


that the FOR ALL ENTRIES table is
not empty.

7. Click Activate
Ctrl+F3.

or press

8. Click Back
or press F3 to
navigate back to the result list.

9. Click Check Again


the ATC check.

to repeat

10. Congratulations. You have fixed


all of the findings.

Summary
This exercise should have provided you with a basic understanding of how to use the ABAP Test Cockpit to
locate functional errors in ABAP source code.

21

SQL MONITOR SQLM


Estimated time: 15 minutes

Objective
In this exercise you are supposed to execute the Sql Monitor transaction SQLM to view and analyze the
current measurement for system M53.
What you will learn
Display of data with transaction SQLM
Usage of different combinations of sorting and filtering to find relevant source code
Analysis of the findings and proposal of improvements
Exercise description

22

Slow Request
Find the request with request entry point ZSQLM* with the largest total time.
Which statement of that request is responsible for the high time consumption?
How could the code be improved?
Many Executions
Which SQL-statement in package ZSQLM_TEST is executed most often?
For which entry points and in how many internal sessions is this statement executed?
How could the code be improved?
Huge Data Transfer
Find the two statements in package ZSQLM_TEST that fetch or modify at most database
records.
What could be improved?
Slow Statement
Find the SQLM trace entry in package ZSQLM_TEST with the largest value of Max.Time.
How can this large value be explained?

Slow Request
Explanation

Screenshot

1. Enter /nsqlm in the Transaction


box.
Confirm your entry by pressing the
Enter key.
Start transaction SQLM.

2. Click Display Data


.

23

Explanation

3. Select By Request .

24

Screenshot

Explanation

Screenshot

4. Select Total Time.


You may also filter by Request entry
point ZSQLM*.

5. Click Execute
.
You can also press F8.

25

Explanation

6. Click Records
.
The results visible in the screen shot
may differ from the current results in
the system that you see during the
exercise. In the screen shot, the third
row in the result display has entry
point ZSQLM_TEST11. The "3" in
the column records is the number of
SQLM data records with this entry
point. Click on this number to view
these records.

7. Double-click on Total Time [ms]


.
The topmost record has the largest
value of total time. Click on this row
to navigate to the source code.

26

Screenshot

Explanation

8. Click Back
previous page.

Screenshot

to return to the

You can also press F3.


SQL-statements in loops are an antipattern that should be replaced by
single
SQL-statements whenever possible.
In this case, the code may be
improved as follows (compare report
ZSQLM_TEST11_OPT):
do 75000 times.
wa-a = sy-index.
append wa to itab.
enddo.
insert zsqlm_test_users
from table itab.
On many databases, this is roughly
20 times faster than the code on the
screen.

27

Many Executions
Explanation

1. Select By Source Position.


As in the exercise before, go to the
Data display selection screen of
SQLM.

2. Select Executions .
You may also filter by package
ZSQLM_TEST.

3. Click Execute
.
You can also press F8.

28

Screenshot

Explanation

Screenshot

4. Double-click on Executions
.
As before, the current results you
see in the system may differ from the
screen shot. In the screen shot, the
third row contains the first result from
package ZSQLM_TEST (the
package name is not visible on the
screen, you could find it by scrolling
to the right).

5. Click Back
previous page.

to return to the

You can also press F3.


This whole loop with the SELECT
SINGLE statement can be replaced
by one Open SQL statement:
select order_id order_details_id
from zsqlm_test_order
into table details_tab
for all entries in
important_order_details
where order_id =
important_order_details-order_id
and item_name like pattern.

(compare report
ZSQLM_TEST3_OPT).

6. Click Records
.
Click on the link "3" to see the SQLM
records with this source position.

29

Explanation
7. Click Exe./Sess.
.
The loop with the SELECT SINGLE
statement is executed with three
different request entry points:
Reports ZSQLM_TEST,
ZSQLM_TEST3 and the remote
function call of
ZSQLM_CALLBACK_RFC.
The column "Int. Sess." shows, how
often each entry point was executed
whereas the column "Exe./Sess."
shows how often the statement was
executed on average for each entry
point.

30

Screenshot

Huge Data Transfer


Explanation

1. Click Execute

Screenshot

You can also press F8.


Again, we start on the Data Display
selection screen of SQLM. Clear
"Order by, Maximal Number of
Records" and keep the choice
"Aggregation - By Source Position".
Clearing the field "Maximal Number
of Records" (or entering 0) does not
limit the number of records that will
be displayed on the next screen.
This will be important afterwards.

2. Click Records

31

Explanation

3. Click Sort in Descending Order


.
You can also press Ctrl+Shift+F4.

4. Use the horizontal scroll bar to


display the desired screen area.
5. Click in the area to the right of
the scroll bar to scroll to the right.
Scroll to the right to see that the first
row has processing block
"LCL_USER_ADMIN=>GET_ACTIV
E_USER_IDS". Double click on that
row to navigate to the source code.
If you do not find this processing
block, you have probably limited the
number of records contained in the
list (look at the screen title). If this is
the case, restart this exercise.

32

Screenshot

Explanation
6. Click Back
previous page.

Screenshot
to return to the

You can also press F3.


The statement SELECT ... FOR ALL
ENTRIES IN user_ids
selects all entries of database table
ZSQLM_TEST_USERS when the
internal table user_ids is empty.
Often (like in this case), this is not
the intended behavior. Replacing the
statement by

if user_ids is not initial.


select a from zsqlm_test_users
into table itab
for all entries in user_ids
where a = user_ids-table_line.
...
endif.

speeds up the code considerably


(compare report
ZSQLM_TEST11_OPT).
7. Click
.
The large value of Max. Records
confirms that the SELECT ... FOR
ALL ENTRIES statement really
fetched many records from time to
time.
8. Double-click
on
.
The third row also contains a result
with package ZSQLM_TEST.
Double-click on that row to navigate
to the source code.

33

Explanation

9. Click Back
previous page.

Screenshot

to return to the

You can also press F3.


The result of the first SELECT
statement is only used locally within
the constructor. The
subsequent operations reduce the
size of the result set, so this situation
is a candidate for
code pushdown. In this case, code
push down of the whole constructor
method is possible by using a more
complex OpenSQL statement (see
report ZSQLM_TEST3_OPT):
select order_id order_details_id
from zsqlm_test_order
into table important_order_details
where ( order_id < 90000 or
item_name like 'ITEM_7%' ) and
item_name not like '____2%' and
item_name not like '____5%' and
order_details_id <= 120129
order by order_id.

34

Slow Statement
Explanation

Screenshot

1. Select None.
Start this exercise by going back to
the Data Display selection screen of
SQLM.

2. Enter ZSQLM_TEST in the


Package box.

35

Explanation

Screenshot

3. Click Execute
.
You can also press F8.

4. Click Max. Time

5. Click Sort in Descending Order


.
You can also press Ctrl+Shift+F4.

6. Double-click on
.
The topmost statement occasionally
needs more than 20 seconds to fetch
a single record ...

36

Explanation
7. Click Back
previous page.

Screenshot
to return to the

You can also press F3.


The database lock created by
"SELECT SINGLE FOR UPDATE" is
held for at least 5 seconds and
released afterwards by COMMIT
WORK.
Work processes that try to execute
the SELECT SINGLE FOR UPDATE
statement while this row of
zsqlm_test_tab3 is locked wait until
the lock is released. The SQLMonitor shows that Max.Time for the
SELECT statement is considerably
larger than 5 seconds. This indicates
that several work processes try to
execute the SELECT SINGLE FOR
UPDATE statement concurrently.

8. Enter /nse37 in the Transaction


box.
Confirm your entry by pressing the
Enter key.
The SELECT SINGLE FOR
UPDATE statement is executed with
entry point
ZSQLM_CALLBACK_RFC.

9. Enter zsqlm_callback_rfc in the


Function Module box.
Enter the name of the request entry
point zsqlm_callback_rfc in the
Function Module box.

37

Explanation

Screenshot

10. Click Where-Used List


.
You can also press Ctrl+Shift+F3.

11. Click Execute

12. Double-click
on
.

This function module is called 4


times asynchronously by report
ZSQLM_TEST. One of these
function modules has to wait until all
other function modules have
released the lock.

Summary
In this exercise, you have learned how to use the SQL monitor to find ABAP coding with a high resource
footprint. You have recognized some common mistakes in this coding and you have seen how to improve it.

38

SQL PERFORMANCE TUNING WORKLIST


Estimated time: 15 minutes

Objective
In this exercise you are supposed to use the SQL Performance Tuning Worklist to find and analyze
performance-critical SQL statements.
What you will learn

How to setup the selection screen of the SQL Performance Tuning Worklist
How to analyze results based on runtime and static data

Exercise description
Please perform the following steps:

Selection Screen Configuation


Start transaction SWLT and configure the selection screen.
The object set shall be restricted to the package pattern Z*.
The latest available SQL Monitor snapshot shall be used.
Static findings shall be imported from the most recent version of the ATC run series
PERFORMANCE_DB.
Load the result list.
Analyzing Results I: Non-Local Nested SQL Statements
Locate the most often executed SQL statement that is nested across modularization units.
Navigate to the source code.
Is the fact that the SQL statement is nested in an external loop easily seen from the
source code?
Display the call stack.
In which include and line does the call stack start?
Is the fact that the SQL statement is nested in an external loop easily seen from the
source code?
What is the dominating request entry point?
How often were the request entry points executed?
How often was the SQL statement executed in each execution of an request entry point on
average?
Analyzing Results II: SQL Statements Transfering Large Numbers of Records
Locate the SQL statement with the highest total number of transfered records.
Analyze the findings and try to determine why the number of records is so large.

39

Selection Screen Configuation


Explanation

1. Start up the Performance Tuning


Worklist by entering /nswlt in the
Transaction box.

2. If you're feeling lazy click Get


Variant...
or press Shift+F5 to
load a preconfigured selection
screen variant. Alternatively you can
also configure the selection screen
yourself. If you want to go this
slightly longer way, skip steps 2 and
3 and continue with step 4.

3. In the popup select the variant


CD262 and click Choose
or
press F2. You can now continue with
step 9 of this exercise.

4. In the section Object Set enter


the pattern Z* into the field Package.

40

Screenshot

Explanation

Screenshot

5. In the section SQL Monitor


Snapshot Selection tick the radio
button Overall Latest Snapshot.

6. Select the radio button ABAP


Test Cockpit in the section Static
Check Settings.
7. Click Select ATC Result
.

8. In the popup select the most


recent version of the
PERFORMANCE_DB run series and
click Continue

9. Click Execute
load the results.

or press Enter.

or press F8 to

41

Explanation

You should now be faced with a


screen like this.

42

Screenshot

Analyzing Results I: Non-Local Nested SQL Statements


Explanation

Screenshot

1. In order to make sure that the


result list is sorted by the total
number of executions, select the
column Executions and click

2. Right-click the column Check


Message and select the Set Filter...
menu item.

3. In the popup insert the pattern


NonLocal* into the filter field and
click Execute

or press Enter.

43

Explanation

4. The sought-after most often


executed non-local SQL statement
can now be found in the uppermost
row.

5. To navigate to the source code,


click the Include Name hotspot.

6. Inspect the source code.


The SELECT statement is locally
nested within the get_details
method. It is, however, not easily
seen from the source code that the
statement is also nested in a nonlocal way (the method is called in a
loop).

44

Screenshot

Explanation

Screenshot

7. Return to the result list by clicking


Back

or pressing F3.

8. Double-click the line to load


additional information into the two
detail views in the lower half of the
screen.

9. In the static detail view click the


Additional Information hotspot in
order to display the call stack.

10. The uppermost row indicates the


bottom of the call stack located in
line 111 of include ZSQLM_TEST3.

11. Here you finally get proof that the


get_details method is called in a
loop.
12. Click Back
or press F3 to
return to the result list.

45

Explanation

13. The dominating request entry


point can be found in the top row of
the SQL Monitor detail view which is
already sorted by the number of
executions.

14. Scroll to the right in the upper


view and locate the columns Int.
Sess. (Internal Sessions) and
Exe./Se... (Executions/Session). The
former provides the number of
executions of the entry points while
the latter indicates how often the
SQL statement was executed in one
internal session on average.

46

Screenshot

Analyzing Results II: SQL Statements Transfering Large Numbers of Records


Explanation

Screenshot

1. Reset any previously applied


filters.

2. Make sure the main result list is


scrolled to the top.

3. Scroll to the right and locate the


column Records.

4. Drag the column to the front and


click
order.

to sort it in descending

47

Explanation

5. Inspect the top two records.

6. Double-click the first row to load


the details.
7. The check title and message
indicate that this statement could
include an empty FOR ALL
ENTRIES table.

8. Click the Include Name hotspot to


navigate to the source code.

9. Inspect the source code.


As suspected the FOR ALL
ENTRIES table is used in the
SELECT statement without prior
content check. When the table is
empty, the WHERE clause is, thus,
invalidated which leads to the
observed high number of transfered
records.

48

Screenshot

Explanation

Screenshot

10. Click Back


or press F3 to
return to the result list.

11. Double-click the second row to


load the details.
12. The check title and message
suggest that this statement is as well
executed in a loop across
modularization units. This also
contributes to the observed high
number of transfered records.

Summary
With this exercise you should have obtained a basic idea of how to use the SQL Performance Tuning
Worklist to find and analyze performance pitfalls in your system.

49

2013 by SAP AG. All rights reserved.


SAP and the SAP logo are registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo are
trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company. Sybase and the Sybase logo are registered
trademarks of Sybase Inc. Sybase is an SAP company. Crossgate is a registered trademark of Crossgate AG in Germany and other countries. Crossgate is
an SAP company.

50

Das könnte Ihnen auch gefallen