0% found this document useful (0 votes)
4 views3 pages

26 - SAP ABAP - Native SQL Overview

Native SQL in SAP ABAP allows the use of database-specific SQL statements that are executed directly without following ABAP syntax. These statements are enclosed between EXEC SQL and ENDEXEC, enabling the use of the full SQL language of the database. An example demonstrates how to retrieve data from the SPFLI table using Native SQL within an ABAP program.

Uploaded by

akhter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

26 - SAP ABAP - Native SQL Overview

Native SQL in SAP ABAP allows the use of database-specific SQL statements that are executed directly without following ABAP syntax. These statements are enclosed between EXEC SQL and ENDEXEC, enabling the use of the full SQL language of the database. An example demonstrates how to retrieve data from the SPFLI table using Native SQL within an ABAP program.

Uploaded by

akhter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Page 1 of 3

SAP ABAP - Native SQL Overview


The term ‘Native SQL’ refers to all statements that can be statically transferred to the
Native SQL interface of the database interface. Native SQL statements do not fall within
the language scope of ABAP and do not follow the ABAP syntax. ABAP merely contains
statements for isolating program sections in which Native SQL statements can be listed.

In native SQL, mainly database-specific SQL statements can be used. These are
transferred unchanged from the native SQL interface to a database system and
executed. The full SQL language scope of the relevant database can be used and the
addressed database tables do not have to be declared in the ABAP Dictionary. There is
also a small set of SAP specific Native SQL statements that are handled in a specific way
by the native SQL interface.

To use a Native SQL statement, you have to precede it with the EXEC SQL statement and
end with ENDEXEC statement.

https://www.tutorialspoint.com/sap_abap/sap_abap_native_sql_overview.htm 1/3
Page 2 of 3

Following is the syntax −

EXEC SQL PERFORMING <form>.


<Native SQL statement>
ENDEXEC.

These statements define an area in an ABAP program where one or more Native SQL
statements can be listed. The statements entered are passed to the Native SQL interface
and then processed as follows −

All SQL statements that are valid for the program interface of the addressed
database system can be listed between EXEC and ENDEXEC, in particular the DDL
(data definition language) statements.

These SQL statements are passed from the Native SQL interface to the database
system largely unchanged. The syntax rules are specified by the database
system, especially the case sensitivity rules for database objects.

If the syntax allows a separator between individual statements, you may include
many Native SQL statements between EXEC and ENDEXEC.
SAP specific Native SQL language elements can be specified between EXEC and
ENDEXEC. These statements are not passed directly from the Native SQL
interface to the database, but they are transformed appropriately.

Example
SPFLI is a standard SAP Table that is used to store Flight schedule information. This is
available within R/3 SAP systems depending on the version and release level. You can
view this information when you enter the Table name SPFLI into the relevant SAP
transaction such as SE11 or SE80. You can also view the data contained in this database
table by using these two transactions.

REPORT ZDEMONATIVE_SQL.
DATA: BEGIN OF wa,
connid TYPE SPFLI-connid,
cityfrom TYPE SPFLI-cityfrom,
cityto TYPE SPFLI-cityto,
END OF wa.

DATA c1 TYPE SPFLI-carrid VALUE 'LH'.


EXEC SQL PERFORMING loop_output.
SELECT connid, cityfrom, cityto
INTO :wa
FROM SPFLI

https://www.tutorialspoint.com/sap_abap/sap_abap_native_sql_overview.htm 2/3
Page 3 of 3

WHERE carrid = :c1


ENDEXEC.

FORM loop_output.
WRITE: / wa-connid, wa-cityfrom, wa-cityto.
ENDFORM.

The above code produces the following output −

0400 FRANKFURT NEW YORK


2402 FRANKFURT BERLIN
0402 FRANKFURT NEW YORK

https://www.tutorialspoint.com/sap_abap/sap_abap_native_sql_overview.htm 3/3

You might also like