Querying using Native SQL

Hi Pals,
I have a requirement which I would like to brief.
I have an internal table with columns FIELD1 and FIELD2. For all the values in FIELD1 I have to query a table MSI(which does not form a part of the R/3 framework) through Native SQL statement and get the corresponding values for FIELD2.
Could anybody suggest how I must proceed writing my statements between EXEC and ENDEXEC.
Do I have to query the database table for each entry in my internal table or is it possible to use for all entries in my SQL statemnt.
Your inputs would be highly appreciated.
Thank You in advance.
Regards,
Gayathri N.

Hai Gayathri
check this document
EXEC SQL.
Addition
... PERFORMING form
Effect
Executes the Native SQL command enclosed by the statements EXEC SQL and ENDEXEC . In contrast to Open SQL , addressed database tables do not have to be known to the ABAP/4 Dictionary and the ABAP/4 program does not have to contain appropriate TABLES statements.
Example
Create the table AVERI_CLNT :
EXEC SQL.
  CREATE TABLE AVERI_CLNT (
         CLIENT   CHAR(3)  NOT NULL,
         ARG1     CHAR(3)  NOT NULL,
         ARG2     CHAR(3)  NOT NULL,
         FUNCTION CHAR(10) NOT NULL,
         PRIMARY KEY (CLIENT, ARG1, ARG2)
ENDEXEC.
With Native SQL commands, passing data between an ABAP/4 program and the database is achieved using host variables . A host variable is an ABAP/4 variable prefixed by a "*" in the Native SQL statement.
Example
Display a section of the table AVERI_CLNT :
DATA: F1(3), F2(3), F3(3).
F3 = ' 1 '
EXEC SQL.
  SELECT CLIENT, ARG1 INTO :F1, :F2 FROM AVERI_CLNT
         WHERE ARG2 = :F3
ENDEXEC.
WRITE: / F1, F2.
To simplify the spelling of INTO lists in the SELECT command, you can specify a single structure as the target area as in Open SQL .
Example
Display a section of the table AVERI_CLNT :
DATA: BEGIN OF WA,
        CLIENT(3), ARG1(3), ARG2(3),
      END OF WA.
DATA  F3(3).
F3 = ' 1 '
EXEC SQL.
  SELECT CLIENT, ARG1 INTO :WA FROM AVERI_CLNT
         WHERE ARG2 = :F3
ENDEXEC.
WRITE: / WA-CLIENT, WA-ARG1.
Notes
In contrast to Open SQL , a client field in Native SQL is a field like any other and must be specified explicitly in calls.
Authorization checks cannot be properly realized in EXEC SQL . You should perform these in the program.
When you start the R/3 System, a CONNECT to the current database is executed automatically. An explicit CONNECT is unnecessary.
A Native SQL command can (but does not have to) end with a ";". Under no circumstances should it end with a ".".
Some database systems allow upper and lower case in table names and field names. If you want to take advantage of this, you must ensure that the spelling of names is correct. To enable entry of lower case letters in names in the ABAP/4 editor, you must set the attribute for upper/lower case in the report.
Since there are no arrays in ABAP/4 , array operations are not possible in Native SQL . If the result of a SELECT command is a table, you can read this table line by line either with the Native SQL command FETCH or with the addition ... PERFORMING form .
Unlike in ABAP/4 programs, the character " in a Native SQL statement does not introduce a comment until the end of the editor line.
Addition
... PERFORMING form
Effect
If the result of a SELECT command is a table, you can read this table line by line in a processing loop. The subroutine form is called once for each line. In this subroutine, you can leave the loop by using EXIT FROM SQL . If the result of the selection is a single record, the subroutine is called only once.
Example
Display a section of the table AVERI_CLNT :
DATA: F1(3), F2(3), F3(3).
F3 = ' 1 '
EXEC SQL PERFORMING WRITE_AVERI_CLNT.
  SELECT CLIENT, ARG1 INTO :F1, :F2 FROM AVERI_CLNT
         WHERE ARG2 = :F3
ENDEXEC.
FORM WRITE_AVERI_CLNT.
  WRITE: / F1, F2.
ENDFORM.
Note
This addition is allowed only with a SELECT command.
Related SELECT , INSERT , UPDATE , MODIFY , DELETE , OPEN CURSOR , FETCH , CLOSE CURSOR, COMMIT WORK and ROLLBACK WORK .
go to se38
type 'EXEC' and put cursor on 'EXEC' press f1-function key
then you get help for EXEC
Thanks & regards
Sreenivasulu P
Message was edited by: Sreenivasulu Ponnadi

Similar Messages

  • How to use Native SQL statement in JDBC receiver interface

    Dear All,
    Can any one please help us in using Native SQL statement in a JDBC receiver channel. The reason why I need to use Native SQL statement instead of standard XML structure is that I need to execute a dynamic SQL query in third party database system lke:-
    Select Field1 Field2 from TABLE Where Field3 like "%Name'
    I expect the the response in the form of XML file which I can pick up using synchornous interface as mentioned on help.sap.com:-
    http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    The value for %Name can change dynamically according to the transaction and hence cannot be inluded as a KEY element in standard XLM structure,
    Hence I need to know:-
    1. What message mapping I should use in case if I have to use Native SQL statement.
    2.What operation mapping I should use in case if I have to use Native SQL statement.
    If guess correclty I may have to use Java mapping to do the above activities. Hence I want to know
    3 .How do to go about it to do the Java mapping.
    Thanks
    Ameet

    >
    Ameet Deshpande wrote:
    > Dear All,
    >
    > Can any one please help us in using Native SQL statement in a JDBC receiver channel. The reason why I need to use Native SQL statement instead of standard XML structure is that I need to execute a dynamic SQL query in third party database system lke:-
    >
    > "
    > Select Field1 Field2 from TABLE Where Field3 like "%Name'
    > "
    > I expect the the response in the form of XML file which I can pick up using synchornous interface as mentioned on help.sap.com:-
    >
    > http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    > http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    >
    > The value for %Name can change dynamically according to the transaction and hence cannot be inluded as a KEY element in standard XLM structure,
    >
    > Hence I need to know:-
    >
    > 1. What message mapping I should use in case if I have to use Native SQL statement.
    > 2.What operation mapping I should use in case if I have to use Native SQL statement.
    > If guess correclty I may have to use Java mapping to do the above activities. Hence I want to know
    > 3 .How do to go about it to do the Java mapping.
    >
    > Thanks
    > Ameet
    You can use a stored procedure, and call it from jdbc receiver adapter.
    I also solve this issue, with a DBLookup in message mapping. You can refer to my blog, and this usefull 3d:
    http://simonlesflex.wordpress.com/2010/12/07/pi-oracle-dblookup/
    /people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer
    /people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler

  • Query Regarding Native SQL

    Hello Friends,
       I am having a requirement to fetch the records from 3 tables( Using inner join)
       into an internal table but I am facing a difficulty that I need to fetch the records from this table with entirely different conditions and I need to use ' UNION ALL' Command to fetch the records from the database. For Eg.
    I have to write two select statement....
    Select <f1> <f2> <f3> <f4>
    from <t1> join <t2> join <t3>
    into table ITAB
    where <Cond. 1>
    Select <f1> <f2> <f3> <f4>
    from <t1> join <t2> join <t3>
    appending table ITAB
    where <Cond. 2>
    But this is taking two much time... So the user told me to use native SQL to combine this two statement with UNION ALL.. I am using database DB2 Can anyone help me regarding this.
    Thanks,
    Navneet

    HI,
    Info in help is good to understand better. Below is the
    same for you understanding.
    ... FROM tabref1 [INNER] JOIN tabref2 ON cond
    Effect
    The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
    In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
    Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Inner Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
    Note
    In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
    Example
    Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID
    WHERE FCONNID = PCONNID
    AND P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    Note
    Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
    Only a table or view may appear to the right of the JOIN operator, not another join expression.
    Only AND is possible in the ON condition as a logical operator.
    Each comparison in the ON condition must contain a field from the right-hand table.
    If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
    Note
    In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
    Variant 3
    ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
    Effect
    Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
    In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
    Left outer join between table 1 and table 2 where column D in both tables set the join condition:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Left Outer Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a3
    b3
    c3
    2
    NULL
    NULL
    NULL
    NULL
    NULL
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all custimers with their bookings for October 15th, 2001:
    DATA: CUSTOMER TYPE SCUSTOM,
    BOOKING TYPE SBOOK.
    SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
    SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
    INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID)
    FROM SCUSTOM LEFT OUTER JOIN SBOOK
    ON SCUSTOMID = SBOOKCUSTOMID AND
    SBOOK~FLDATE = '20011015'
    ORDER BY SCUSTOMNAME SBOOKFLDATE.
    WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
    Note
    For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
    Only a table or view may come after the JOIN operator, not another join statement.
    The only logical operator allowed in the ON condition is AND.
    Each comparison in the ON condition must contain a field from the right-hand table.
    Comparisons in the WHERE condition must not contain a field from the right-hand table.
    The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
    Note
    In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
    Example
    Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
    DATA: BEGIN OF WA,
    FLIGHT TYPE SFLIGHT,
    PFLI TYPE SPFLI,
    CARR TYPE SCARR,
    END OF WA.
    SELECT * INTO WA
    FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID )
    INNER JOIN SCARR AS C
    ON FCARRID = CCARRID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
    WA-FLIGHT-CONNID.
    ENDSELECT.
    Kishore.

  • How I can create dynamically-formed requests or use native SQL in EJB?

    Hi all.
    I'm working around modify an example from NetWeaver Developer Studio (CarRental). I want to get ordered data from table and allow users to specify the ordering field, not in the code. EJB QL doesn't support dynamically-formed queries like "select object(b) from QuickBooking b where b.status like ?1 order by b.<b>?2</b>" so i can't passing field name as parameter into query. Creating a sorting method for every field is not good solution because I need a dynamically-formed requests.
    I think using native SQL will help but I don't know how I can use SQL in EJB.
    Thanks,
    Lev

    import javax.persistence.EntityManager;within class, place
    protected EntityManager  entityManager;of course make it public, private, whatever you need.
    Then, in your method
    entityManager.createNativeQuery(....);R. Grimes

  • What is native sql when i use native sql

    what is native sql & when i use native sql plz give with me example

    I imagine you mean Native Dynamic SQL, NDS. An example would be:
    EXECUTE IMMEDIATE 'select count(*) from ' || v_tablename INTO v_count;
    i.e. you construct the SQL "dynamically" as a string and then execute it.
    You would use it in situations where you could not know the precise query when building the code - e.g. as above, if you don't know which table to count the rows from until run time.

  • Using Native SQL in ABAP for DB2 database

    Dear Friends,
           I have 500K records in ITAB(Internal table) which needs to insert in 'Z' transparent table. Currently it is taking hours of time for insertion and commit. 
    Does using Native SQL helps in performance or any suggestions? If so please send the code. Our database is DB2.
    Your immediate reply is appreciated. Thanks in advance.

    Hi Rama,
    Using array inserts and commit after each Insert, set up your array size as a parameter and try  different array sizes.
    I would start with 2000 and increment by 1000 or 2000 and see what the optimal array size is.
    I would think more commits are desirable, as the array gets bigger it takes longer for the system to prepare in the event of a rollback.
    Just remember to commit after each insert. And are you enqueueing the table first?
    Hope this helps.
    Filler

  • How to use Native SQL String

    Hi all,
    How do i use Native SQL String in the Reciver JDBC Adapter.
    Do i need to change the message format could u suggest me some blogs on the same.
    Also please can anyone let me knw if i can use this for stored procedure.

    hi aditya,
    there shud be no format as such. for sql xml format there are specific structure. but for native sql there shudnt be any specific structure.
    as pointed in sap documentaion:
    Instead of an XML document format, a text is expected that represents any valid SQL statement.
    When inserting a line into a table the corresponding document looks as follows:
    INSERT INTO tableName  (column-name1, column-name2, column-name3) VALUES(‘column-value1’, ‘column-value2’, ‘column-value3’)
    so jus make sure that u give a valid sql statement becoz if will be passed as it is to the database and try ur scenario.
    regards,
    latika.

  • # coming when I select data from oracle table using Native SQL

    Hi Gurus,
    I am selecting 'First name' from oracle table directly using native sql. I am fetching 65000 records but 10+ records having '#' at the end of firstname. For eg: John#.
    But oracle team couldn't find '#' in their table for those records. What could be problem?
    or what could be the character in oracle which comes as '#' in abap?
    Pls help...
    Saj

    Thanks for replies.
    My DB NLS_PARAMETER is AL32UTF8. I am able to pullout data with older version of ojdbc jar file. So I think there is no issue regarding NLS setting.
    So please guide me with proper solution as soon as possible.

  • Insert / Update of a TIME field using Native SQL

    Hi Oracle gurus,
    We are trying to perform inserts and updates within an ORACLE table where a TIME field exists without suscess. We are trying to code it using Native SQL.
    EXEC SQL.
    INSERT INTO table (field1[name], field2[age], field3[birthday], field4[hour])
    VALUES (:name, :age, TO_DATE(:date_birth), ¿:hour?)
    ENDEXEC.
    EXEC SQL.
    UPDATE table SET field3[birthday] = TO_DATE(:date_birth), field4[hour] = ¿:hour?
    WHERE field1[name] = :name AND field2[age] = :age
    ENDEXEC.
    Which is the right coding sentence in order to achieve our goal?
    Many thanks in advance. Best regards,
       Imanol

    Hi
    There is no TIME datatype in oracle. There is only a TIMESTAMP or DATE type or the field is VARCHAR2 as most date fields in a SAP database are. To help you we would need the real field type. If possible you please do a desc <owner>.<table> in a sqlplus session and give us the field type.
    If possible also supply the error you get.
    Regards, Michael

  • How to get oracle 9i blob column into an itab  in sap using Native SQL

    Hi ,
    We are using SAP ECC 5.0  and we need to coonect to an oracle database ver 9i rel2.
    We need to get the data stored in a blob(pdf/jpeg) into an itab and later
    use it for futher processing.
    I am familiar with using native SQL and I wrote a stored procedure in the non sap oracle database to send the blob info into an internal table in sap.
    But the information is in hex format and the long raw of SAP does not handle this very well.
    Plz see my code below.
    data: itab_insp_drawing like zpicture_cluster(which is of type lraw - 7902 )
          occurs 100 with header line.
    EXEC SQL.
        EXECUTE PROCEDURE
           proc_get_insp_drawings  (
                   IN  :itab-aq_id,
                   IN  :itab-section_id,
                   IN  :t_in_position,
                   out :itab_insp_drawing-picture,
                   OUT :t_blob_length,
                   out :t_out_position,
                   OUT :t_status  )
       ENDEXEC.
      append itab_insp_drawing.
      while t_out_position < t_blob_length.
       EXEC SQL.
        EXECUTE PROCEDURE
           proc_get_insp_drawings  (
                   IN  :itab-aq_id,
                   IN  :itab-section_id,
                   IN  :t_in_position,
                   out :itab_insp_drawing-picture,
                   OUT :t_blob_length,
                   out :t_out_position,
                   OUT :t_status  )
       ENDEXEC.
       append itab_insp_drawing.
       endwhile.
    Any ideas of how to handle blobs from non sap oracle table. I need this blob into an itab in sap.
    Help appreciated.
    Thanks
    Mala

    Please refer the example in this link which deals with Oracle date format.
    You can finnd a command DECODE which is used for date formats. If you have a look at whole theory then you will get an idea.
    Link:[Bulk insert SQL command to transfer data from SAP to Oracle|http://sap.ittoolbox.com/groups/technical-functional/sap-dev/bulk-insert-sql-command-to-transfer-data-from-sap-to-oracle-cl_sql_connection-3780804]

  • Who to use Native SQL statements in ABAP

    hi all,
    who to use native sql staements in abap bypassing Application server.
    with regards,
    suresh babu aluri.

    Hi
    Native SQL 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.
    All Native SQL statements bypass SAP buffering.
    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.
    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.
    Reward points if useful
    Regards
    Anji

  • Using native sql for update

    Hello ,
    I have a reqaust to update a db table declared "outside" our R3 db.
    I mennage to select the data using native sql with a connection to the db.
    Now i need to modify the data on the db.
    Is there a similliar command like "fetch next" ' for update?
    Mybe i need to build a procedure in th "host" db and use its own commands to update?
    Thanks,
    koby

    Hello Kobi,
    Which release of SAP are you woking on?
    If you're on ECC6.0, instead you using Native SQL to call the stored procs of external DBs you can use the [ADBC APIs |http://help.sap.com/abapdocu_702/en/abenadbc_procedure.htm](CL_SQL* classes).
    BR,
    Suhas

  • Insertion / Update of field of type "TIME" using Native SQL

    Hi ABAP gurus,
    We are trying to perform inserts and updates within an ORACLE table where a TIME field exists without suscess. We are trying to code it using Native SQL.
    EXEC SQL.
    INSERT INTO table (field1[name], field2[age], field3[birthday], field4[hour])
    VALUES (:name, :age, TO_DATE(:date_birth), ¿:hour?)
    ENDEXEC.
    EXEC SQL.
    UPDATE table SET field3[birthday] = TO_DATE(:date_birth), field4[hour] = ¿:hour?
    WHERE field1[name] = :name AND field2[age] = :age
    ENDEXEC.
    Which is the right coding sentence in order to achieve our goal?
    Many thanks in advance. Best regards,
       Imanol

    >
    Imanol Beguiristain wrote:
    > Hi all,
    >
    > I am sorry for being unclear.
    >
    > I do want to code both INSERT and UPDATE. That is clear.
    >
    > The problem we are having is that we don't know how to code (using Native SQL) such instructions using in the SQL sentence a field of TIME type.
    >
    > Any helps?
    >
    > Thanks in advance.
    >
    >   Imanol
    I've not heard of an Oracle TIME datatype; we used to use the timestamp which is stored as part of the date or we set up a separate column to hold the time defined as CHAR.  Still, it is possible that they have created such a thing since I last did SQL.  In which case, there would have to be a function like TO_DATE which you would use to convert your time to its time format.
    If you mean TIMESTAMP you can use something like the following to do the data conversion.
    TO_TIMESTAMP(LOCALTIMESTAMP, 'DD-MON-RR HH.MI.SSXFF')

  • Performance issue using Native SQL

    Hi
        I am getting the data from Oracle database using Native SQL in ABAP. I am facing performance problem when i am using Native SQL to get data from Oracle database.Its been very slow and getting timed out.
    This is the code i am using for this.
    EXEC SQL PERFORMING BUILD_TAB.
    Get the territory id
        SELECT TERR_ID
          FROM DWPROD.VW_ARDETAIL_PRD1@DWP
          INTO :IT_TERR-TERR_ID
               :DG_TERR_ID
         WHERE COMPANY     = :dt_output-bukrs
           AND PAY_ADDR_ID = :dt_output-kunnr
           AND DOC_NO      = :dt_output-belnr
           AND DOC_ITEM_NO = :dt_output-buzei
      ENDEXEC.
      IF sy-dbcnt >= 1.
        READ TABLE it_terr INDEX 1.
        dg_terr_id = it_terr-terr_id.
        EXEC SQL.
    Get the Saled rep id, name
          SELECT MR_USER_ID,
                 MR_NAME
            FROM DWPROD.VW_TERR@DWP
            INTO :dt_output-srep_id,
                 :dt_output-srep_name
           WHERE TERR_ID = :DG_TERR_ID
        ENDEXEC.
    *Get sales manager id and sales manager name
        EXEC SQL.
          SELECT SALES_GRP_ID
            FROM DWPROD.VW_TERRRPT@DWP
            INTO :DG_SGRPID
           WHERE TERR_ID = :DG_TERR_ID
        ENDEXEC.
        IF sy-dbcnt >= 1.
          EXEC SQL.
            SELECT MGR_USER_ID,
                   MGR_NAME
              FROM DWPROD.VW_SGRP@DWP
              INTO :dt_output-sman_id,
                   :dt_output-sman_name
             WHERE SALES_GRP_ID = :DG_SGRPID
          ENDEXEC.
        ENDIF.
      ENDIF.
    Can any one suggest a solution to improve the performance.
    Thnaks
    Vianney

    Hi John!
    Looks like you need just one entry out of the tables, but you select 'into table'.
    Try to add a 'up to 1 rows' restriction, then Oracle will be much faster with the execution.
    To get an idea, who this parameter looks like in native SQL for Oracle, write a simple test program with an open SQL statement (including this parameter / select single) and run a SQL-trace (ST05). Here you can see in 'explain' how native translation looks like, can also maintain some small tests with 'enter SQL statement'.
    Regards,
    Christian

  • Program using Native SQL ... Need suggestion.. Look into code

    Hi Friends ,
    I need your Inputs to solve the new requirement , which need to be solve using Native SQL,
    For this i need to connet to data base 'SIP'.
    The table used for this  are SAPI.TRANSACTION
    fields in SAPI.TRANSACTION
             -  SYSTEMCODE
             - BATCH_ID
         and more
    the above two fields are selection parameters based on which i need to get data :
    please rectify the code and also  help me in this
      TRY.
          EXEC SQL.
            CONNECT TO :'SIP'
          ENDEXEC.
          IF sy-subrc NE 0.
    Error Message
          ENDIF.
          EXEC SQL.
            OPEN dbcur FOR
              SELECT SYSTEM CODE   BATCH_ID
                     FROM SAPI.TRANSACTION
    can i use where condition here , i tried to put the selection parameters here
    and tried to put the internal table , but the programs gets terminated,
    How should i get the fields from table SAPI.TRANSACTION
           IF sy-subrc <> 0.
           RAISE EXCEPTION TYPE cx_sy_native_sql_error.
           ENDIF.
          ENDEXEC.
    DO.
      EXEC SQL.
          FETCH NEXT dbcur INTO :BATCH_ID
    Here i want to get batch id and delete data from other table SAPI.BATCH
      ENDEXEC.
      IF sy-subrc <> 0.
        EXIT.
      ELSE.
      ENDIF.
    ENDDO.
          EXEC SQL.
            CLOSE dbcur
          ENDEXEC.
          EXEC SQL.
            DISCONNECT :'SIP'
          ENDEXEC.
      ENDTRY.

    Hi Anirban, I tried that and it still gives the same error:
    - "itab_mytable" cannot be a table, a reference, a string, or contain any of these objects. any of these objects"
    itab_mytable has been declare as an internal table.
    Basically, from the code in the link you gave me, I have made the following changes:
    REPORT demo_native_sql.
    TYPES: BEGIN OF st,
            connid   TYPE spfli-connid,
            cityfrom TYPE spfli-cityfrom,
            cityto   TYPE spfli-cityto,
          END OF st.
    DATA: itab_mytable TYPE TABLE OF st.
    <...>
    EXEC SQL.
      SELECT connid, cityfrom, cityto
      INTO   :itab_mytable
      FROM   spfli
    ENDEXEC.
    But this doesn't work. If the internal table is replaced with a one-lined work area, then the select statement works.

Maybe you are looking for

  • Errors occur during executing consistency checks

    Hi all, During my phase"executing consistency checks", errors occur : X_STXH| Sender structure S_STXB is not assigned to the receiver structure R_STXB. It happened in PC001_PCL_CHECK sub-activity. The details as follows: ubactivity PC001_PCL_CHECK wa

  • Ai CS6 crashes unexpectedly

    Ai CS6 crashes for no reason, no warning. All of a sudden out of nowhere Ai freezes and I get the Windows dialogue window alerting that the program is unresponsive and must close. This has been going on since the install and is very very annoying. I

  • Camera edit won't crop bug

    what is the fix for the now infamous CROP bug on iPhone photos? the crop simply doesn't work correctly anymore on iOS 8. I'm an artist and photoshop expert who takes 1000 shots a month. I mostly save abstract artworks to the camera roll not pretty la

  • Can you populate popups depending on what previous selections you made?

    Im not sure if this is in the correct forum but is it possible but can you make popups populate depending on a previous popup selection? As an example if you have a popup with 2 selections 10 and 20 could you have a second popup display either select

  • Faults with document style operation

    I am getting the following error when attempting to generate stubs from my WSDL: warning: ignoring fault "TestError" of document-style operation "testOperationWithFault" Are faults not supported for document-style operations or is my WSDL incorrect.