Professional Documents
Culture Documents
SQL INTERFACE
Select where VS Select + Check
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
ENDSELECT.
VS
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
SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
WHERE CARRID = 'LH'
AND CONNID = '0400'.
ENDSELECT.
VS
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.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
ABAPLOVERS ABAP TIPS AND TRICKS
SQL INTERFACE
Select Single VS Select-Endselect
SELECT * FROM SBOOK INTO SBOOK_WA
WHERE CARRID = 'LH'.
EXIT.
ENDSELECT.
VS
If you are interested 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.
VS
It is always faster to use the Into Table version of a Select statement than to use Append statements.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
ABAPLOVERS ABAP TIPS AND TRICKS
SQL INTERFACE
Select aggregates
C4A = '000'.
SELECT * FROM T100 INTO T100_WA
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100_WA-MSGNR > C4A.
C4A = T100_WA-MSGNR.
ENDSELECT.
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 yourself. Network load is
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.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
ABAPLOVERS ABAP TIPS AND TRICKS
SQL INTERFACE
Select with View
VS
To process a join, use a view instead of nested Select statements. Network load is considerably less.
VS
SELECT * INTO WA
FROM SPFLI AS P INNER JOIN SFLIGHT AS F
ON P~CARRID = F~CARRID AND
P~CONNID = F~CONNID.
ENDSELECT.
To read data from several logically connected tables use a join instead of nested Select statements. Network
load is considerably less.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
ABAPLOVERS ABAP TIPS AND TRICKS
SQL INTERFACE
VS
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.
VS
For all frequently used, read-only tables, try to use SAP buffering. Network load is considerably less.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
ABAPLOVERS ABAP TIPS AND TRICKS
SQL INTERFACE
Array Insert VS Single row Insert
VS
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
SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
SFLIGHT_WA-SEATSOCC =
SFLIGHT_WA-SEATSOCC - 1.
UPDATE SFLIGHT FROM SFLIGHT_WA.
ENDSELECT.
VS
UPDATE SFLIGHT
SET SEATSOCC = SEATSOCC – 1.
Whenever possible, use column updates instead of single-row updates to update your database tables.
Network load is considerably less.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
ABAPLOVERS ABAP TIPS AND TRICKS
SQL INTERFACE
Using Subqueries
VS
Instead of using nested Select loops or FOR ALL ENTRIES it is often possible to use subqueries. Network
load is considerably less.
LOGON TO ABAPLOVERS.BLOGSPOT.COM