Skip to Content
author's profile photo Former Member
Former Member

Dynamic native SQL Insert Statement

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 03:55 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.