Select Where VS Select + Check
Always specify your conditions in the Where-clause instead of checking them yourself with
check statements. The database system can then use an index (if possible) and the network
load is considerably less.
Select with Index Support
For all frequently used Select statements, try to use an index. You always use an index if
you specify (a generic part of) the index fields concatenated with logical Ands in the Select statement's Where clause. Note that complex Where clauses are poison for the
statement optimizer in any database system.
Select single vs. Select-Endselect
if there exists at least one row of a database table or view with a certain condition, use
the Select Single statement instead of a Select-Endselect-loop. Select Single requires one
communication with the database system, whereas Select-Endselect needs two.
Select Into table t
It is always faster to use the Into Table version of a Select statement than to use Append
statements.
Select aggregates
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
yourself. Network load is considerably less.
Select Endselect VS Aray Select
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.
Select with View
To process a join, use a view instead of nested Select statements. Network load is
considerably less.
Select with join
To read data from several logically connected tables use a join instead of nested Select
statements. Network load is considerably less.
Select with select list
Use a select list or a view instead of Select * , if you are only interested in specific
columns of the table. Network load is considerably less.
Select with buffer support
For all frequently used, read-only tables, try to use SAP buffering. Network load is
considerably less.
Array insert VS Single-row Insert
Whenever possible, use array operations instead of single-row operations to modify your
database tables. Frequent communication between the application program and database system produces considerable overhead.
Column Update
Whenever possible, use column updates instead of single-row updates to update your database
tables. Network load is considerably less.
Using subqueries
Instead of using nested Select loops or FOR ALL ENTRIES it is often possible to use
subqueries. Network load is considerably less.
String Manupulations
Special Operators in If (CA,.....
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 consumption can rise substantially.
String Concatenation
Some function modules for string manipulation have become obsolete and should be replaced by ABAP/4 statements or functions: STRING_CONCATENATE... -> CONCATENATE, STRING_SPLIT... ->
SPLIT, STRING_LENGTH -> strlen(), STRING_CENTER -> WRITE...TO...CENTERED, STRING_MOVE_RIGHT
-> WRITE...TO...RIGHT-JUSTIFIED
String Concatenation
Use the CONCATENATE statement instead of programming a string concatenation of your own.
Leading Spaces
If you want to delete the leading spaces in a string, use the ABAP/4 statement 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. In any
case, avoid using SHIFT inside a WHILE-loop!
String Split
Use the SPLIT statement instead of programming a string split yourself.
String Length
Use the strlen( ) function to restrict the DO loop to the relevant part of the field, e.g. when determinating a check-sum.
Clear Field
Use "CLEAR f WITH val" whenever you want to initialize a field with a value different from the field's type-specific initial value.
Using an Expicit Work Area instead of filling the header line
Avoid unnecessary MOVEs by using the explicit work area operations
APPEND wa TO itab.
INSERT wa INTO itab.
COLLECT wa INTO itab.
MODIFY itab FROM wa.
READ TABLE itab INTO wa.
LOOP AT itab INTO wa.
where appropriate.
Linear Search VS Binary Search
If internal tables are assumed to have many (>20) entries, a linear search through all entries is very time-consuming. Try to keep the table ordered and use binary search or used a table of type SORTED TABLE. If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
Dynamic Vs Static Key access
A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime. However, for large tables the costs are dominated by number of comparison needed to locate the entry.
Creating a Secondary Index to avoid Linear Search
If you need to access an internal table with different keys repeatedly, keep your own secondary indices.With a secondary index, you can replace a linear search with a binary search plus an index access.
Key Access to multiple Lines Loop/Check VS Loop...Where
LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally. As with any logical expressions, the performance is better if the operands of a comparison share a common type. The performance can be further enhanced if LOOP ... WHERE is combined with FROM i1 and/or TO i2, if possible.
Single READ access on unique sorted Vs. hashed Tables
Entries in a sorted table are located by binary search. The costs depend on the number of entries in the table (O (log n)). Entries in a hashed table are located by an internal hash-algorithm The costs are constant (O (1)), i.e. they do not depend on the table size. Hashed tables are optimized for single entry access.
Partial Sequential Access: Sorted Vs. hashed Tables
Hashed tables are optimized for single entry access. The entries have no specific order. Therefore, a partial sequential access cannot be optimized. Every entry must be checked to match the condition (full table scan). Sorted tables are ordered ascendingly by their key components. If a partial key of the form "k1 = v1 AND ... AND kn = vn" where k1 .. kn
No comments:
Post a Comment