Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

sql

Former Member
0 Kudos
74

what does exec sql statement do in abap?what is the disadvantage?plzz tell

3 REPLIES 3

former_member583013
Active Contributor
0 Kudos
46

It lets you do native sql that means...That you can manipulate database internal without ABAP clauses...It's disadvantages are that not all database engines works the same...so you can get some nasty results...

Greetings,

Blag.

Kanagaraja_L
Active Contributor
0 Kudos
46

Srinath,

EXEC SQL is the native SQL language that one can use to fetch the data from the database just like the Open SQL statements but we should avoid using them as they are database dependent.

In case of Open SQL,you write the database statements rrespectve of the database installed because the database interface converts the Open SQL commands into Native SQL commands which are database specfic,hence making them database independent and portable which is not possible with Native or EXEC SQL.

EXEC SQL PERFORMING <form>.

<Native SQL statement>

ENDEXEC.

No table logging on SAP level during Native SQL operations

Synchronous match codes are not updated by Native SQL operations

No synchronization of the SAP table buffer

SQL statements become database dependent. This may cause numerous porting problems between database versions

Advantages of Native SQL

Kanagaraja L

Former Member
0 Kudos
46

Hi,

EXEC SQl statement does Native SQL .Normally we use OPEN sql statement.

This is not database specific.So datbase convetor converts into database specific sql statements for our sql statements.This is slow fetching compared to Native sql.

Open SQL allows you to access database tables declared in the ABAP Dictionary regardless of the database platform that you R/3 System is using. Native SQL allows you to use database-specific SQL statements in an ABAP program. This means that you can use database tables that are not administered by the ABAP Dictionary, and therefore integrate data that is not part of the R/3 System.

As a rule, an ABAP program containing database-specific SQL statements will not run under different database systems. If your program will be used on more than one database platform, only use Open SQL statements.

Native SQL Statements in ABAP Programs

To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:

REPORT demo_native_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

WHERE carrid = :c1

ENDEXEC.

FORM loop_output.

WRITE: / wa-connid, wa-cityfrom, wa-cityto.

ENDFORM.

There is no period after 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.

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.

Where as in Native Sql we have to use database specific SQl statements.So we get fast response.

Finally

Native SQL and the Database Interface

Native SQL statements bypass the R/3 database interface. There is no table logging, and no synchronization with the database buffer on the application server. For this reason, you should, wherever possible, use Open SQL to change database tables declared in the ABAP Dictionary. In particular, tables declared in the ABAP Dictionary that contain long columns with the types LCHR or LRAW should only be addressed using Open SQL, since the columns contain extra, database-specific length information for the column. Native SQL does not take this information into account, and may therefore produce incorrect results. Furthermore, Native SQL does not support automatic client handling. Instead, you must treat client fields like any other.

Regds

Parvathi

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Dec 24, 2007 6:58 AM