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

QUERY FOR INSERT INTO SQL TABLE

former_member190312
Active Participant
0 Likes
598

Hi all,

i want to insert some records into SQL table but not SAP database table. This table is only present in SQL database &

not present in SAP database.

i want to write a program in SAP to update the SQL table(not present in SAP database). is it possible?

if yes, plz give me the query for inserting records into SQL table.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
534

Hi,

you want to work with an internal table, right?

Or where is the other table you want to update?

Regards

Nicole

3 REPLIES 3
Read only

Former Member
0 Likes
535

Hi,

you want to work with an internal table, right?

Or where is the other table you want to update?

Regards

Nicole

Read only

0 Likes
534

Thanks yar.

other table is present in SQL database but not in SAP database.

Read only

0 Likes
534

Hello,

working on the same issue:

Try this:

*----


DATA : Begin Of XY Occurs 1000,

id(15) TYPE C,

Name(50) TYPE C,

ArtNr(50) TYPE C,

lieferant TYPE I,

End Of XY.

*----


*----


  • Fill this internal Table with the SAP-Table

*----


*----


  • START Connection to your Database

EXEC SQL.

Connect TO 'TEST_FH'

ENDEXEC.

IF SY-SUBRC EQ 0.

EXEC SQL.

Set Connection 'TEST_FH' " <-- this is defines with TCode dbco

ENDEXEC.

IF SY-SUBRC EQ 0.

Else.

" OUT_Msg = '... won't connect'.

Exit.

EndIf. " Else IF SY-SUBRC EQ 0

Else.

" OUT_Msg = 'Error at Set Connection Test_FH'.

Exit.

EndIf. " IF SY-SUBRC EQ 0

  • ENDE Connection to your Database

*----


*----


  • START Insert your table XY to an external database

Loop AT XY.

Try.

EXEC SQL.

INSERT INTO stoff

(id, name , artnr, lieferant)

VALUES

( :XY-ID, :XY-Name, :XY-ArtNr, :XY-Lieferant )

ENDEXEC.

COMMIT WORK AND WAIT. " <=== Maybe VERY important

CATCH cx_sy_native_sql_error INTO exc_ref.

error_text = exc_ref->get_text( ).

Concatenate 'Table-INSERT: ' error_text Into error_text.

MESSAGE error_text TYPE 'I'.

ENDTRY.

ENDLoop. " Loop AT XY

  • END Insert your table XY to an external database

*----


*----


  • START: Clear Connection

EXEC SQL.

DISCONNECT 'TEST_FH'

ENDEXEC.

  • END : Clear Connection

*----


Hope it works

Best wishes

Frank