Application Development and Automation 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: 
Read only

native sql connect to sql server

Former Member
0 Likes
673

hello everyone!

my r/3 application server is unix os,versio is 620,I want to connect outer sql server,how can I make it?

thanks in advance!

if the suggest is helpfull,point will be rewarded.

2 REPLIES 2
Read only

Former Member
0 Likes
430

Hi,

Write your sql statement within

EXEC SQL.

  • Sql statement

ENDEXEC.

the above statement will directly in your database server. the sql statement should be compatable with your DB.

for more info about native sql, check the below links

[native sql|http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3b8b358411d1829f0000e829fbfe/content.htm]

[Native SQL Example|http://www.sap-img.com/abap/sql-tool-for-abap-yes4sql-both-native-open-sql.htm]

Regards,

Boobalan S

Edited by: Boobalan Suburaj on Aug 6, 2008 6:58 AM

Read only

Former Member
0 Likes
430

hi Bruce,

in R3 we can use SQL statements which are native to particular RDBMS (ie that too execute as it like on their SQL server) we enclose them with

EXEC SQL [PERFORMING subr].

...

ENDEXEC.

Effect

These statements define an area in an ABAP program in which one or more Native SQL statements are to be carried out. The area between EXEC and ENDEXEC is not completely checked by the syntax check. The statements entered there are passed to the Native SQL interface and processed there as follows:

Almost all SQL statements that are valid for the addressed database system can be included between EXEC and ENDEXEC, in particular the DDL 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, in particular the case sensitivity rules for database objects. If the syntax allows a separator character between individual statements, you can include several Native SQL statements between EXEC and ENDEXEC. Generally, the semicolon ( is used as the separator character.

You can also include SAP-specific Native SQL language elements between EXEC and ENDEXEC. These statements are not passed directly from the Native SQL interface to the database, but are converted appropriately. These SAP-specific language elements are::

Host variables

Statements for cursor processing

Database procedure calls

Statements for establishing database connections

All Native SQL statements bypass SAP buffering. Automatic client handling is not performed.

System fields

The statement ENDEXEC sets the system fields sy-subrc and sy-dbcnt. When using the addition PERFORMING, note that implicit cursor processing is carried out and the system fields are set for every read process.

sy-subrc Meaning

0 The statements between EXEC and ENDEXEC were executed successfully.

4 The statements between EXEC and ENDEXEC were not executed. After implicit cursor processing with PERFORMING, sy-subrc always contains the value 4.

The ENDEXEC statement sets sy-dbcnt to the number of table rows processed in the last Native SQL statement. After implicit cursor processing with PERFORMING, sy-dbcnt contains the total number of lines read.

Note

Programs with Native SQL statements are generally dependent on the database system used, so that they cannot be executed in all ABAP systems. This is especially true for the examples in this section, which was written for Informix database systems.

Example

Inserting two rows in the database table SCARR. If neither of these rows exists, sy-subrc is set to 0 by ENDEXEC and sy-dbcnt to 1. Otherwise, an exception is raised and handled.

DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,

error_text TYPE string.

TRY.

EXEC SQL.

INSERT INTO scarr

(MANDT, CARRID, CARRNAME, CURRCODE, URL)

VALUES ('000', 'FF', 'Funny Flyers', 'EUR',

'http://www.ff.com');

INSERT INTO scarr

(MANDT, CARRID, CARRNAME, CURRCODE, URL)

VALUES ('000', 'EF', 'Easy Flyers', 'EUR',

'http://www.ef.com');

ENDEXEC.

CATCH cx_sy_native_sql_error INTO exc_ref.

error_text = exc_ref->get_text( ).

MESSAGE error_text TYPE 'I'.

ENDTRY.

Regards

Raju Mummidi