Use of native SQL-select statment

hi,
in my z-abap i use a native sql, saying the following:
EXEC SQL.
  select agzdau into :gf_agzdau from APZD08/AG
                where AGMAID = '77732' and
                      AGJAHR = 2008 and
                      AGMON  = 09 and
                      AGSPAL = 'ZASALD'
                      %_HINTS AS400 'HARD_CLOSE'
ENDEXEC.
before that i make a connection to the server where the table is stored.
APZD08 is the library and AG is the filename (on a AS/400-machine)
BUT: the file is not always in APZD08-lib, it depends on the employee.
how can i make the lib-name and file flexible:
i have tried it with
select...............from :gf_file
and i have put a value for gf_file before.
but with that i got an SQL-error -104 when executing.
i can't use a hostvariable there it seems.
any ideas ?
reg, Martin

Hi.
I would use ADBC instead of EXEC SQL. Then you can concatenate the SQL statement in the way you want it. But in that case you should use host variables in the where condition to get better performance.
So something like the following (untested, no syntax check yet, pseudo code...):
DATA: p_con_name   TYPE dbcon-con_name,
      p_con_ref    TYPE REF TO cl_sql_connection,
      p_stmnt      TYPE REF TO cl_sql_statement,
      p_result_set TYPE REF TO cl_sql_result_set,
      query        TYPE string.
p_con_ref = cl_sql_connection=>get_connection( 'YOURCON' ).
LOOP AT it_employees
* CASE your logic
CONCATENATE 'select agzdau from '  table_name
            'where  AGMAID = ? and AGJAHR = ?'
       INTO statement SEPARATED BY SPACE.
* ENDCASE
TRY.
  p_stmnt = p_con_ref->create_statement( ).
  GET REFERENCE OF p_agamaid INTO p_paramref.
  p_stmnt->set_param( p_paramref ).
  GET REFERENCE OF p_agjahr INTO p_paramref.
  p_stmnt->set_param( p_paramref ).
  p_result_set = p_stmnt->execute_query( query ).
  GET REFERENCE OF gf_agzdau INTO p_resultref.
  p_result_set->set_param( p_resultref ).
  p_result_set->next( ).
  CATCH CX_SQL_EXCEPTION.
* error handling needed!
  ENDTRY.
ENDLOOP.
p_con_ref->close( ).
Oh, I was assuming that there is only one result. If there can be more (and better style anyway) do a while-loop until next( ) is different from zero.
Best regards,
Jan

Similar Messages

  • Use of Native SQL

    Can i use all sql statementsa which are used in oracle ? Basically I am more interested in oracle data conversion functions like to_date(),To_Char() with appropriate formats.
    I know that to use oracle's native commands i have to use Native SQL and for that i have to write my query between EXEC SQL and ENDEXEC.  But i am not able to use query that uses date conversion fuctions like to_date() and to_char().
    Also i want to know the list of SQL statements which can be used with Native SQL in Oracle.

    HI.
    please refer this one.
    To avoid the standard F4 help to be show, insert the event PROCESS ON-VALUE-REQUEST request in the program and add a field statement for the field that should trigger the F4 help. In the module called from PROCESS ON-VALUE-REQUEST request, call function module F4IF_FIELD_VALUE_REQUEST.
    Example Code :
    process before output.
    process after input.
    PROCESS ON VALUE-REQUEST.
    FIELD sflight-carrid MODULE f4_help_for_carrid.
    MODULE f4_help_for_carrid INPUT.
    NOTE:
    Tabname/fieldname is the name of the table and field
    for which F4 should be shown.
    Dynprog/Dynpnr/Dynprofield are the names of the Progran/Dynpro/Field
    in which the f4 value should be returned.
    Value: The value of the Dynpro field when calling the F4 help.
    You can limit the values shown, by inseting a value in this parameter
    e.g 'A*' to show only values beginning with A
    CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
    tabname = 'SFLIGHT'
    fieldname = 'CARRID'
    SEARCHHELP = ' '
    SHLPPARAM = ' '
    dynpprog = 'ZDANY_F4_OWN_CALL'
    dynpnr = '0100'
    dynprofield = 'SFLIGHT-CARRID'
    STEPL = 0
    value = 'A*'
    MULTIPLE_CHOICE = ' '
    DISPLAY = ' '
    SUPPRESS_RECORDLIST = ' '
    CALLBACK_PROGRAM = ' '
    CALLBACK_FORM = ' '
    TABLES
    RETURN_TAB =
    EXCEPTIONS
    FIELD_NOT_FOUND = 1
    NO_HELP_FOR_FIELD = 2
    INCONSISTENT_HELP = 3
    NO_VALUES_FOUND = 4
    OTHERS = 5
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDMODULE. " F4_help_for_carrid
    To control F4 help in a selection screen use the AT SELECTION-SCREEN ON VALUE-REQUEST FOR event.Note that for ranges both the low and high value of the field must have there own ON VALUE-REQUEST
    Example:
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prctr-low.
    PERFORM f4_help_carrid.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prctr-high.
    PERFORM f4_help_carrid
    Rewards all helpfull answers.
    Regards.
    Jay

  • BW uses more Native SQL than R/3 does?

    hi all,
    BW uses more Native SQL than R/3 does? can anyone explain me how does bw makes effective use of native sql. (i knew what is meant by native sql). can anyone explain me with an realtime scenario.
    regds
    hari

    Hi,
    I don't get your question exactly; Native SQL is the SQL coding used in ABAP in order to deal with the underlying database objects (but I read that you knew that already...).
    BW and R/3 are using extensively native SQL, I couldn't tell if one the application uses more than the other, furthermore I don't think such a statement would make sense.
    BW uses native SQL to post data in the PSA, read this data in the PSA and pass it the internal tables for further processing (Trules / URules for instance); insert records in a cube; read the data in a cube/ods/IObj... in order to display the result of a query; native SQL is used for administrating the BW objects, monitoring, to record statistic; native SQL is used to generate code dynamically and to store/retrieve it from the database...
    In few words, there's a database table behind every single object/process in BW and R/3.
    The database is the memory of your system, native SQL is the mean to use this memory.
    hope this answers your question
    Olivier.
    Message was edited by:
            Olivier Cora

  • Retreiving data from external DB using cursors (Native SQL)

    Hi experts,
    Iu2019m trying to use some functionality based on the Native SQL on an Oracle Server. Iu2019m facing some difficulties using cursors and fetching data from the external database.
    Basically the synonym its zfisicc_c_dblink, and Iu2019m running the for the following code:
    TRY.
          OPEN CURSOR WITH HOLD c1 FOR SELECT *
                                FROM  zfisicc_c_dblink
                                WHERE estado_sif = 'I'.
        CATCH cx_sql_exception INTO sqlerr_ref.
          PERFORM handle_sql_exception USING sqlerr_ref.
      ENDTRY.
    DO.
    *  "Move the data from the Cursor into the target area.
        FETCH NEXT CURSOR c1 APPENDING TABLE tab.
        IF sy-subrc  0.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE CURSOR c1.
    The cursor C1 it's cursor type and the table tab it's ZFISICC_C_DBLINK type, but every time i run it it's giving me the ORA-932 error.
    Database error text........: "ORA-00932: inconsistent datatypes: expected %s
    got %s"
    Can anyone help me on this error? What Iu2019m doing wrong when fetching the data ?
    Another doubt that Iu2019ve it's when using pl/Sql procedure. Can anyone tell how I can retrieve data from the external database with the following code?
    **Select Directo com Cursor
      EXEC SQL.
        CONNECT TO :gv_db_name AS 'dblink_con'
      ENDEXEC.
      IF sy-subrc NE 0.
        WRITE: 'Não foi possível fazer a ligação à DBCON: ', gv_db_name.
      ELSE.
        EXEC SQL.
          DECLARE CURSOR c_1 IS SELECT tipo_operacao FROM movimento_contribuicao
                 WHERE ROWNUM <= 10000;
              wa movimento_contribuicao.tipo_operacao%type;
    BEGIN
           OPEN c_1;
         LOOP
            FETCH c_1 INTO wa; "Not able to return data to SAP system
             EXIT WHEN c_1%NOTFOUND;
          END LOOP;
      END;
        ENDEXEC.
          EXEC SQL.
          DISCONNECT 'dblink_con'
        ENDEXEC.
      ENDIF.
    On the FETCH c_1 INTO wa; code Iu2019m moving the data to an Oracle variable, wa movimento_contribuicao.tipo_operacao%type;, and not to an program variable. Can anyone explain me this how this is +possible using this PL/SQL procedure?
    Thanks in advance,
    Best Regards
    João Martins
    Edited by: Rob Burbank on May 7, 2010 10:25 AM

    Hi Joao,
    Regarding your first question: It looks like there's a conversion problem (with one or more columns) from your Oracle table to your ABAP internal table.
    In the following link you can see (in your case in the SELECT section) the type conversions used for each type combination.
    Some combinations lead to an oracle error (specified in the "Result" column), like in your case (error 932).
    http://help.sap.com/saphelp_470/helpdata/EN/a3/74caa1d9c411d1950e0000e8353423/content.htm
    Regarding your second question: You can use the PERFORMING addition in the EXEC SQL statement.
    You can see an example in the following link:
    http://help.sap.com/saphelp_470/helpdata/EN/fc/eb3b8b358411d1829f0000e829fbfe/content.htm
    Hope it helps.
    Regards,
    Ana Luisa.

  • "Select * into table internal_table from database_table" in native SQL

    Dear All,
    Is it possible to insert into internal table from database table in native sql instead of open sql? Regarding single values it's clear, just to use ":variable_name". But how to map internal table? RDBMS Oracle version > 9. If it's possible and you know how to do it, please, give some code example.
    Thank you,
    Pavel

    Hi ,
    Here is the code snippet for the native sql .
    select * from zwf_role into table i_wfroles." where role_id ='CAO'.
      loop at i_wfroles into wa_wfroles.
        EXEC sql.
          insert into   ROLES_MASTER_SAP
                 values (:wa_wfroles-ROLE_ID,:wa_wfroles-ROLE_NM,
                        :wa_wfroles-ROLE_DESC,:wa_wfroles-PAR_ROLE_ID,
                        :wa_wfroles-WF_ROLE_ORDER,:wa_wfroles-ROLE_TYPE )
        ENDEXEC.
        if sy-subrc = 0 .
          suc_rec_cnt = suc_rec_cnt + 1.
        else.
          fail_rec_cnt = fail_rec_cnt + 1.
        endif.
    *              ( ROLE_ID,ROLE_NAME, ROLE_DESC,PARENT_ROLE_ID,ROLE_ORDER,
    *                  ROLE_TYPE )
      endloop.
    zwf_role database table has the same files
    Regards
    Girish

  • About use native sql

    how to use the native sql get the following value
    REPORT  YXLIU0010.
    DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
          error_text TYPE string.
    DATA: BEGIN OF ITAB OCCURS 0 ,
      F_BH(30) TYPE C,
      F_NCYEJE TYPE p DECIMALS 2,
    END OF ITAB.
      TRY.
        EXEC SQL PERFORMING eout.
          select ZFIITKMJE.F_KMBH as F_BH,SUM(F_SNJZ) as F_NCYEJE  into :itab from ZFIITKMJE
        ENDEXEC.
      CATCH cx_sy_native_sql_error
        INTO exc_ref.
        error_text = exc_ref->get_text( ).
        ROLLBACK WORK.
      ENDTRY.
    FORM eout.
      write / ITAB-f_bh  .
    ENDFORM.
    it seems than native sql not suppot alias column

    ok!, the last code can work. but i don`t know what happen with "fetch next" or with other thing....
    because now the problem is when call the function: DB02_GET_TB_DETL_ANALYSIS_DB2.
    this send  a dump:
    Table does not exist in database.
    The termination occurred in line 26 of the source code of the (Include)
    program "LDB02_DB2U20"
    of the source code of program "LDB02_DB2U20" (when calling the editor 260).
    Processing was terminated because the exception "CX_SY_NATIVE_SQL_ERROR"
    occurred in the
    procedure "DB02_GET_TB_DETL_ANALYSIS_DB2" "(FUNCTION)" but was not handled
    locally, not declared in the
    RAISING clause of the procedure.
    The procedure is in the program "SAPLDB02_DB2 ". Its source code starts in line
    7
    of the (Include) program "LDB02_DB2$20 ".
    and indicate this part in the code of the function:
    000240 ?
    000250 ?   EXEC SQL.
         > ?     SELECT NAME, CREATOR,
    000270 ?            TYPE, DBNAME,
    000280 ?            TSNAME, COLCOUNT,
    000290 ?            NPAGES, KEYCOLUMNS,

  • 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.

  • Native sql for nth record

    Hi generally in oracle
    we write something like this
    select top 1 * from emp_mast where row_num = 10.
    for getting the 10th row from table.
    so in ABAP
    how to write the same with native sql.
    select * from mara into wa up to 10 rows order by matnr descending.
    check sy-subrc = 0.
    write mara-matnr.
    exit.
    endselect.
    but the above is not satisfactory
    I think so in open sql its not possible....if possible then how ?
    Any ideas...

    hi
    There is no nth record in a relational database
    i just asked this question because it was asked ..... i dont mention it here beause its against forum rules !!!
    Oracle is also a RDBMS.
    I admit to your reply about reorg.
    if oracle db is used in SAP ... then it should be possible to replicate the same in ABAP using native sql ... not sure just an assumption ...

  • 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

  • Function which returns multiple values that can then be used in an SQL Sele

    I'd like to create a function which returns multiple values that can then be used in an SQL Select statement's IN( ) clause
    Currently, the select statement is like (well, this is a very simplified version):
    select application, clientid
    from tbl_apps, tbl_status
    where tbl_apps.statusid = tbl_status.statusid
    and tbl_status.approved > 0;
    I'd like to pull the checking of the tbl_status into a PL/SQL function so my select would look something like :
    select application, clientid
    from tbl_apps
    where tbl_apps.statusid in (myfunction);
    So my function would be running this sql:
    select statusid from tbl_status where approved > 0;
    ... will return values 1, 5, 15, 32 (and more)
    ... but I haven't been able to figure out how to return the results so they can be used in SQL.
    Thanks for any help you can give me!!
    Trisha Gorr

    Perhaps take a look at pipelined functions:
    Single column example:
    SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(32767);
      2  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
      2      l_idx    PLS_INTEGER;
      3      l_list   VARCHAR2(32767) := p_list;
      4      l_value  VARCHAR2(32767);
      5    BEGIN
      6      LOOP
      7        l_idx := INSTR(l_list, p_delim);
      8        IF l_idx > 0 THEN
      9          PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
    10          l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
    11        ELSE
    12          PIPE ROW(l_list);
    13          EXIT;
    14        END IF;
    15      END LOOP;
    16      RETURN;
    17    END SPLIT;
    18  /
    Function created.
    SQL> SELECT column_value
      2  FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    COLUMN_VALUE
    FRED
    JIM
    BOB
    TED
    MARK
    SQL> create table mytable (val VARCHAR2(20));
    Table created.
    SQL> insert into mytable
      2  select column_value
      3  from TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    5 rows created.
    SQL> select * from mytable;
    VAL
    FRED
    JIM
    BOB
    TED
    MARK
    SQL>Multiple column example:
    SQL> CREATE OR REPLACE TYPE myrec AS OBJECT
      2  ( col1   VARCHAR2(10),
      3    col2   VARCHAR2(10)
      4  )
      5  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE TYPE myrectable AS TABLE OF myrec
      2  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION pipedata(p_str IN VARCHAR2) RETURN myrectable PIPELINED IS
      2    v_str VARCHAR2(4000) := REPLACE(REPLACE(p_str, '('),')');
      3    v_obj myrec := myrec(NULL,NULL);
      4  BEGIN
      5    LOOP
      6      EXIT WHEN v_str IS NULL;
      7      v_obj.col1 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
      8      v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
      9      IF INSTR(v_str,',')>0 THEN
    10        v_obj.col2 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
    11        v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
    12      ELSE
    13        v_obj.col2 := v_str;
    14        v_str := NULL;
    15      END IF;
    16      PIPE ROW (v_obj);
    17    END LOOP;
    18    RETURN;
    19  END;
    20  /
    Function created.
    SQL>
    SQL> create table mytab (col1 varchar2(10), col2 varchar2(10));
    Table created.
    SQL>
    SQL> insert into mytab (col1, col2) select col1, col2 from table(pipedata('(1,2),(2,3),(4,5)'));
    3 rows created.
    SQL>
    SQL> select * from mytab;
    COL1       COL2
    1          2
    2          3
    4          5

  • JDBC Receiver - Message Protocol = Native SQL String

    Hi Friends
    Has any one worked on JDBC Receiver with Message Protocol as <b>Native SQL String</b>?
    If so, can you please send me a detailed scenario of it...like
    the datatypes, message types, mappping.
    Because if I use the Native SQL String, then I think I have to pass a simple SQL string to the receiver..
    So how can I do that?
    Regards,
    Raju...

    Hi Raju,
    This can be done using the following format,
    <root>
      <stmt>
        <Customers action="SQL_DML">
          <access> UPDATE Customers SET Name=’$NAME$’ WHERE Number='$NUMBER$’
          </access>
          <key>
            <NAME>ABC</NAME>
            <NUMBER>000</NUMBER>
          </key>
        </Customers>
      </stmt>
    </root>
    Just pass map the value to the correspondung fields in the KEY FIELD and it will work like you want, dynamically.
    Regards,
    bhavesh

  • Fetch join with Native SQL Query?

    Hello all,
    I am using the J2EE 5.0 persistence api with the SUN appserver v9. As the java persistence api does not yet support spatial queries ("... where contains(polygon, point)") I have to use native SQL queries for that purpose.
    Now my question is how can I "join fetch" my ManyToOne-related entities when using a native SQL query? Is this somehow possible using the SqlResultSetMapping annotation?

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

Maybe you are looking for

  • Error by sending a Web Service request

    Hi, we generated a WSDL from an outbound-interface and build a web application with it. When we send a Web Service request to SAP-XI from our Web Dynpro client application, we get an error "CALL_CONSUMER_ERROR" (of category "XI_J2EE_MESSAGING_SYSTEM"

  • Maximum No. of DBs involved in Oracle Streams

    Hi, Is there any limitations in Maximum No. of databases involved in Oracle Streams. I have implemented schema level oracle streams between two database. I am planning to extend to another 6 database. Is it feasible or any restriction, pl. clarify.

  • Question About Time Remapping - Premiere Pro CC 2014

    I have a question in regards the the Time Remapping feature. When I use it to gradually speed a clip up, the audio obviously doesn't change with the video. I was looking to see if there is a way to do the same change to the audio, within Pr Pro or Au

  • Iphoto isn't working on my macbook pro

    Iphoto isn't working on my macbook pro, it is coming up with the following message:- Your photo library is either in use by another application or has become unreadable. Shut down and restart your computer, and then open iphoto again.  If the problem

  • Sales order - Delivery Block

    Hello all. I am creating a sales order using the bapi BAPI_SALESORDER_CREATEFROMDAT2. The problem is that is the client has a delivery block i want to remove it from the sales order so i can deliver. How can i do this? Thanks in advance Nuno Silva