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

request on Native SQL Insert statement

Dear All,

Good morning and Happy Valentines day.

By using Native SQL statement.

I want to insert a record into my table.

the values which are to be inserted, I have to get from other table.

Can anyone help me on this.

Thanks in advance.

Regards,

Manoj.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 14, 2007 at 06:13 AM

    Use this code:

    DATA: GT_T2 TYPE TABLE OF <TABLE2>,
          GT_T1 TYPE TABLE OF <TABLE1>.
    
    SELECT * FROM <table2> INTO TABLE gt_t2.
    
    LOOP AT GT_T2.
      MOVE-CORRESPONDING GT_T2 TO GT_T1.
      APPEND GT_T1.
    ENDLOOP.
    
    INSERT <table1> FROM TABLE gt_t1.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 14, 2007 at 06:14 AM

    Hi,

    check this example

    EXEC SQL.

    INSERT INTO AVERI_CLNT (CLIENT, ARG1, ARG2, ARG3)

    VALUES ('000', 9, 2, 47)

    ENDEXEC.

    reward points if it helps

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Can anyone help me to insert records into another database using native sql

      I already know about this query of using native sql to insert one record, but i need to do almost 100 records

      EXEC SQL.

      INSERT INTO AVERI_CLNT (CLIENT, ARG1, ARG2, ARG3)

      VALUES ('000', 9, 2, 47)

      ENDEXEC.

  • author's profile photo Former Member
    Former Member
    Posted on Feb 14, 2007 at 01:38 PM

    Hi,

    Native SQL allows you to perform operations on databases over and above those in the Open SQL command set. In contrast to Open SQL, Native SQL supports not only operations on the local database active in the R/3 System, but also on any external databases.

    Native SQL comprises all the static statements of the data definition language (DDL) and the data manipulation language (DML) used by the relational database system concerned.

    In an ABAP/4 program, a Native SQL command must be introduced by EXEC SQL and concluded by ENDEXEC. To execute a Native SQL command, the database table does not have to be declared in the ABAP/4 Dictionary.

    EXEC SQL.

    INSERT INTO <TABLENAME> (<FIELD1>, <FIELD2>, <FIELD3>)

    VALUES (<VALUE1>,<VALUE3><VALUE3>)

    ENDEXEC.

    Regards,

    Sruthi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 12, 2007 at 06:48 AM
    "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:

    EXEC SQL [PERFORMING <form>].
      <Native SQL statement>
    ENDEXEC

    .

    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.

    If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.

    As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.

    REPORT Zdemo_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.

    The system displays the following information:

    The program uses the work area WA and the field C1 in the Native SQL SELECT statement. WA is the target area into which the selected data is written. The structure WA in the INTO clause is treated as though its components were all listed individually. INTO :WA-CONNID, :WA-CITYFROM, :WA-CITYTO. C1 is used in the WHERE clause. The subroutine LOOP_OUTPUT writes the data from WA to the screen.

    Reward points if it is usefull ...

    Girish

    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.