Open SQL and Native SQL in SAP ABAP PDF
Open SQL and Native SQL in SAP ABAP PDF
(https://www.guru99.com/)
R Programming (/r-
tutorial.html)
1. NATIVE SQL
2. OPEN SQL.
Native SQL allows you to use database-specific SQL statements in an ABAP/4 program. This
means that you can use database tables that are not administered by ABAP dictionary, and
therefore integrate data that is not part of the R/3 system.
Open SQL consists of a set of ABAP statements that perform operations on the central
database in the R/3 system. The results of the operations and any error messages are
independent of the database system in use. Open SQL thus provides a uniform syntax and
semantics for all of the database systems supported by SAP. ABAP programs that only use
Open SQL statements will work in any R/3 system, regardless of the database system in use.
Open SQL statements can only work with database tables that have been been created in
the ABAP dictionary.
https://www.guru99.com/native-open-sql.html 1/9
2/26/2019 Open SQL & Native SQL in SAP ABAP
(https://help.sap.com/static/saphelp_nw70/en/fc/eb3976358411d1829f0000e829fbfe/h-
00100010000_image002.gif)
SELECT
INSERT
UPDATE
MODIFY
DELETE
OPEN CURSOR, FETCH, CLOSE CURSOR
Example
https://www.guru99.com/native-open-sql.html 2/9
2/26/2019 Open SQL & Native SQL in SAP ABAP
TABLES SBOOK.
WA LIKE SBOOK.
OPEN CURSOR C FOR SELECT * FROM SBOOK WHERE CARRID = 'LH '
DO.
IF SY-SUBRC <> 0.
CLOSE CURSOR C.
EXIT.
ENDIF.
WA-INVOICE.
ENDDO.
Output the passenger list for the Lu hansa flight 0400 on 28-02.1995:
SY-SUBRC
New
price drop
https://www.guru99.com/native-open-sql.html 3/9
A er every Open SQL statement, the system
2/26/2019
field SY-SUBRC contains the value 0 if the
Open SQL & Native SQL in SAP ABAP
SY-DBCNT
A er an Open SQL statement, the system field SY-DBCNT contains the number of database
lines processed.
Native SQL
As already mentioned, Native SQL allows you to use database-specific SQL statements in an
ABAP program.
To use Native SQL statement, you must precede it with the EXEC SQL statement, and follow
it with the ENDEXEC statement.
Syntax
ENDEXEC.
There is no period a er Native SQL statements. Furthermore, using inverted commas (") or
an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a
comment as it would in normal ABAP syntax. You need to know whether table and field
names are case-sensitive in your chosen database.
Ad
In Native SQL statements, the data is transported between the database table and the ABAP
program using host variables. These are declared in the ABAP program, and preceded in the
Native SQL statement by a colon (:). You can use elementary structures as host variables.
Exceptionally, structures in an INTO clause are treated as though all of their fields were listed
individually.
As in Open SQL, a er the ENDEXEC statement, SY-DBCNT contains the number of lines
processed. In nearly all cases, SY-SUBRC contains the value 0 a er the ENDEXEC statement.
https://www.guru99.com/native-open-sql.html 4/9
2/26/2019 Open SQL & Native SQL in SAP ABAP
Open SQL - Performance Rules
To improve the performance of the SQL and in turn of the ABAP program, one should take
care of the following rules-
Bu ering
Logical databases
Avoid repeated database access
Next (/all-about-sap-internal-tables.html)
https://www.guru99.com/native-open-sql.html 6/9