Converting Native SQL to OPEN SQL

Any inputs on how the following Native SQL can be converted to OPEN SQL.
Especially self join of same table .
EXEC SQL PERFORMING APPEND_ITAB.
    SELECT /+ ORDERED/
           A.VTYPE,          A.LIFNR,          G.MTNO,
           A.ASYTR,          A.DATAB,          A.DATBI,
           D.MAKTX,          F.NAME1,          G.COMP,
           C.PREF,           C.COMP,           E.MAKTX,
           C.QNTY,           C.UNIT,           B.MEINS,
           A.EKGRP,          A.SEQNO,          C.STGB,
           C.DATUV,          C.DATUB
      INTO :WA_MODULE-VTYPE, :WA_MODULE-LIFNR, :WA_MODULE-MATNR,
           :WA_MODULE-ASYTR, :WA_MODULE-DATAB, :WA_MODULE-DATBI,
           :WA_MODULE-MAKTX, :WA_MODULE-NAME1, :WA_SUB-UPGVC,
           :WA_SUB-PREF,     :WA_SUB-COMP,     :WA_SUB-MAKTX,
           :WA_SUB-QNTY,     :WA_SUB-UNIT,     :WA_SUB-MEINS,
           :WA_MODULE-EKGRP, :WA_MODULE-SEQNO, :WA_SUB-STGB,
           :WA_SUB-DATAB,    :WA_SUB-DATBI
      FROM ZTMM_ASSY_COST1 A, ZTBM_ABXDULDT G,
           ZTBM_ABXDULDT   C, MARA B,  MAKT D,  MAKT E, LFA1 F
     WHERE A.MANDT    =       :SY-MANDT
       AND A.VTYPE    BETWEEN :WA_VTYPE_F AND :WA_VTYPE_T
       AND A.MCODE    BETWEEN :WA_MCODE_F AND :WA_MCODE_T
       AND A.LIFNR    BETWEEN :WA_LIFNR_F AND :WA_LIFNR_T
       AND A.EKGRP    BETWEEN :WA_EKGRP_F AND :WA_EKGRP_T
       AND A.DATAB    <=      :P_DATUM
       AND A.DATBI    >=      :P_DATUM
       AND F.MANDT    =       A.MANDT
       AND F.LIFNR    =       A.LIFNR
       AND G.MANDT    =       A.MANDT
       AND G.MTNO     LIKE    CONCAT(CONCAT(A.VTYPE,A.MCODE),'%')
       AND G.MTNO     BETWEEN :WA_MATNR_F AND :WA_MATNR_T
       AND G.PLNT     =       :C_WERKS
       AND G.USAG     =       '2'
       AND G.ALTN     in      ('1','01')
       AND G.DATUV    <=      :P_DATUM
       AND G.DATUB    >=      :P_DATUM
       AND B.MANDT(+) =       G.MANDT
       AND B.MATNR(+) =       G.MTNO
       AND B.LVORM(+) =       ' '
       AND C.MANDT(+) =       G.MANDT
       AND C.MTNO(+)  =       G.COMP
       AND C.PLNT(+)  =       G.PLNT
       AND C.USAG(+)  =       '2'
       AND C.ALTN(+)  =       '01'
       AND C.DATUV(+) <=      :P_DATUM
       AND C.DATUB(+) >=      :P_DATUM
       AND D.MANDT(+) =       B.MANDT
       AND D.MATNR(+) =       B.MATNR
       AND D.SPRAS(+) =       :SY-LANGU
       AND E.MANDT(+) =       C.MANDT
       AND E.MATNR(+) =       C.COMP
       AND E.SPRAS(+) =       :SY-LANGU
     ORDER BY A.VTYPE, A.LIFNR, G.MTNO
  ENDEXEC.

Then why don't you post the code you have. It would be a lot easier for us to improve that rather than try do redo what you have already done.
Rob

Similar Messages

  • Converting Native SQL to EJB ql

    Hi there
    Simple enough question, how would I go about converting the following native SQL query into EJB QL syntax. This by the way is a simple search on keywords attributed to a person.
    SELECT PersonId, COUNT(word)
    FROM keyword_table
    WHERE word = 'a' OR word = 'c' OR word = 'b'
    GROUP BY PersonId HAVING COUNT(word) <= 3
    ORDER BY COUNT(word) desc
    Note that PersonId is a foreign key joinColumn to a Person entity bean, Ideally i want to be returning person objects through a foreign key in my interest table using GROUP BY etc. I had something like this in mind:
    select Person p FROM Interest i WHERE i.Word = 'a' OR i.Word = 'c' OR i.Word = 'b'
    GROUP BY i.Person.PersonId HAVING COUNT(i.Word) <= 3
    ORDER BY COUNT(i.Word) desc
    Kind Regards
    - Vaughan Cross

    suppose there are two beans "Account" and "Transrecord" with 1-to-m relationship, the mapping table is "ACCOUNT"(PK is ACCID) and "TRANSRECORD"(FK is ACCID)
    The cmr field in Account is "transrecords" and the cmr field in Transrecord is "theAccount".
    For a SQL statement (this statment may be not that meaningful, but it is for testing the function of my translation tool):
    SELECT t.* FROM TRANSRECORD t , ACCOUNT A WHERE a.ACCID = t.ACCID
    >>
    one other way of translation would be
    Select object(t) from account a,transrecord t where a.accid = a.transrecords.accid
    select q1.*
    from TRANSRECORD q1, ACCOUNT q2
    where ( q2.\"ACCID\" IS NOT NULL ) and ( q2.\"ACCID\" = q1.\"ACCID\")");
    Since ACCID is the primary key of ACCOUNT table, so "q2.ACCID IS NOT NULL " is always true, the >>SQL statement is equivalent
    with the oringinal SQL statement.isn't it what is supposed to happen since you cannot have a record in the foreign key table without a corresponding record in the primary key table?
    I tested it in Transrecord bean as a defined EJB-QL in WSAD, the generated SQL statement after the >>deployment is:I am using WSAD 5.1, which file has the converted SQLs?
    sanjay.

  • Convert OpenSQL to Native SQL

    Does someone know of a function module that will accept a SQL statement in OpenSQL format, and convert it to Native SQL (Oracle) format?
    We cannot turn on a trace in our system.
    Thanks.

    Check these threads ...
    Converting OPEN SQL to NATIVE SQL
    Open SQL to Native SQL conversion
    Regards,
    Santosh
    Message was edited by: Santosh Kumar P

  • Performance: Open SQL vs. Native SQL (Oracle)

    Hi everybody,
    I have an interesting issue here. For a DB selection I use an Open SQL query from a table view into an internal table. It works fine, but the performance is not very well. The SELECT uses LIKE and wildcards (%) to search for customer master data (names and address fields).
    Because of the bad performance I made some tests in transaction DB02 with native SQL, but exactly the same SELECT structure. It looks like this:
      SELECT *
        FROM zzrm_cust_s_hlp
       WHERE client = 100
         AND mc_name1      LIKE '<name>%'
         AND mc_name2      LIKE '<name>%'
         AND valid_from    <= <timestamp>
         AND valid_to      >= <timestamp>
    Ok, now I tried exactly the same SELECT statement with the same data to search for (<name> and <timestamp) with Open SQL and Native SQL. The Difference is quite suprising, the Native SQL query is about 5-10 times faster (arount 1 sec) than the Open SQL query (around 5-10 sec). Even with the LIKE keywords and the wildcards.
    Any ideas what could be the problem with the Open SQL query?
    And: what can I do to achive the same performance as with the Native SQL query?
    Kind regards and thanks in advance for any help,
    Matthias

    Ok, here is the the SQL explaination from the DB02 query:
    SELECT STATEMENT ( Estimated Costs = 194 , Estimated #Rows = 1 )
           9 COUNT STOPKEY
             Filter Predicates
               8 NESTED LOOPS
                 ( Estim. Costs = 193 , Estim. #Rows = 1 )
                 Estim. CPU-Costs = 1,665,938 Estim. IO-Costs = 193
                   5 NESTED LOOPS
                     ( Estim. Costs = 144 , Estim. #Rows = 98 )
                     Estim. CPU-Costs = 1,162,148 Estim. IO-Costs = 144
                       2 TABLE ACCESS BY INDEX ROWID BUT000
                         ( Estim. Costs = 51 , Estim. #Rows = 93 )
                         Estim. CPU-Costs = 468,764 Estim. IO-Costs = 51
                         Filter Predicates
                           1 INDEX SKIP SCAN BUT000~NAM
                             ( Estim. Costs = 6 , Estim. #Rows = 93 )
                             Search Columns: 1
                             Estim. CPU-Costs = 59,542 Estim. IO-Costs = 6
                             Access Predicates Filter Predicates
                       4 TABLE ACCESS BY INDEX ROWID BUT020
                         ( Estim. Costs = 1 , Estim. #Rows = 1 )
                         Estim. CPU-Costs = 7,456 Estim. IO-Costs = 1
                         Filter Predicates
                           3 INDEX RANGE SCAN BUT020~0
                             ( Estim. Costs = 1 , Estim. #Rows = 1 )
                             Search Columns: 2
                             Estim. CPU-Costs = 3,661 Estim. IO-Costs = 1
                             Access Predicates
                   7 TABLE ACCESS BY INDEX ROWID ADRC
                     ( Estim. Costs = 1 , Estim. #Rows = 1 )
                     Estim. CPU-Costs = 5,141 Estim. IO-Costs = 1
                     Filter Predicates
                       6 INDEX UNIQUE SCAN ADRC~0
                         Search Columns: 4
                         Estim. CPU-Costs = 525 Estim. IO-Costs = 0
                         Access Predicates
    And this is the one from the Open SQL query in ABAP:
    SELECT STATEMENT ( Estimated Costs = 15,711 , Estimated #Rows = 29 )
           7 NESTED LOOPS
             ( Estim. Costs = 15,710 , Estim. #Rows = 29 )
             Estim. CPU-Costs = 3,021,708,117 Estim. IO-Costs = 15,482
               4 NESTED LOOPS
                 ( Estim. Costs = 15,411 , Estim. #Rows = 598 )
                 Estim. CPU-Costs = 3,018,711,707 Estim. IO-Costs = 15,183
                   1 TABLE ACCESS FULL BUT020
                     ( Estim. Costs = 9,431 , Estim. #Rows = 11,951 )
                     Estim. CPU-Costs = 2,959,067,612 Estim. IO-Costs = 9,207
                     Filter Predicates
                   3 TABLE ACCESS BY INDEX ROWID ADRC
                     ( Estim. Costs = 1 , Estim. #Rows = 1 )
                     Estim. CPU-Costs = 4,991 Estim. IO-Costs = 1
                     Filter Predicates
                       2 INDEX UNIQUE SCAN ADRC~0
                         Search Columns: 4
                         Estim. CPU-Costs = 525 Estim. IO-Costs = 0
                         Access Predicates
               6 TABLE ACCESS BY INDEX ROWID BUT000
                 ( Estim. Costs = 1 , Estim. #Rows = 1 )
                 Estim. CPU-Costs = 5,011 Estim. IO-Costs = 1
                 Filter Predicates
                   5 INDEX UNIQUE SCAN BUT000~0
                     Search Columns: 2
                     Estim. CPU-Costs = 525 Estim. IO-Costs = 0
                     Access Predicates
    Of course I can see the difference.
    But since the statements are identical, I don't understand why this difference exists
    Thanks for your help!
    Kind regards, Matthias

  • CREATE VIEW in ABAP (Open SQL or Native SQL)

    Hi all you experts!
    I want to create a VIEW in ABAP. I have created Table Views using ABAP Dictionary (in transaction SE11), I don't have any problem with them.
    But, what I need is to create a dynamic view, I mean, a view that can be created/replaced (or modified) at runtime. Is this possible with SAP Open SQL, I don't think so... that is why I tried to created using native SQL but it is not working.
    Here is the code:
      EXEC SQL.
        CREATE VIEW [ZMXRFIV_GLPCA]
          AS SELECT
             T1.GL_SIRID,
             T1.POPER,
             T1.RBUKRS,
             T1.RPRCTR,
             T1.RACCT,
             T1.HSL
          FROM
             GLPCA T1
          INNER JOIN
             SKA1 T2
          ON
             T1.RACCT = T2.SAKNR
          WHERE
            T1.RVERS      =  '000'
            AND T1.RYEAR  =  '2008'
            AND T1.KOKRS  =  'PI01'
            AND T2.KTOPL  =  'PI00'
            AND T2.XBILK  <> 'X'.
      ENDEXEC.
    I have tried using quotes (") for the view name, parenthesis and even using only the name but this make no difference.
    Do any of you experts have any idea?
    PS: After creating the view I need to do a SELECT INTO TABLE to that view and finally delete this view and continue working with the data on the internal table.

    Hi ,
    oh yes it is an object (well, how the database should handle it in any context if it wasn't)
    i.e. for ORACLE you would have several thousands of them:
    select count(*) from dba_objects where object_type ='VIEW'
    If you avoid some kind of foreground processing (i.e. pull the data over the network) and handle the processing inside the database it can improve somehow performance a little (i.e. using the retieved rows of the view to stuff into a database table directly). But his may not always possible...
    bye
    yk

  • Open & Native SQL

    Hai all !
      Can anybody give me the exact Difference between Open SQL & Native SQL.
    Thanks in Advance,
    Swapna.

    Hii!
       Open SQL is basically SAP specific Structured Query language.Open SQL consists of a set of ABAP statements that perform operations on the central database in the R/3 System. The results of the operations and any error messages are independent of the database system in use. Open SQL thus provides a uniform syntax and semantics for all of the database systems supported by SAP. ABAP programs that only use Open SQL statements will work in any R/3 System, regardless of the database system in use. Open SQL statements can only work with database tables that have been created in the ABAP Dictionary.
    Native SQL is basically a database specific language.
    Open SQL allows you to access database tables declared in the ABAP Dictionary regardless of the database platform that you R/3 System is using. Native SQL allows you to use database-specific SQL statements in an ABAP program. This means that you can use database tables that are not administered by the ABAP Dictionary, and therefore integrate data that is not part of the R/3 System.
    As a rule, an ABAP program containing database-specific SQL statements will not run under different database systems. If your program will be used on more than one database platform, only use Open SQL statements.
    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.

  • Open an native sql

    1) what is open sql an wat is native sql an wt is the diference between these to.....

    Hi Satish,
    The difference is:
    OPEN SQL - Open SQL consists of a set of ABAP statements that perform operations on the central database in the R/3 System. The results of the operations and any error messages are independent of the database system in use. Open SQL thus provides a uniform syntax and semantics for all of the database systems supported by SAP. ABAP programs that only use Open SQL statements will work in any R/3 System, regardless of the database system in use. Open SQL statements can only work with database tables that have been created in the ABAP Dictionary.
    NATIVE SQL - Open SQL allows you to access database tables declared in the ABAP Dictionary regardless of the database platform that you R/3 System is using. Native SQL allows you to use database-specific SQL statements in an ABAP program. This means that you can use database tables that are not administered by the ABAP Dictionary, and therefore integrate data that is not part of the R/3 System.
    Plz Reward if useful,
    Mahi.

  • Abap sql convert to native sql fuction

    hi expert!
    exist a function can do follow things:
      convert selection-screen's select-options which user key in
         to oracle where condition expression
    or exist one function can convert abap sql to oracle sql
    thank you very much

    example:
      EXEC SQL.
            CONNECT TO :'DATA BASE NAME'
          ENDEXEC.
          IF sy-subrc EQ 0 .
             TRY.
                  EXEC SQL .
                    SELECT COUNT(*) FROM <TABLE NAME>
                    INTO :recount
                    WHERE code = :itab-<FIELD>
                  ENDEXEC .
                CATCH cx_sy_native_sql_error INTO exc_ref.
                  error_text = exc_ref->get_text( ).
                  MESSAGE error_text TYPE 'I'.
              ENDTRY.

  • Native sql DBCO, CONNECT statement short dump

    Hi ALL ,
    I am facing the  problem here.  please help me out in this.
    i am trying to connce to the external database MSS, i made all the entries in the DBCO t-code and writing the follwoing native sql statement.
    EXEC SQL.
    CONNECT TO 'AAJ' AS 'V'
    ENDEXEC.
    EXEC SQL.
    SET CONNECTION 'V'
    ENDEXEC.
    The above statement is not giving any error  when i activate it but when i execute it is giving me shortdump error .
    I already maintan   entries in DBCON table or DBCO t-code
    And also tel me once it is connect how can i access the data from MSS (Microsoft sql server)i mean what kind of statement.
    helpfull answer will be rewarded.
    Anees
    9886358645
    Message was edited by:
            anees jawad

    Native SQL
    Open SQL allows you to access database tables declared in the ABAP Dictionary regardless of the database platform that you R/3 System is using. Native SQL allows you to use database-specific SQL statements in an ABAP program. This means that you can use database tables that are not administered by the ABAP Dictionary, and therefore integrate data that is not part of the R/3 System.
    As a rule, an ABAP program containing database-specific SQL statements will not run under different database systems. If your program will be used on more than one database platform, only use Open SQL statements.
    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  )
    The parameters are separated by commas. You must also specify whether the parameter is for input (IN), output (OUT) or input and output (INOUT). For further information, refer to SAP Note 44977.
    EXEC SQL
       EXECUTE PROCEDURE proc1 ( IN , OUT :y )
    ENDEXEC.
    Cursor Processing
    Cursor processing in Native SQL is similar to that in Open SQL:
    OPEN
      ENDIF.
    ENDDO.
    EXEC SQL.
      CLOSE c1
    ENDEXEC.
    This example opens a cursor, reads data line by line, and closes the cursor again. As in Open SQL, SY-SUBRC indicates whether a line could be read.
    Data Types and Conversions
    Using Native SQL, you can
    Transfer values from ABAP fields to the database
    Read data from the database and process it in ABAP programs.
    Native SQL works without the administrative data about database tables stored in the ABAP Dictionary. Consequently, it cannot perform all of the consistency checks used in Open SQL. This places a larger degree of responsibility on application developers to work with ABAP fields of the correct type. You should always ensure that the ABAP data type and the type of the database column are identical.
    If the database table is not defined in the ABAP Dictionary, you cannot refer directly to its data type. In this case, you should create a uniform type description in the ABAP Dictionary, which can then be used by all application programs.
    If the table is defined in the ABAP Dictionary, you should remember that the sequence of fields in the ABAP Dictionary definition may not be the same as the actual sequence of fields in the database. Using the asterisk (*) in the SELECT clause to read all columns into a corresponding work area would lead to meaningless results. In the worst case, it would cause an error.
    The Native SQL module of the database interface passes a description of the type, size, and memory location of the ABAP fields used to the database system. The relevant database system operations are usually used to access and convert the data. You can find details of these operations in the manuals for the programming interface of the relevant database system. In some cases, Native SQL also performs other compatibility checks.
    The documentation from the various database manufacturers provides detailed lists of combinations of ABAP data types and database column types, both for storing ABAP field values in database tables (INSERT, UPDATE) and for reading database contents into ABAP fields (SELECT). You can also apply these descriptions for the input and output parameters of database procedures. Any combinations not listed there are undefined, and should not be used.
    The following sections provide details of the data types and conversions for individual databases. Although they are database-specific, there are also some common features.
    Recommended type combinations are underlined. Only for these combinations is behavior guaranteed from release to release. For any other combinations, you should assume that the description only applies to the specified release.
    The results of conversions are listed in a results column:
    "OK": The conversion can be performed without loss of data.
    Operations that fail are indicated by their SQL error code. Errors of this kind always lead to program termination and an ABAP short dump.
    In some cases, data is transferred without an SQL error occurring. However, the data is truncated, rounded, or otherwise unusable:
    Right truncation.
    "Left" or "right" applies to the normal way of writing a value. So, for example, if a number is truncated, its decimal places are affected.
    : Left truncation
    : Number is rounded up or down during conversion
    : A number that was "too small" is rounded to 0 (underflow)
    : The conversion result is undefined.
    There are several possible results. The concrete result is either not known at all, or can only be described using a set of rules that is too complicated for practical use.
    : The conversion returns the SQL value NULL.
    : The conversion is performed without fields and unchecked.
    The original data is converted, but without its format being checked. The result may therefore be a value invalid for the result type, which cannot be processed further. An example of this is a date field containing the value "99999999" or "abcdefgh" after conversion.
    Combinations of ABAP data type and database column type can be divided into finer subcategories. Here, for example, using the transfer direction ABAP ® database (INSERT, UPDATE):
    If the width of the ABAP field is greater than that of the database column, the ABAP field may contain values for which there is not enough space in the database column. This can produce other cases: The concrete data value in ABAP finds space in the database column, or not.
    If the ABAP field is at most as long as the database column, there is always space for the ABAP value in the database column.
    Some types, such as numeric columns, expect values in a particular format. This is particularly important in connection with character types, for example, when you want to write an ABAP character field (type C) into an integer column.
    Native SQL for Oracle
    Native SQL for Informix
    Native SQL for DB2 Common Server
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3b8b358411d1829f0000e829fbfe/content.htm

  • Native SQL Regarding

    Hai Experts,
    I need To  Insert Values Into Sql Server Table Using EXEC And ENDEXEC Commands.
    Can Any one Give Some Suggestion.
    <REMOVED BY MODERATOR>
    Thanks In Adv,
    Jai.M
    Edited by: Alvaro Tejada Galindo on Feb 22, 2008 4:38 PM

    Hi,
    EXEC SQl statement does Native SQL .Normally we use OPEN sql statement.
    This is not database specific.So datbase convetor converts into database specific sql statements for our sql statements.This is slow fetching compared to Native sql.
    Open SQL allows you to access database tables declared in the ABAP Dictionary regardless of the database platform that you R/3 System is using. Native SQL allows you to use database-specific SQL statements in an ABAP program. This means that you can use database tables that are not administered by the ABAP Dictionary, and therefore integrate data that is not part of the R/3 System.
    As a rule, an ABAP program containing database-specific SQL statements will not run under different database systems. If your program will be used on more than one database platform, only use Open SQL statements.
    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:
    REPORT demo_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.
    <REMOVED BY MODERATOR>
    Cheers,
    Chandra Sekhar.
    Edited by: Alvaro Tejada Galindo on Feb 22, 2008 4:40 PM

  • What is native sql?

    hi all,
    what is native sql? can any one provide me some examples with native sql? and when do we go for writing prgm in native sql?
    is native sql stms are supported for pool and cluster tables?
    regds
    hari

    Hi Hari,
    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.
    Scope of Native SQL
    Native SQL allows you to execute (nearly) all statements available through the SQL programming interface (usually known as SQL Call Interface or similar) for executing SQL program code directly (using EXEC IMMEDIATE or a similar command). The following sections list the statements that are not supported.
    The parameters are separated by commas. You must also specify whether the parameter is for input (IN), output (OUT) or input and output (INOUT). For further information, refer to SAP Note 44977.
    EXEC SQL
       EXECUTE PROCEDURE proc1 ( IN :x, OUT :y )
    ENDEXEC.
    Cursor Processing
    Cursor processing in Native SQL is similar to that in Open SQL:
    OPEN <cursor name> FOR <statement>
    FETCH NEXT <cursor name> INTO <target(s)>.
    CLOSE <cursor name>
    EXEC SQL
      OPEN c1 FOR
        SELECT client, arg1, arg2 FROM table_001
         WHERE client = '000' AND arg2 = :arg2
    ENDEXEC.
    DO.
      EXEC SQL.
        FETCH NEXT c1 INTO :wa-client, :wa-arg1, :wa-arg2
      ENDEXEC.
      IF sy-subrc <> 0.
        EXIT.
      ELSE.
        <verarbeite Daten>
      ENDIF.
    ENDDO.
    EXEC SQL.
      CLOSE c1
    ENDEXEC.
    This example opens a cursor, reads data line by line, and closes the cursor again. As in Open SQL, SY-SUBRC indicates whether a line could be read.
    Data Types and Conversions
    Using Native SQL, you can
    Transfer values from ABAP fields to the database
    Read data from the database and process it in ABAP programs.
    Native SQL works without the administrative data about database tables stored in the ABAP Dictionary. Consequently, it cannot perform all of the consistency checks used in Open SQL. This places a larger degree of responsibility on application developers to work with ABAP fields of the correct type. You should always ensure that the ABAP data type and the type of the database column are identical.
    If the database table is not defined in the ABAP Dictionary, you cannot refer directly to its data type. In this case, you should create a uniform type description in the ABAP Dictionary, which can then be used by all application programs.
    If the table is defined in the ABAP Dictionary, you should remember that the sequence of fields in the ABAP Dictionary definition may not be the same as the actual sequence of fields in the database. Using the asterisk (*) in the SELECT clause to read all columns into a corresponding work area would lead to meaningless results. In the worst case, it would cause an error.
    The
    Native SQL module of the database interface passes a description of the type, size, and memory location of the ABAP fields used to the database system. The relevant database system operations are usually used to access and convert the data. You can find details of these operations in the manuals for the programming interface of the relevant database system. In some cases, Native SQL also performs other compatibility checks. 
    The documentation from the various database manufacturers provides detailed lists of combinations of ABAP data types and database column types, both for storing ABAP field values in database tables (INSERT, UPDATE) and for reading database contents into ABAP fields (SELECT). You can also apply these descriptions for the input and output parameters of database procedures. Any combinations not listed there are undefined, and should not be used.
    The following sections provide details of the data types and conversions for individual databases. Although they are database-specific, there are also some common features.
    Recommended type combinations are underlined. Only for these combinations is behavior guaranteed from release to release. For any other combinations, you should assume that the description only applies to the specified release.
    The results of conversions are listed in a results column:
    "OK": The conversion can be performed without loss of data.
    Operations that fail are indicated by their SQL error code. Errors of this kind always lead to program termination and an ABAP short dump.
    In some cases, data is transferred without an SQL error occurring. However, the data is truncated, rounded, or otherwise unusable:
    Right truncation.
    "Left" or "right" applies to the normal way of writing a value. So, for example, if a number is truncated, its decimal places are affected.
    : Left truncation
    : Number is rounded up or down during conversion
    : A number that was "too small" is rounded to 0 (underflow)
    : The conversion result is undefined.
    There are several possible results. The concrete result is either not known at all, or can only be described using a set of rules that is too complicated for practical use.
    : The conversion returns the SQL value NULL.
    : The conversion is performed without fields and unchecked.
    The original data is converted, but without its format being checked. The result may therefore be a value invalid for the result type, which cannot be processed further. An example of this is a date field containing the value "99999999" or "abcdefgh" after conversion.
    Combinations of ABAP data type and database column type can be divided into finer subcategories. Here, for example, using the transfer direction ABAP ® database (INSERT, UPDATE):
    If the width of the ABAP field is greater than that of the database column, the ABAP field may contain values for which there is not enough space in the database column. This can produce other cases: The concrete data value in ABAP finds space in the database column, or not.
    If the ABAP field is at most as long as the database column, there is always space for the ABAP value in the database column.
    Some types, such as numeric columns, expect values in a particular format. This is particularly important in connection with character types, for example, when you want to write an ABAP character field (type C) into an integer column.
    Reward pts if found usefull :)
    regards
    Sathish

  • Native SQL "Table does not exist in database"

    Hi Developers,
    I'm doing a database connection to an Oracle db and trying to read data using native SQL - I keep getting the runtime error "table does not exist in database" on the statement Fetch Next Cursor. The following is the code snippet (I've commented out the Exec SQL and Fetch Next to make sure I have a connection and I do). HR is a schema in the database and T_Donation is a table in HR.
    Data: w1(3),
             c1 type cursor.
    start-of-selection.
      if con_name is initial.
        write: 'No connection specified'.                       "#EC NOTEXT
        return.
      endif.
    try to open the connection and catch the errors (if any)
      try.
          con_ref = cl_sql_connection=>get_connection( con_name ).
        catch cx_sql_exception into sqlerr_ref.
        error occured
          write:
            'Could not open connection', con_name, '.'.         "#EC NOTEXT
          if sqlerr_ref->unknown_connection = 'X'.
            write:
              / con_name, 'is not defined in DBCON'.            "#EC NOTEXT
          elseif sqlerr_ref->db_error = 'X'.
            write:
              / 'sql error', sqlerr_ref->sql_code, 'occured:',
              / sqlerr_ref->sql_message.                        "#EC NOTEXT
          else.
            perform get_trace_file using dev_file.
            write:
              / 'DBI error', sqlerr_ref->internal_error, 'occured.',
              / 'See trace file for further info:',
                icon_read_file as icon hotspot, dev_file.       "#EC NOTEXT
          endif.
          return.
      endtry.
    connection successfully opened
      write:
        / 'Connection', con_name, 'successfully opened.'.       "#EC NOTEXT
    *- Get the data from MS-SQL Server
      EXEC SQL.
        open C1 for
        SELECT HR.T_DONATION.DN_DONATIONYEAR
        FROM HR.T_DONATION
      ENDEXEC.
      do.
        EXEC SQL.
          FETCH NEXT C1 into :w1
        ENDEXEC.
        if sy-subrc = 0.
          perform loop_output.
        else.
          exit.
        endif.
      enddo.
      EXEC SQL.
        CLOSE C1
      ENDEXEC.
    close connection again
      con_ref->close( ).
      write:
        / 'Connection', con_name, 'closed'.                     "#EC NOTEXT
    end-of-selection.
    *& Form LOOP_OUTPUT
    Output
    form loop_output .
      write: /5 w1.
    endform. " LOOP_OUTPUT
    Thanks for your help.
    Jim
    Message was edited by:
            James Barnes

    Well my advice is to check the question in the sql tutorial, it will be quicker then getting an answere.

  • Native sql not populating correct data in ECC6.0 unicode system

    Hi,
    I am working in an upgrade upgrade project from 4.6c to ECC6.0.
    4.6c is non-unicode system. ECC6 is Unicode system.
    I am facing Native SQL problem in custom developed programe in ECC6.That means programe reading the data from oracle datbase and stored into internal table.
    But data not stored as normal character format that means its stored as different character format.
    I am suspecting this is due to unicode system. IF that is issue then please provide
    what syntax I have to use for Native SQL statment in unicode system.
    I have provided the code which we are using in programe.
      data:
        i_locn       type table of t_locn,
        v_locn       like line  of i_locn.
      field-symbols:
        <f_005t>        type t_005t.
    Get existing EIS_VIDEO_LOCN_CONV records
      EXEC SQL.
        OPEN C FOR
          SELECT EIS_LOCN
            FROM VIDADMIN.EIS_VIDEO_LOCN_CONV
      ENDEXEC.
      do.
        EXEC SQL.
          FETCH NEXT C
            INTO :V_LOCN-EIS_LOCN
        ENDEXEC.
        if sy-subrc ne 0.
          exit.
        endif.
        append v_locn to i_locn.
      enddo.
      EXEC SQL.
        CLOSE C
      ENDEXEC.
      sort i_locn.
    I am facing the problem in i_locn internal table. Please give me your input to solve this issue.
    - Anandakumar K

    Hi,
    We have resolved this issue with BASIS team help.
    We modified the data charcater set as UTF8  in Oracle data base in unicode system ECC6.0 then the programme returns the
    exact character format
    Regards
    K.Anandakumar

  • Mapping Problem with Native SQL query

    My application uses a native SQL query to locate certain entities. It looks like this:
    SELECT UPLOADATTEMPTREF, STUDENTNUMBER, USERID, WORKITEMCODE, WORKITEMINSTURN, WORKITEMTITLE, MODULERUNCODE, STUDENTNAME, SUBMISSIONDEADLINE, UPLOADATTEMPTSERVERDATE, FILENAME, UPLOADCOMPLETESERVERDATE, NEWFILENAME, FILESIZE, FILEPATH, DOWNLOADSERVERDATE, MODULECODE, MODULETITLE
    FROM Submission_Attempt WHERE UPLOADATTEMPTREF IN (
    SELECT uploadAttemptRef FROM (" +<br /><br />                         "SELECT MAX(uploadAttemptRef) AS uploadAttemptRef, UserID, workItemInstUrn, " +<br /><br />                         "workItemCode FROM Submission_Attempt where workiteminsturn = ?1 " +<br /><br />                         "GROUP BY UserID, workItemInstUrn, workItemCode) Table1 ) " +<br /><br />                         "and uploadCompleteServerDate is not null;"<br />
    My expectation was that EclipseLink would be able to handle the mapping of the results to the entity quite happily. However, I get a NonSynchronizedVector of Objects - each Object representing one field of data.
    I need help with either:
    Converting the above SQL into JPQL so that I (hopefully) don't have to worry about the SQL or
    Understanding why this isn't working properly...
    Anyone able to help?
    Edited by: phunnimonkey on Nov 6, 2008 3:33 AM

    Never mind - the problem was to do with not specifying a class when creating the native query.

  • Query in native SQl

    I'm new to Native SQL commands.
    Can somebody tell me how to fine tune this code.
    Is there anything like FOR ALL ENTRIES in these commands also. We're using Oracle database.
    loop at it_cus1.
          EXEC SQL PERFORMING APPEND_IT_CUS2.
            SELECT SAP_MASTNR, ANK_MASTNR
            INTO
            :IT_CUS2-KUNNR, :IT_CUS2-DATLT
            FROM NOVARTIS.TABLE_ADRESS@ANKD
              WHERE ANK_MASTNR = :IT_CUS1-DATLT
          ENDEXEC.
    endloop.
    FORM append_it_cus2 .
      APPEND it_cus2.
      CLEAR it_cus2.
    ENDFORM.

    you could try cursor processing, it might be more efficient:
    EXEC SQL.
      OPEN C FOR
    SELECT SAP_MASTNR, ANK_MASTNR
    FROM NOVARTIS.TABLE_ADRESS@ANKD
    WHERE ANK_MASTNR = :IT_CUS1-DATLT
    ENDEXEC.
    loop at it_cus1.
      EXEC SQL.
        FETCH NEXT C into
        :IT_CUS2-KUNNR, :IT_CUS2-DATLT
      ENDEXEC.
      APPEND it_cus2.
      CLEAR it_cus2.
    ENDloop.
    EXEC SQL.
      CLOSE C
    ENDEXEC.

Maybe you are looking for

  • Is there a third party MagSafe 2 L-shaped adapter for MBA

    In the 18 months we've had our 2012 MBA, we've never had a day in which the MagSafe 2 didn't come out at least 5 times without our intending it to.  This laptop is portable - it doesn't stay on a desk - my wife works in bed, on the couch, while nursi

  • Help with Location Services.

    Just got an iPad (MD510LL) The device can't determine my location, on any app. Everything that is suppose to be on, is set. I even went as far as reseting all settings and still no cigar. I have access to the internet and I have no issues in that dep

  • Job Schedular status running after killing process flow from OWF monitor

    Hi, PROBLEM SCENARIO: Scheuled job called 'TEST' kicks off process flow called 'Child_load' under 'Parent_load_all' and gets stuck. I go into OWF (ORACLE WORK FLOW MONIOTOR) and kill both the process flows and then complete the Process flow run manua

  • OIM 11gR2 : GTC working but no entry in USR

    Hi, I am running a GTC for recon with the ODS. I am getting no errors in the error log, the scheduler runs the GTC job absolutely fine but i am not getting the recon entry in the USR table. Kindly help. Thanks,

  • Max Message Size

    I´d like to configure the prohibition of processing messages grater than 100 MB... Is that possible? In which tx? Thanks a lot