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: 

Dynamic native SQL Insert Statement

Former Member
0 Kudos

Hi,

i will execute/modifiy the following code example to work dynamic. I mean that i want to configure how many fields and which field should be insert in the DB-Table

Samplecode:

LOOP AT vendor_tab INTO vendor_wa.

EXEC SQL.

insert into DatabaseTable.Dummy

(

ve_vendor_no,

ve_name,

ve_country

<b>.......(dynmaic)</b>

)

VALUES

(

:vendor_wa-a-lifnr,

:vendor_wa-a-name1,

:vendor_wa-a-land1

<b>............(dynamic)</b>

)

ENDEXEC.

ADD 1 TO commit_count.

IF commit_count EQ db_comit.

COMMIT WORK AND WAIT.

MOVE 0 TO commit_count.

ENDIF.

ENDLOOP.

If anyone has an idea it will be greatfull.

Thx

Joachim

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi JWR,

Try this: build dynamically the part between the brackets ( ).

Define 2 string fields and concatenate inside what u need to build your SQL statement.

Then u'll have:

data: str1 type string,

str2 type string.

LOOP AT vendor_tab INTO vendor_wa.

  • build strings of fields - u cane move this part any where it suits

concatenate 've_vendor_no' 've_name' 've_country' .......(dynamic) into str1

separated by space.

concatenate ':vendor_wa-a-lifnr' ':vendor_wa-a-name1' ':vendor_wa-a-land1'

............(dynamic) into str2 separated by space.

EXEC SQL.

insert into DatabaseTable.Dummy

(

str1

)

VALUES

(

str2

)

ENDEXEC.

...

...

ENDLOOP.

Good luck

Pls reward if helps

Igal

3 REPLIES 3

Former Member
0 Kudos

Hi JWR,

Try this: build dynamically the part between the brackets ( ).

Define 2 string fields and concatenate inside what u need to build your SQL statement.

Then u'll have:

data: str1 type string,

str2 type string.

LOOP AT vendor_tab INTO vendor_wa.

  • build strings of fields - u cane move this part any where it suits

concatenate 've_vendor_no' 've_name' 've_country' .......(dynamic) into str1

separated by space.

concatenate ':vendor_wa-a-lifnr' ':vendor_wa-a-name1' ':vendor_wa-a-land1'

............(dynamic) into str2 separated by space.

EXEC SQL.

insert into DatabaseTable.Dummy

(

str1

)

VALUES

(

str2

)

ENDEXEC.

...

...

ENDLOOP.

Good luck

Pls reward if helps

Igal

Hello, Joachim!

Could you share the source code for the solution indicated by Igal, please? I did several tests, but all without success. Thank you very much

0 Kudos

Me too. It's not working. It says "Invalid column name 'str2'.