SAP R/3 Document - FAQ: SQL / Performance
SAP R/3 Document - FAQ: SQL / Performance
a) Open SQL.
They are a set of ABAP/4 commands, which perform operation on database tables. The
results of these operations and the associated error messages are independent of database
systems used. Open SQL thus offers a unified SQL syntax and semantics of different
database systems.
To avoid incompatibilities between different database tables and also to make ABAP
programs independent of the database system in use, SAP has created a set of separate
SQL statements called Open SQL. Open SQL contains a subset of standard SQL
statements as well as some enhancements, which are specific to SAP. Using Open SQL
enables you to access any database tables available to the SAP system, regardless of the
manufacturer.
b) Native SQL.
These are database specific SQL statements or the ANSI SQL which all RDBMS
supports..
Syntax
EXEC SQL [PERFORMING <form>].
<Native SQL statement> [;]
ENDEXEC.
Advantage :
1) Tables which are not declared in ABAP dictionary can be accessed. ( e.g.
TABLES belonging to sys or system user of oracle etc.)
2) To use some of the special features supported by the database specific SQL.
(e.g. Passing hints to Oracle optimizer.)
Disadvantage :.
1) No syntax check is performed what ever is written between EXEC &
ENDEXEC.
2) ABAP program containing database-specific SQL statements will not run
under different database systems.
3) There is no automatic client handling for client dependent tables.
4) Care has to be taken during migration to higher versions.
SAP R/3 Document – FAQ SQL / Performance
NOTE :
Ø Note here that the addition INTO CORRESPONDING FIELDS in the INTO clause
of the SELECT statement is only effective for large amounts of data, because the
time required to compare the field names is otherwise too great.
Ø Consider using the DISTINCT option if you are expecting a lot of duplicate table
entries.
Ø Use fewer database accesses
Ø Transfer all of the data at once from the database into internal tables
Ø Where possible, avoid accessing the same data more than once (for example, by
using SELECT before an UPDATE or DELETE statement).
Ø Avoid nested SELECT loops. Instead, use an internal table and a second SELECT
statement with the FOR ALL ENTRIES addition.
Ø In exceptional cases, you can also select data using a separate cursor.
TIPS:
q You can check the performance of your SQL or ABAP functions by using the ‘SQL
Trace’ and ‘Runtime analysis’ utilities.
q For tips on how to improve the performance of ABAP tasks, choose transaction SE30
Definition: The Runtime Analysis tool lets you analyze the performance of any transaction or
program created within the ABAP Workbench. The Runtime Analysis tool creates lists that reveal
expensive statements, summarize table accesses, and show the hierarchy of a program's overall
flow. This information enables you to detect and analyze problems resulting from:
The SQL Trace tool lets you examine the database calls of reports and transactions. This tool
shows you:
Ø the SQL statements that your application uses.
Ø which values the system uses for specific database accesses and changes
Ø how the system translates ABAP OPEN SQL commands (such as SELECT) into standard
SQL commands
SAP R/3 Document – FAQ SQL / Performance
NOTE : Only one user can use the trace tool at a time. So, it is very important to switch off the
tool as soon as the execution is over.
• If the database already contains a line with the same primary key as the line to be
inserted, MODIFY works like UPDATE, i.e. the line is changed.
Note : For performance reasons, you should use MODIFY only if you cannot distinguish
between these two options in your ABAP program.