Professional Documents
Culture Documents
This page contains some general guidelines for efficient ABAP/4 Program Development
that should be considered to improve the systems performance on the following areas:-
Physical I/O - data must be read from and written into I/O devices. This can be a potential
bottle neck. A well configured system always runs 'I/O-bound' - the performance of the
I/O dictates the overall performance.
Network communication - not critical for little data volumes, becomes a bottle neck when
large volumes are transferred.
Policies and procedures can also be put into place so that every SAP-customer
development object is thoroughly reviewed (quality – program correctness as well as
code-efficiency) prior to promoting the object to the SAP-production system.
Information on the SAP R/3 ABAP/4 Development Workbench programming tools and
its features can be found on the SAP Public Web-Server.
--------------------------------------------------------------------------------
Avoid dead-code
Spend adequate time anayzing business requirements, process flows, data-structures and
data-model
Quality assurance is key: plan and execute a good test plan and testing methodology
Experience counts
--------------------------------------------------------------------------------
vs.
In order to keep the amount of data which is relevant to the query the hit set small, avoid
using SELECT+CHECK statements wherever possible. As a general rule of thumb,
always specify all known conditions in the WHERE clause (if possible). If there is no
WHERE clause the DBMS has no chance to make optimizations. Always specify your
conditions in the Where-clause instead of checking them yourself with check-statements.
The database system can also potentially make use a database index (if possible) for
greater efficiency resulting in less load on the database server and considerably less load
on the network traffic as well.
Also, it is important to use EQ (=) in the WHERE clause wherever possible, and analyze
the SQL-statement for the optimum path the database optimizer will utilize via SQL-trace
when necessary.
Also, ensure careful usage of "OR", "NOT" and value range tables (INTTAB) that are
used inappropriately in Open SQL statements.
--------------------------------------------------------------------------------
SELECT *
vs.
SELECT SINGLE *
If you are interested in exactly one row of a database table or view, use the SELECT
SINGLE statement instead of a SELECT * statement. SELECT SINGLE requires one
communication with the database system whereas SELECT * requires two.
--------------------------------------------------------------------------------
vs.
It is usually faster to use the INTO TABLE version of a SELECT statement than to use
APPEND statements
--------------------------------------------------------------------------------
vs.
If you want to find the maximum, minimum, sum and average value or the count of a
database column, use a select list with aggregate functions instead of computing the
aggregates within the program. The RDBMS is responsible for aggregated computations
instead of transferring large amount of data to the application. Overall Network,
Application-server and Database load is also considerably less.
--------------------------------------------------------------------------------
vs.
If you process your data only once, use a SELECT-ENDSELECT loop instead of
collecting data in an internal table with SELECT ... INTO TABLE. Internal table
handling takes up much more space
--------------------------------------------------------------------------------
vs.
To process a join, use a view wherever possible instead of nested SELECT statements.
Using nested selects is a technique with low performance. The inner select statement is
executed several times which might be an overhead. In addition, fewer data must be
transferred if another technique would be used eg. join implemented as a view in ABAP/4
Repository.
--------------------------------------------------------------------------------
Nested select:
SELECT * FROM pers WHERE condition.
SELECT * FROM persproj WHERE person = pers-persnr.
... process ...
ENDSELECT.
ENDSELECT.
vs.
SELECT persnr FROM pers INTO TABLE ipers WHERE cond. ……….
SELECT * FROM persproj FOR ALL ENTRIES IN ipers
WHERE person = ipers-persnr
………... process .……………
ENDSELECT.
In the lower version the new Open SQL statement FOR ALL ENTRIES is used. Prior to
the call, all interesting records from 'pers' are read into an internal table. The second
SELECT statement results in a call looking like this (ipers containing: P01, P02, P03):
(SELECT * FROM persproj WHERE person = 'P01')
UNION
(SELECT * FROM persproj WHERE person = 'P02')
UNION
(SELECT * FROM persproj WHERE person = 'P03')
In case of large statements, the R/3's database interface divides the statement into several
parts and recombines the resulting set to one. The advantage here is that the number of
transfers is minimized and there is minimal restrictions due to the statement size (compare
with range tables).
--------------------------------------------------------------------------------
vs.
Use a select list or a view instead of SELECT *, if you are only interested in specific
columns of the table. If only certain fields are needed then only those fields should be read
from the database. Similarly, the number of columns can also be restricted by using a
view defined in ABAP/4 Dictionary. Overall database and network load is considerably
less.
--------------------------------------------------------------------------------
vs.
For all frequently used, read-only(few updates) tables, do attempt to use SAP-buffering
for eimproved performance response times. This would reduce the overall Database
activity and Network traffic.
--------------------------------------------------------------------------------
Single-line inserts
LOOP AT <INT-TAB>
INSERT INTO <TABLE> VALUES <INT-TAB>
ENDLOOP
vs.
Array inserts
Whenever possible, use array operations instead of single-row operations to modify the
database tables.
Frequent communication between the application program and database system produces
considerable overhead.
--------------------------------------------------------------------------------
Single-line updates
SELECT * FROM <TABLE>
<COLUMN-UPDATE STATEMENT>
UPDATE <TABLE>
ENDSELECT
vs.
Column updates
UPDATE <TABLE> SET <COLUMN-UPDATE STATEMENT>
Wherever possible, use column updates instead of single row updates to update your
database tables
--------------------------------------------------------------------------------
vs.
Using CA operator
Use the special operators CO, CA, CS instead of programming the operations yourself
If ABAP/4 statements are executed per character on long strings, CPU consumprion can
rise substantially
--------------------------------------------------------------------------------
Some function modules for string manipulation have become obsolete, and should be
replaced by ABAP statements or functions
--------------------------------------------------------------------------------
vs.
--------------------------------------------------------------------------------
vs.
--------------------------------------------------------------------------------
vs
If you want ot delete the leading spaces in a string use the ABAP/4 statements
SHIFT...LEFT DELETING LEADING... Other constructions (with CN and SHIFT... BY
SY-FDPOS PLACES, with CONDENSE if possible, with CN and ASSIGN CLA+SY-
FDPOS(LEN) ...) are not as fast
--------------------------------------------------------------------------------
vs
Use the strlen () function to restrict the DO loop to the relevant part of the field, eg. when
determinating a check-sum