You are on page 1of 22

Introduction

Write a report that displays the text 'Hello world' on your screen.
Solution
Ok, because this is your first program, you get an extra help.
Call Transaction 'SE38'.
Create a new program.
To proceed in an SAP 3.x system you must be registered as a Developer. You get your
Developer Key from your Sys. admin in a couple of minutes/hours/days after you
applied for it. It must be entered once when you create your first program.
Program attributes:
Type: 1
Application: S
Choose a meaningful title
(Save)
Choose Development Class &TMP or press Button 'Local object'
Now you can edit the source code.
Position the cursor in a line number cell. Press F1 for the help of editor line
commands.
enter i3 which inserts three new rows into your program.
report zbctcb98.
write: / 'hello world'.
(Save, Generate, Execute)
In 3.x you can set your Editor mode in menu /Settings/Editor mode
(in 2.x this is the only editor mode)
If you choose Command mode you get an extra input line, where you can execute
commands. Position the cursor here and press F1 for the available commands. My
favorite one is the HELP command.Try out the HELP WRITE command. What you
see now is a hypertext (clickable). I know that this online help is an online

meaningless chaos for the first time, but sooner or later it should become your
reference.

The title of the report should not be printed in your list. Define an integer variable
with a value of 2. Display the text 'example' and then this variable. Create an integer
input parameter (Default value 20). Display the 'hello world' in the same row, the input
parameter tells in wich column. Check that the the value of your input paramater is
between 0 and 40.
On the screen you should get something like this:
example

hello world

Solution

Second variant for 'hello world'


report zbctcb98 no standard page heading.
parameters: column type i default 20.
data: num2 type i value 2.
check column ge 0 and column le 40.
write: / 'example', num2, at column 'hello world' intensified off.
Try out different values for column. You should notice that the display of num2 is
right-justified. Check the output characteristics of other data types!

Modify the second example. Display a title row with page number and date. Put a
counter before the rows and display a header line at the top of each page. Format the
numbers so, that just 4 places are displayed. (the value of the parameter is 40 to get a
nice list)
The list should look like this one:
Page: 1
Counter
1
2
3
4
Solution

Text
example
example
example
example

Third Example
Number
2
2
2
2

18.03.1997
Introduction
hello world
hello world
hello world
hello world

It's the first formatted list


report zbctcb98 no standard page heading line-size 90 line-count 120.
parameters: column type i default 40.
data: num2 type i value 2.
data: counter type i value 1.
check column ge 0 and column le 40.
do.
write: /2(4) counter, 15 'example', 23(4) num2,
at column 'hello world' intensified off.
add 1 to counter.
check counter eq 161.
exit.
enddo.
top-of-page.
write: /2 'Page:', 8(4) sy-pagno, 40 'Third Example', 70 sy-datum.
uline.
write: /2 'Counter', 15 'Text', 23 'Number',
at column 'Introduction' intensified off.
uline.
Try out the SHOW SY command in the editor command line. The SHOW command
describes the fields of database tables, views and structures. With the SHOW SY
command you can see the fields of the SYSTEM structure. These fields are updated at
run time. In this example we used the fields sy-pagno and sy-datum.

Read a logical database (you must have data in those tables, now LFA1), fill up an
internal table. Sort the data by a given field and then display the internal table.
solution

Reading database tables - logical database


report zbctcb98 no standard page heading.
tables: lfa1.
data: begin of t occurs 0,
linfr like lfa1-lifnr,
name1 like lfa1-name1,
end of t.
start-of-selection.
get lfa1.
clear t.
move-corresponding lfa1 to t.
append t.
end-of-selection.
sort t by name1.

loop at t.
write: / t-name1, t-lifnr.
endloop.

Write the same report with a select statement.


solution

Reading database tables - select


report zbctcb98 no standard page heading.
tables: lfa1.
select * from lfa1 order by name1.
write: / lfa1-name1, ' ', lfa1-lifnr.
endselect.

Useful System Adm. Utilities


Autotransport
Complete documentation to perform automatic transports. The developer mails the change
request numbers to a technical user. The program collects these mails regularly and starts the
imports for the the requested system. In this way the transports are automatically imported,
the system administrator checks only the logs. The program can be scheduled as a job to run
at anytime. Documentation is written in German, there is a concise English translation.
Sendmessage
This is a modification of the standard system. It implements the 'send message' function. The
system administrator (or user) can send individual messages to one or more users. The chosen
users will receive the message immediately in a pop-up window.
ZBCTCB89.TXT
The report creates a user list of the system.
Useful in a multi-client development system.
Fields: user-id, client, printer, profiles
ZBCMKZ17.TXT
Report and Transaction Starter. It shows an individual list of reports/trans. to start
It's like User Menu, but you can also start reports with it (and much faster).
Needs a table with user name and favourite reports/ transactions.
ZPROG001.TXT
Fills up a database table with records from a UNIX file.

BC Tips&Tricks
You run a report as job and it does not want to finish.
You might want to debug the report to find out what causes this 'neverending' run.
1. Start the report as a job.
2. Call transaction 'SM50'
3. Put the cursor on the workprocess which runs your job.
4. Push button 'Debugging'.
You will get a session where you can debug the running job. Be careful! When the job
is in the middle of a SELECT it will dump when you try to debug.
If you start the report online and already opened a second session, you can start
transaction 'SM04'. Click on the user-id and choose the session you want to debug.
After pressing the button 'Debugging', the choosen session jumps in debug mode.
Infosystem
You forgot the name of an SAP table or program, but found one which is quite similar to it.
I found the easiest way to use the development class as search field. Look for it in the
attributes of the known program/table. Then go to the infosystem in the development
workbench. Select the object type you are looking for. Set only the development class on the
selection screen.
Program analysis
You want to find out which tables are used in a standard program, but the source code is too
complex to analyze or debug.
Switch on the SQL trace and run the program. Later you can find all the used tables in the
trace log.

SAP R/3 3.0d


Useful System Adm. Transactions
AL01 SAP Alert Monitor
AL02 Database alert monitor
AL03 Operating system alert monitor
AL04 Monitor call distribution
AL05 Monitor current workload
AL06 Performance: Upload/Download
AL07 EarlyWatch Report
AL08 Users Logged On
AL09 Data for database expertise
AL10 Download to Early Watch
AL11 Display SAP Directories
AL12 Display table buffer (Exp. session)
AL13 Display Shared Memory (Expert mode)
AL15 Customize SAPOSCOL destination
AL16 Local Alert Monitor for Operat.Syst.
AL17 Remote Alert Monitor f.Operat. Syst.
AL18 Local File System Monitor
AL19 Remote File System Monitor
AL20 EarlyWatch Data Collector List
CREF Cross-reference
DB01 Analyze exclusive lockwaits
DB02 Analyze tables and indexes
DB03 Parameter changes in database
DB11 Early Watch Profile Maintenance
DB12 Overview of Backup Logs
DB13 Database administration calendar
DB14 Show SAPDBA Action Logs
DMIG Start Transaction for Data Migration
RLOG Data migration logging
RZ01 Job Scheduling Monitor
RZ02 Network Graphics for SAP Instances
RZ03 Presentation, Control SAP Instances
RZ04 Maintain SAP Instances
RZ06 Alerts Thresholds Maintenance
RZ08 SAP Alert Monitor
RZ10 Maintenance of profile parameters
RZ11 Profile parameter maintenance
SA38 ABAP/4 Reporting
SARA Archive management
SARL Call of ArchiveLink Monitor
SARP Reporting (Tree Structure): Execute
SART Display Reporting Tree
SCC0 Client Copy
SCC1 Client Copy - Special Selections

SCC2 Client transport


SCC3 Client Copy Log
SCC4 Client administration
SCC5 Client Delete
SCOM SAPcomm: Configuration
SCPF Generate enterprise IMG
SCU0 Table Analyses And Comparison
SCU1 Table Comparison - Export to Tape
SCU2 Table Comparison Against Tape
SCU3 Table History
SE01 Transport and Correction System
SE02 Environment Analyzer
SE03 Transport Utilities
SE06 Set up Workbench Organizer
SE07 Transport System Status Display
SICK Installation Check
SM01 Lock Transactions
SM02 System Messages
SM04 User Overview
SM12 Display and Delete Locks
SM13 Display Update Records
SM21 System log
SM23 System Log Analysis
SM28 Installation Check
SM30 Call Up View Maintenance
SM31 Table maintenance
SM35 Batch Input Monitoring
SM36 Batch request
SM37 Background job overview
SM38 Queue Maintenance Transaction
SM39 Job analysis
SM49 Execute Logical Commands
SM50 Work Process Overview
SM51 List of SAP Servers
SM54 TXCOM maintenance
SM55 THOST maintenance
SM56 Number Range Buffer
SM58 Asynchronous RFC Error Log
SM59 RFC Destinations (Display/Maintain)
SM60 Borrow/Return Objects
SM63 Display/Maintain Operating Mode Sets
SM64 Release of an event
SM65 Background Processing Analysis Tool
SM66 Systemwide Work Process Overview
SM67 Job scheduling
SM68 Job administration
SM69 Display/Maintain Logical Commands
SMEN Dynamic menu
SMGW Gateway Monitor
SMLG Maintain Logon Group

SMLI Language import utility


SMLT Language transport utility
SP12 TemSe Administration
SPAD Spool Management
ST01 System Trace
ST02 Setups/Tune Buffers
ST03 Performance,SAP Statistics, Workload
ST04 Select activity of the databases
ST05 SQL Trace
ST06 Operating System Monitor
ST07 Application monitor
ST08 Network Monitor
ST09 Network Alert Monitor
ST10 Table Call Statistics
ST11 Display Developer Traces
ST22 ABAP/4 Runtime Error Analysis
ST62 Create industry short texts
STAT Local transaction statistics
SU01 Maintain User
SU02 Maintain Authorization Profiles
SU03 Maintain Authorizations
SU10 Mass changes to User Master
SU11 Maintain Authorizations
SU12 Mass Changes to User Master Records
SU20 Maintain Authorization Fields
SU21 Maintain Authorization Objects
SU22 Auth. object usage in transactions
SU30 Total checks in the area of auth.

System fields

ABCDE
APPLI
BATCH
BATZD
BATZM
BATZO
BATZS
BATZW
BINPT
BREP4
BSPLD
CALLD
CALLR
CCURS
CCURT
CDATE
COLNO
CPAGE
CPROG
CTABL
CTYPE
CUCOL
CUROW
DATAR
DATLO
DATUM
DATUT
DAYST
DBCNT
DBNAM
DBSYS
DCSYS
DSNAM
DYNGR
DYNNR
FDAYW
FDPOS
FMKEY
HOST
INDEX
LANGU
LDBPG
LILLI
LINCT

Constant: Alphabet (A,B,C,...)


SAP applications
Background active (X)
Background SUBMIT: Daily
Background SUBMIT: Monthly
Background SUBMIT: Once
Background SUBMIT: Immediately
Background SUBMIT: Weekly
Batch input active (X)
Background SUBMIT: Root name of request report
Background SUBMIT: List output to spool
CALL mode active (X)
Print: ID for print dialog function
Rate specification/result field (CURRENCY CONVERT)
Table rate from currency conversion
Date of rate from currency conversion
Current column during list creation
Current page number
Runtime: Main program
Exchange rate table from currency conversion
Exchange rate type 'M','B','G' from CURRENCY
CONVERSION
Cursor position (column)
Cursor position (line)
Flag: Data received
Local date for user
System: Date
Global date related to UTC (GMT)
Summertime active ? ('daylight saving time')
Number of elements in edited dataset with DB operations
Logical database for ABAP/4 program
System: Database system
System: Dialog system
Runtime: Name of dataset for spool output
Screen group of current screen
Number of current screen
Factory calendar weekday
Location of a string
Current function code menu
Host
Number of loop passes
SAP logon language key
Program: ABAP/4 database program for SY-DBNAM
Number of current list line
Number of list lines

LINNO
LINSZ
LISEL
LISTI
LOCDB
LOCOP
LOOPC
LSIND
LSTAT
MACDB
MACOL
MANDT
MARKY
MAROW
MODNO
MSGID
MSGLI
MSGNO
MSGTY
MSGV1
MSGV2
MSGV3
MSGV4
OPSYS
PAART
PAGCT
PAGNO
PDEST
PEXPI
PFKEY
PLIST
PRABT
PRBIG
PRCOP
PRDSN
PREFX
PRIMM
PRNEW
PRREC
PRREL
PRTXT
REPID
RTITL
SAPRL
SCOLS

Current line for list creation


Line size of list
Interact.: Selected line
Number of current list line
Local database exists
Local database operation
Number of LOOP lines at screen step loop
Number of secondary list
Interact.: Status information for each list level
Program: Name of file for matchcode access
Number of columns from SET MARGIN
Client number from SAP logon
Current line character for MARK
No. of lines from SET MARGIN statement
Number of alternative modi
Message ID
Interact.: Message line (line 23)
Message number
Message type (E,I.W,...)
Message variable
Message variable
Message variable
Message variable
System: Operating system
Print: Format
Page size of list from REPORT statement
Runtime: Current page in list
Print: Output device
Print: Spool retention period
Runtime: Current F key status
Print: Name of spool request (list name)
Print: Department on cover sheet
Print: Selection cover sheet
Print: Number of copies
Print: Name of spool dataset
ABAP/4 prefix for background jobs
Print: Print immediately
Print: New spool request (list)
Print: Recipient
Print: Delete after printing
Print: Text for cover sheet
Program: Name of ABAP/4 program
Print: Report title of program to be printed
System: SAP Release
Columns on screen

SLSET
SPONO
SPONR
SROWS
STACO
STARO
STEPL
SUBRC
SUBTY
SYSID
TABIX
TCODE
TFDSN
TFILL
TIMLO
TIMUT
TITLE
TLENG
TMAXL
TNAME
TOCCU
TPAGI
TSTLO
TSTUT
TTABC
TTABI
TVAR0
TVAR1
TVAR2
TVAR3
TVAR4
TVAR5
TVAR6
TVAR7
TVAR8
TVAR9

Name of selection set


Runtime: Spool number for list output

Runtime: Spool number from TRANSFER statement


Lines on screen
Interact.: List displayed from column
Interact.: Page displayed from line
Number of LOOP line at screen step
Return value after specific ABAP/4 statements
ABAP/4: Call type for SUBMIT
System: SAP System ID
Runtime: Current line of an internal table
Session: Current transaction code
Runtime: Dataset for data extracts
Current number of entries in internal table
Local time for user
Global time related to UTC (GMT)
Title of ABAP/4 program
Line width of an internal table
Maximum number of entries in internal table (?)
Name of internal table after an access (?)
OCCURS parameter with internal tables
Flag indicating roll-out of internal table to paging area (?)
Timestamp (date and time) for user
Timestamp (date and time) related to UTC (GMT)
Number of line last read in an internal table (?)
Offset of internal table in roll area (?)
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Runtime: Text variable for ABAP/4 text elements
Time difference from 'Greenwich Mean Time' (UTC) in
TZONE
seconds
UCOMM Interact.: Command field function entry
ULINE
Constant: Underline (---------...)
UNAME Session: SAP user from SAP logon
UZEIT
System: Time
VLINE
Constant: Vertical bar
WAERS T001: Company code currency after reading B segment

WILLI
WINCO
WINDI
WINRO
WINSL
WINX1
WINX2
WINY1
WINY2
WTITL
XCODE
ZONLO

Number of current window line


Cursor position in window (column)
Index of current window line
Cursor position in window (line)
Interact.: Selected window line
Window coordinate (column left)
Window coordinate (column right)
Window coordinate (line left)
Window coordinate (line right)
Standard page header indicator
Extended command field
Time zone of user

Tips&Tricks
How to customize the display options?
In the right upper corner of your SAP window you can find a symbol. Click on it. In the
Options you can change the colors, text fonts. Hide or display various elements of the
standard SAP window. There are two important settings.
In the Cursor folder enable AutoTAB. This means that after filling an 8 character field with
eight character you don't have to push the TAB button to jump to the next field, the system
automatically puts the cursor there.
In the General folder you can deselect the statusbar. This enlarges the work area of your
window. When you receive a warning this comes in a small window and you must press the
button to return to your work. But you don't see the time, system and session number in the
status line any more.
With the Default Size options you can easily change your window back to the default size.

Office Tips
You want to send an urgent message to an SAP user. When you send your mail choose the
option Express. The user receives your letter immediately and a popup window informs him
that he has an express mail in his mailbox.
Go /Office/Outbox/Edit and create a mail. In the Extras menu you can find the Insert URL
function. Fill out the fields and press Ok. This puts a text in your letter which referes to a Web
page (same as an html link). If your network has Internet access, when the receiver clicks on
the text the Web browser starts and loads the refered Web page automatically.
Printer problems
Printing does not work in SAP. There is a printer definition for your local printer, but it does
not work. Presuming that you use the program SAPLPD on your computer.
Boot your computer and start only the SAPLogon and the SAPLpd program.
Delete all of your old print jobs in the SAP system (Transaction SP01).Generate only
one new print job.
Check that there is enough resource in your computer. Check the free memory (Win
3.1x) and the free disk space (The lists are temporarily saved on your disk).
Open the SAPLPD and read the print log in the window. The printer definition must
correspond with the parameters shown here.
Check that the standard printer is on the same lpt (Win 3.1: Control panel, Printer) as
defined for the printer (usually lpt1).
In Transaction SP01 read the protocol of your print job. Do not generate new print
jobs! Wait till the SAP system changes the status of the print job.
If you can not find the print job in SP01 anymore, then the print job was successfully
printed out. If it didn't come out on your printer and the SAPLpd didn't indicate an
incoming print job, then the connection was realised with another PC. Then SAP
printer definition you used, does not correspond with your computer.
Use icons in your mail
Put the code @nn@ in the title or in the body of your SAP mail where nn is a number, for
example 01 ( @01@ ). The system will look up the icon and displays it in the mail. The next
program lists the icon codes, their length with other information and the corresponding icons.
REPORT ZMDICON2.
TABLES: ICON.
DATA: ICONE LIKE ICON-ID.
DATA: BUFFER(4),
FF LIKE ICON-NAME.
INCLUDE <ICON>.
FIELD-SYMBOLS: <F>.
WRITE : /
'Icon
Id
L B S M F Name der Icone'.
ULINE.
WRITE : /
'Icone
Id
Lnge
F fr Funktionstaste geeignet'.
WRITE : /
'
M
fr Nachricht (message) geeignet'.
WRITE : /
'
S
fr Statusanzeige geeignet'.
WRITE : /
'
B
fr Drucktaste (button) geeignet'.
ULINE.
SELECT * FROM ICON.

MOVE: ICON-ID TO ICONE,


ICON-NAME TO FF.
ASSIGN (FF) TO <F>.
MOVE <F> TO BUFFER.
* write: / buffer, <f>, 20 icon-id,icon-name,icon-oleng,
WRITE: / BUFFER.
* write at (4) <f>.
WRITE:
20 '@',21 ICON-ID+1(2),23 '@',ICON-OLENG,
ICON-BUTTON,ICON-STATUS,ICON-MESSAGE,ICON-FUNCTION,
ICON-NAME.
ENDSELECT.

SAP ABAP Performance Tuning


Tips & Tricks
Introduction
Page 1 of 8

Need for performance tuning


In this world of SAP programming, ABAP is the universal language. In most of the projects, the focus is on
getting a team of ABAP programmers as soon as possible, handing over the technical specifications to them and
asking them to churn out the ABAP programs within the given deadlines.
Often due to this pressure of schedules and deliveries, the main focus of making a efficient program takes a back
seat. An efficient ABAP program is one which delivers the required output to the user in a finite time as per the
complexity of the program, rather than hearing the comment I put the program to run, have my lunch and come
back to check the results.

Leaving aside the hyperbole, a performance optimized ABAP program saves the time of the end user, thus
increasing the productivity of the user, and in turn keeping the user and the management happy.
This tutorial focuses on presenting various performance tuning tips and tricks to make the ABAP programs
efficient in doing their work. This tutorial also assumes that the reader is well versed in all the concepts and
syntax of ABAP programming.
NOTE: Performance of a program is also often limited due to hardware restrictions, which is out of the scope of
this article.
================================================================================

Use of selection criteria


Instead of selecting all the data and doing the processing during the selection, it is advisable to restrict the data to
the selection criteria itself, rather than filtering it out using the ABAP code.
Not recommended
Select * from zflight.
Check : zflight-airln = LF and zflight-fligh = BW222.
Endselect.
Recommended
Select * from zflight where airln = LF and fligh = 222.
Endselect.
One more point to be noted here is of the select *. Often this is a lazy coding practice. When a programmer gives
select * even if one or two fields are to be selected, this can significantly slow the program and put unnecessary
load on the entire system. When the application server sends this request to the database server, and the database
server has to pass on the entire structure for each row back to the application server. This consumes both CPU
and networking resources, especially for large structures.
Thus it is advisable to select only those fields that are needed, so that the database server passes only a small
amount of data back.
Also it is advisable to avoid selecting the data fields into local variables as this also puts unnecessary load on the
server. Instead attempt must be made to select the fields into an internal table.

Use of aggregate functions


Use the already provided aggregate functions, instead of finding out the minimum/maximum values using ABAP
code.
Not recommended
Maxnu = 0.
Select * from zflight where airln = LF and cntry = IN.
Check zflight-fligh > maxnu.

Maxnu = zflight-fligh.
Endselect.

Recommended
Select max( fligh ) from zflight into maxnu where airln = LF and cntry = IN.
The other aggregate functions that can be used are min (to find the minimum value), avg (to find the average of a
Data interval), sum (to add up a data interval) and count (counting the lines in a data selection).

Use of Views instead of base tables


Many times ABAP programmers deal with base tables and nested selects. Instead it is always advisable to see
whether there is any view provided by SAP on those base tables, so that the data can be filtered out directly,
rather than specially coding for it.
Not recommended
Select * from zcntry where cntry like IN%.
Select single * from zflight where cntry = zcntry-cntry and airln = LF.
Endselect.

Recommended
Select * from zcnfl where cntry like IN% and airln = LF.
Endselect.

Use of the into table clause of select statement


Instead of appending one record at a time into an internal table, it is advisable to select all the records in a single
shot.
Not recommended
Refresh: int_fligh.
Select * from zflight into int_fligh.
Append int_fligh. Clear int_fligh.
Endselect.

Recommended
Refresh: int_fligh.

Select * from zflight into table int_fligh.

Modifying a group of lines of an internal table


Use the variations of the modify command to speed up this kind of processing.
Not recommended
Loop at int_fligh.
If int_fligh-flag is initial.
Int_fligh-flag = X.
Endif.
Modify int_fligh.
Endloop.

Recommended
Int_fligh-flag = X.
Modify int_fligh transporting flag where flag is initial.

Use of binary search option


When a programmer uses the read command, the table is sequentially searched. This slows down the processing.
Instead of this, use the binary search addition. The binary search algorithm helps faster search of a value in an
internal table. It is advisable to sort the internal table before doing a binary search. Binary search repeatedly
divides the search interval in half. If the value to be searched is less than the item in the middle of the interval,
the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.
Not Recommended
Read table int_fligh with key airln = LF.

Recommended
Read table int_fligh with key airln = LF binary search.

Appending 2 internal tables


Instead of using the normal loop-endloop approach for this kind of programming, use the variation of the append
command. Care should be taken that the definition of both the internal tables should be identical.
Not Recommended
Loop at int_fligh1.

Append int_fligh1 to int_fligh2.


Endloop.

Recommended
Append lines of int_fligh1 to int_fligh2.

Using table buffering


Use of buffered tables is recommended to improve the performance considerably. The buffer is bypassed while
using the following statements

1.
2.
3.
4.

Select distinct
Select for update
Order by, group by, having clause
Joins

Use the Bypass buffer addition to the select clause in order to explicitly bypass the buffer while selecting the
data.

Use of FOR ALL Entries


Outer join can be created using this addition to the where clause in a select statement. It speeds up the
performance tremendously, but the cons of using this variation are listed below

1. Duplicates are automatically removed from the resulting data set. Hence care should be taken
that the unique key of the detail line items should be given in the select statement.

2. If the table on which the For All Entries IN clause is based is empty, all rows are selected into
3.

the destination table. Hence it is advisable to check before-hand that the first table is not
empty.
If the table on which the For All Entries IN clause is based is very large, the performance will
go down instead of improving. Hence attempt should be made to keep the table size to a
moderate level.

Not Recommended
Loop at int_cntry.
Select single * from zfligh into int_fligh
where cntry = int_cntry-cntry.
Append int_fligh.
Endloop.

Recommended
Select * from zfligh appending table int_fligh

For all entries in int_cntry


Where cntry = int_cntry-cntry.

Proper structure of Where Clause


When a base table has multiple indices, the where clause should be in the order of the index, either a primary or
a secondary index.
To choose an index, the optimizer checks the field names specified in the where clause and then uses an index
that has the same order of the fields. One more tip is that if a table begins with MANDT, while an index does
not, there is a high possibility that the optimizer might not use that index.
In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program.
This will come handy in programs that access data from the finance tables.

Proper use of Move statement


Instead of using the move-corresponding clause it is advisable to use the move statement instead. Attempt should
be made to move entire internal table headers in a single shot, rather than moving the fields one by one.

Proper use of Inner Join


When multiple SAP tables are logically joined, it is always advisable to use inner join to read the data from
them. This certainly reduces the load on the network.
Let us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code
and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and
other fields which hold the details of the flights that an airline operates.
Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.
Select a~airln a~lnnam b~fligh b~cntry into table int_airdet
From zairln as a inner join zflight as b on a~airln = b~airln.
In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join.

Use of ABAP Sort instead of Order By


The order by clause is executed on the database server, while the sort statement is executed on the application
server. Thus instead of giving the order by in the select clause statement, it is better to collect the records in an
internal table and then use the sort command to sort the resulting data set.

Tools provided for Performance Analysis


Following are the different tools provided by SAP for performance analysis of an ABAP object

1. Run time analysis transaction SE30


This transaction gives all the analysis of an ABAP program with respect to the database and the nondatabase processing.

2. SQL Trace transaction ST05

The trace list has many lines that are not related to the SELECT statement in the
ABAP program. This is because the execution of any ABAP program requires
additional administrative SQL calls. To restrict the list output, use the filter introducing
the trace list.
The trace list contains different SQL statements simultaneously related to the one SELECT statement in
the ABAP program. This is because the R/3 Database Interface - a sophisticated component of the R/3
Application Server - maps every Open SQL statement to one or a series of physical database calls and
brings it to execution. This mapping, crucial to R/3s performance, depends on the particular call and
database system. For example, the SELECT-ENDSELECT loop on the SPFLI table in our test program
is mapped to a sequence PREPARE-OPEN-FETCH of physical calls in an Oracle environment.
The WHERE clause in the trace list's SQL statement is different from the WHERE
clause in the ABAP statement. This is because in an R/3 system, a client is a selfcontained unit with separate master records and its own set of table data (in
commercial, organizational, and technical terms). With ABAP, every Open SQL
statement automatically executes within the correct client environment. For this
reason, a condition with the actual client code is added to every WHERE clause if a
client field is a component of the searched table.
To see a statement's execution plan, just position the cursor on the PREPARE statement and
choose Explain SQL. A detailed explanation of the execution plan depends on the database
system in use.

You might also like