GRANT statements in EXEC SQL/ENDEXEC

Hello, All!!
Can someone please advise if this is possible in ABAP? Sample code is:
      exec sql.
        GRANT SELECT ON :tabname TO 'DB_ROLE'
      endexec.
I am getting a ORA-00903 error, the trace file is showing "GRANT SELECT ON :A0  TO 'OWB_BI_READONLY';"
Please advise ASAP; points guaranteed for helpful answers.
Best Regards,
Reenal

Hi Reenal,
Try using the below code:
  data: zsql type ref to CL_SQL_STATEMENT.
  CREATE OBJECT ZSQL.
  tabname = <i>tablename</i>.
  data: lv_state(200),
        lv_strstate type string.
  concatenate
        'GRANT SELECT ON'
        tabname
        'to OWB_BI_READONLY'
        into lv_state separated by space.
  lv_strstate = lv_state.
  translate lv_strstate to upper case.
  TRY.
      CALL METHOD ZSQL->EXECUTE_DDL
        EXPORTING
          STATEMENT = lv_strstate.
    catch CX_SQL_EXCEPTION INTO exc_ref.
      error_text = exc_ref->get_text( ).
      MESSAGE error_text TYPE 'I'.
  ENDTRY.

Similar Messages

  • EXEC SQL

    Hi,
    What does an EXEC SQL stmt do in ABAP?
    What is the disadvantage of using it?
    Regards,
    Kalai

    Hi
    <b>EXEC SQL</b>
    EXEC SQL [PERFORMING subr].
    ENDEXEC.
    These 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. These SAP-specific language elements are::
    <b>Host variables</b>
    Statements for cursor processing
    Database procedure calls
    Statements for establishing database connections
    All Native SQL statements bypass SAP buffering. Automatic client handling is not performed.
    <b>System fields</b>
    The statement ENDEXEC sets the system fields sy-subrc and sy-dbcnt.
    sy-subrc Meaning
    0 The statements between EXEC and ENDEXEC were executed successfully.
    4 The statements between EXEC and ENDEXEC were not executed.
    The ENDEXEC statement sets sy-dbcnt to the number of table rows processed in the last Native SQL statement.
    Programs with Native SQL statements are generally dependent on the database system used, so that they cannot be executed in all SAP Systems. This is especially true for the examples in this section, which was written for Informix database systems.
    <b>Example</b> 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.
    <b>Reward if usefull</b>

  • Error in EXEC SQL

    hi, I have a problem.
    I would like to capture an error provoked by the education EXEC SQL.
    I have tried to insert the block try... cath around the command EXEC but
    the program goes in loop.
    Thanks for the help
    This is the example that I have tried but it doesn't work
    data myref type ref to CX_SY_NATIVE_SQL_EROR.
    try.
    exec sql.
    endexec.
    catch CX_SY_NATIVE_SQL_EROR.
    write 'Error ', myref->SQL_ERROR.
    RAISE EXCEPTION myref.
    endtry.

    According to you, you've placed the sqlexec statements in fieldchange event but if you'll notice in your error, it happened on the fieldformula event of SI_LTTR_TMP field. currently, what is the code in SI_WRK.SI_LTTR_TMP.FieldFormula?
    Thanks...

  • Possible to do "grant" sql statement in Native SQL?

    We have a need to do a grant of access from one of our systems out for various applications.  In order for this to work we need to run a grant access command on the table and are trying to put a wrapper around this so we can use an abap.  Below is the code I am unit testing.  Two questions.  First, can a grant be done via native SQL in abap?  Second, if it can be done, what is the error with the logic where I am trying to put in the table name via a parameter.
    REPORT  ZLJTEST2.
    tables dd02l.
    DATA scarr_carrid TYPE dd02l-tabname.
    SELECT-OPTIONS s_carrid for dd02l-tabname no intervals.
    DATA s_carrid_wa LIKE LINE OF s_carrid.
    DATA name TYPE c LENGTH 20.
    TRY.
        EXEC SQL.
          CREATE FUNCTION selfunc( input CHAR(20) )
            RETURNING char(20);
            DEFINE output char(20);
            set schema sapr3;
            grant select on table input to group infouser;
            RETURN output;
            END FUNCTION;
        ENDEXEC.
        LOOP AT s_carrid INTO s_carrid_wa
                         WHERE sign = 'I' AND option = 'EQ'.
          TRY.
             EXEC SQL.
                EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low,
                                           OUT :name )
              ENDEXEC.
              WRITE: / s_carrid_wa-low, name.
            CATCH cx_sy_native_sql_error.
              MESSAGE `Error in procedure execution` TYPE 'I'.
          ENDTRY.
        ENDLOOP.
        EXEC SQL.
          DROP FUNCTION selfunc;
        ENDEXEC.
      CATCH cx_sy_native_sql_error.
        MESSAGE `Error in procedure handling` TYPE 'I'.
    ENDTRY.

    Hi,
    Yes it is posible.
    I made one program like you want. But it need very long code.
    Here I explain the idea:
    1. Create Screen with input TEXT EDIT CONTROL.
        This is for input SQL Statement.
    2. Get SQL Statement from Text Edit Control using method <b>get_text_as_r3table</b>.
    3. Now we need to separate SQL Statement into different table.
        We Separate SELECT, FROM, WHERE, GROUP, HAVING, ORDER, etc.
    4. We need dynamic internal table to store the data.
    5. Select the data according SQL statement.
          SELECT (IT_SELECT)
            into corresponding fields of table  <dyn_table>
          FROM (IT_FROM)
          WHERE (IT_WHERE)
          GROUP BY (IT_GROUP)
          HAVING (IT_HAVING)
          ORDER BY (IT_ORDER).
    6. Display our data using ALV GRID
    Hopefully it will help you.
    Regards,

  • Use Of "#EC CI_EXECSQL in ABAP with EXEC SQL. Statement giving Syntax Error

    Dear Gurus,
    I have encountered an issue while trying to remove warning for using Native SQL statement using pseudo comment "#EC CI_EXECSQL
    The thing is like this -- i have used follwing native sql command in abap.
    EXEC SQL.
        CONNECT TO 'SURROUND_DB'
      ENDEXEC.
    Now when i am checking this code in code inspector it is showing a warning with information below
    CA CL_CI_TEST_CRITICAL_STATEMENTS0006
    Code Inspector
    Critical Statements
    Use of Native SQL
    Authorization checks cannot be appropriately run using EXEC SQL and should be carried out at program level.
    The message can be hidden using the pseudo-comment "#EC CI_EXECSQL
    Use of exceptin handling section for that warning showing me to use :
    The message can be hidden using pseudo
    comment      "#EC CI_EXECSQL
    Now when I am using "#EC CI_EXECSQL in the abap like below :
    EXEC SQL. "#EC CI_EXECSQL
        CONNECT TO 'SURROUND_DB'
      ENDEXEC.
    It is giving syntax error
    The text literal ""#EC CI_EXECSQL        " is longer than 255
    characters.Check whether it ends correctly.
    Please provide the guideline to resolve this issue.
    Thanks & regards
    Saifur Rahaman.

    Hi Saifur,
    You can remove the warning using the following syntax:
    EXEC "#EC CI_EXECSQL
      SQL.
        CONNECT TO 'SURROUND_DB'
      ENDEXEC.
    At least, it worked fine for me when using OPEN CURSOR, SELECT, FETCH and so on statements.
    The way to use the pseudo comment is not very intuitive, but at least for my examples worked fine.
    I hope this may help you.
    Best regards,
    Edgardo G. König

  • EXEC SQL STATEMENT

    Is there something wrong with this EXEC SQL Statement...
            EXEC SQL PERFORMING sr_STORE_data.
              select *
                     into :<FS_wt> @:c_db
                     from (lwt_source-PS_STRUCT)
                     where sb_effdt = :p_date
            ENDEXEC.

    hi,
    Check whether the table name can be passed dynamically by specifying it in parantheses.
    check this sample code, it might help you,
    **** A field-symbol to access that work area
      assign NEW_LINE->*  to <wa_it>.
    *PERFORMING loop using <wa_it> changing itab_test
      EXEC SQL.
       open c for
       SELECT
       HOB_KH_IK as Ik, count(*) as ANZAHL,
       AVG(ENTL_DATUM - HOB_AUFN_DAT) AS VWD,
       SUM(KOSTEN_GESAMT/100)  as KOSTEN
      FROM BUSI.BW02_K_FALL
      GROUP BY HOB_KH_IK
      ENDEXEC.
    DO.
          EXEC SQL.
            fetch next c into :<wa_it>
          ENDEXEC.
          IF sy-subrc <> 0.
            EXIT.
          ENDIF.
          append <wa_it> to itab_test.
        ENDDO.
        EXEC SQL.
          close c
        ENDEXEC.
        write: / 'OK ?'.
    Regards,
    Sailaja.
    Message was edited by:
            Sailaja Nalam

  • How to use INSERT in EXEC SQL ...... ENDEXEC ?

    Hi,
    The following code;
    DATA: BEGIN OF str_insert,
            a(3) TYPE c,
            b(3) TYPE c,
          END OF str_insert.
    EXEC SQL.
      SET CONNECTION DEFAULT
    ENDEXEC.
    str_insert-a = 'a'.
    str_insert-b = 'b'.
    EXEC SQL.
    INSERT INTO ZSAP  VALUES :str_insert
    ENDEXEC.
    The Structure of the ZSAP table (There is no data in ZSAP);
    A CHAR 3 (Primary Key)
    B CHAR 3
    I cannot instert a record to this table it throughs the following error;
    Runtime Errors         DBIF_DSQL2_SQL_ERROR  
    Exceptn                CX_SY_NATIVE_SQL_ERROR
    How could use a structure to insert values into ZSAP?
    Thanks,
    Kishan

    Hello..
      loop at T_PC.
        loop at T_PCD .
          at new NUMREFERENCIA.
            exec sql.
             INSERT INTO tblPolizaContableR3
                (LibroMayor, PeriodoContable, Prefijo, NumReferencia,
                Fecha, FuenteDiario, ComentarioPoliza, Moneda,
                TipoCambio, RefExternaID1, RefExternaID2, RefExterna1,
                RefExterna2, DescRefExterna)
             VALUES (:T_PC-LIBROMAYOR, :T_PC-PERIODOCONTABLE,
              :T_PC-PREFIJO, :T_PC-NUMREFERENCIA, :T_PC-FECHA,
              :T_PC-FUENTEDIARIO, :T_PC-COMENTARIOPLIZA, :T_PC-MONEDA,
              :T_PC-TIPOCAMBIO, :T_PC-REFEXTARNAID1, :T_PC-REFEXTERNAID2,
              :T_PC-REFEXTERNA1, :T_PC-REFEXTERNA2, :T_PC-DESCREFEXTERNA)
            endexec.
          endat.
            exec sql.
             INSERT INTO tblPolizaContableDetR3
                (LibroMayor, PeriodoContable, Prefijo, NumReferencia,
                Partida, Cuenta, CuentaIMSA, CCostoIMSA,
                Cargo, Abono, ComentarioPartida)
             VALUES (:T_PCD-LIBROMAYOR, :T_PCD-PERIODOCONTABLE,
              :T_PCD-PREFIJO, :T_PCD-NUMREFERENCIA, :T_PCD-PARTIDA,
              :T_PCD-CUENTA, :T_PCD-CUENTAIMSA, :T_PCD-CCOSTOIMSA,
              :T_PCD-CARGO, :T_PCD-ABONO, :T_PCD-COMENPARTIDA)
            endexec.   
        endloop.
    Hope this help you.
    Regards, Gustavo Estrada

  • Exec SQL statement from BW to MS SQL

    Hi Experts,
    I need to execute sql statement from BW on MS SQL Server.
    I want to do it in process chain. There is a so called ABAP Program Component.
    How to implement such a program or function module that will execute on MS SQL Server an sql statement such as for instance:
    "Create view SOME_VIEW as select * from XTABLE".
    I have already configured database connection using DBCO transaction.
    Waiting for response.
    Krzysztof

    Thanks, but that is not what I was asking for.
    I just need to send some SQL statement from BW to MS SQL Server using ABAP program (exec sql or something like this).
    Could you provide me a pattern of such an ABAP program?
    The sql statement is not importent here, I have already extracted data from MS SQL to BW, I have configured dataflow, process chains and so on.
    No I need to determine DELTA on MS SQL Server. I've got some ideas but I need to know how to send SQL statement from BW to MS SQL Server using ABAP program.
    Please any help will be appreciated

  • SQL error 3113 occurred when executing EXEC SQL.

    Hi,
    We are facing one typical problem, One background is failing regularly with
    below dump. as we now got all notes giving information, if database  restarted
    taking backup, these type of failures occur, but our database is only down for backup once in a week, but it is failing with frequenly.
    in this two servers are located in different place, in this job tries to connect
    another server to get material statistics.
    It is giving some error message in sm21 with
    SQL error 3113 occurred when executing EXEC SQL.
    work procees in reconnect mode.
    all notes saying these types of dump occur when database restared, but this dump
    even though database is up.
    below is short dump, please can anyone help me from this problem.
    ABAP runtime errors    DBIF_DSQL2_SQL_ERROR
          Occurred on    08.01.2007 at 00:30:28
    >> Short dump has not been completely stored. It is too big.
    SQL error 3113 occurred when executing EXEC SQL.
    What happened?
    The error occurred in the current database connection "AZ1".
    What can you do?
    Note the actions and input that caused the error.
    Inform your SAP system administrator.
    You can print out this message by choosing "Print". Transaction ST22
    allows you to display and manage termination messages, including keeping
    them beyond their normal deletion date.
    Error analysis
    How to correct the error
    Database error text........: "ORA-03113: end-of-file on communication channel#"
    Triggering SQL statement...: "select mara.groes, mara.brgew, mara.ntgew,
    mara.gewei, mara.volum, mara.voleh, mara.mstae, mara.mstde, mara.prdha,
    marc.matnr, marc.werks, marc.mmsta, marc.mmstd from sapr3.mara, sapr3.m
    where sapr3.mara.mandt = sapr3.marc.mandt and sapr3.mara.matnr =
    Internal call code.........: "[DBDS/NEW DSQL]"
    Please check the entries in the system log (Transaction SM21).
    If the error occurred in a non-modified SAP program, you may be
    able to find a solution in the SAP note system.
    If you have access to the note system yourself, use the following
    search criteria:
    "DBIF_DSQL2_SQL_ERROR"
    "ZM2431216 " or "ZM2431216 "
    "EXTRACT_GENERAL_DATA"
    If you cannot solve the problem yourself, please send the
    following documents to SAP:
    1. A hard copy print describing the problem.
      To obtain this, select the "Print" function on the current screen.
    2. A suitable hardcopy prinout of the system log.
      To obtain this, call the system log with Transaction SM21
      and select the "Print" function to print out the relevant
      part.
    3. If the programs are your own programs or modified SAP programs,
      supply the source code.
      To do this, you can either use the "PRINT" command in th
      print the programs using the report RSINCL00.
    4. Details regarding the conditions under which the error o
      or which actions and input led to the error.
    System environment
    SAP Release.............. "46C"
    Application server....... "essceu3"
    Network address.......... "172.19.119.198"
    Operating system......... "AIX"
    Release.................. "5.3"
    Hardware type............ "00C7ADBD4C00"
    Database server.......... "ukblx176"
    Database type............ "ORACLE"
    Database name............ "EU3"
    Database owner........... "SAPR3"
    Character set............ "es_ES.ISO8859-1"
    SAP kernel............... "46D"
    Created on............... "Jul 9 2006 20:26:33"
    Created in............... "AIX 1 5 00447C4A4C00"
    Database version......... "OCI_920__OCI_7_API "
    Patch level.............. "2257"
    Patch text............... " "
    Supported environment....
    Database................. "ORACLE 8.0.5.., ORACLE 8.0.6.., ORACLE
    8.1.6.., ORACLE 8.1.7.., ORACLE 9.2.0.., ORACLE 10.2.0.."
    SAP database version..... "46D"
    Operating system......... "AIX 1 4, AIX 2 4, AIX 3 4, AIX 1 5, AIX 2 5, AIX 3
    5, , System build information:,                                      , LCHN :
    841480"
    User, transaction...
    Client.............. 600
    User................ "MPZMMES"
    Language key........ "S"
    Transaction......... " "
    Program............. "ZM2431216 "
    Screen.............. "SAPMSSY0 1000"
    Screen line......... 6
    Information on where termination occurred
    The termination occurred in the ABAP/4 program "ZM2431216 " in
    "EXTRACT_GENERAL_DATA".
    The main program was "ZM2431216 ".
    The termination occurred in line 980
    of the source code of program "ZM2431216 " (when callin
    The program "ZM2431216 " was started as a background jo
    Source code extract
    009500              mara.ntgew,
    009510              mara.gewei,
    009520              mara.volum,
    009530              mara.voleh,
    009540              mara.mstae,
    009550              mara.mstde,
    009560              mara.prdha,
    009570              marc.matnr,
    009580              marc.werks,
    009590              marc.mmsta,
    009600              marc.mmstd
    009610        into :w_ops-groes,
    009620              :w_ops-brgew,
    009630              :w_ops-ntgew,
    009640              :w_ops-gewei,
    009650              :w_ops-volum,
    009660              :w_ops-voleh,
    009670              :w_ops-mstae,
    009680              :w_ops-mstde,
    009690              :w_ops-prdha,
    009700              :w_ops-matnr,
    009710              :w_ops-werks,
    009720              :w_ops-mmsta,
    009730              :w_ops-mmstd
    009740        from sapr3.mara, sapr3.marc
    009750        where sapr3.mara.mandt = sapr3.marc.mandt
    009760          and sapr3.mara.matnr = sapr3.marc.matnr
    009770          and sapr3.mara.mandt = :p_mandt
    009780          and sapr3.mara.matnr = :w_ebs-matnr
    009790          and sapr3.marc.werks = :p_owerks
        >    ENDEXEC.
    009810  endform.                    " extract_general_data
    009820  *&
    009830  *&      Form  append_i_ops
    009840  *&
    009850  *      Appends W_OPS to I_OPS
    009860  *
    009870  form append_i_ops.
    009880    append w_ops to i_ops.
    009890  endform.                    " append_i_ops
    009900  *&
    009910  *&      Form  extract_material_description
    009920  *&
    009930  *      Extracts a Material Description from the remote database an
    009940  *      modifies the current record in I_OPS.
    009950  *
    009960  *        >P_SPRAS  Language Key
    009970  *
    009980  form extract_material_description using    p_spras.
    009990    EXEC sql performing set_langauge.
    Contents of system fields
    SY field contents..................... SY field contents............
    SY-SUBRC 0                            SY-INDEX 0
    SY-TABIX 1                            SY-DBCNT 1
    SY-FDPOS 18                            SY-LSIND 0
    SY-PAGNO 0                            SY-LINNO 1
    SY-COLNO 1
    Chosen variables
    Name.......................... Contents.1........2........3....+..
    W_EBS-PRAT4
                                  2
                                  0
    W_OPS-GROES
                                  22222222222222222222222222222222
                                  00000000000000000000000000000000
    W_OPS-BRGEW                    #######
                                  0000000
                                  000000C
    W_OPS-NTGEW                    #######
                                  0000000
                                  000000C
    regards,
    krishnaiah.

    Hi,
    This is usually a SERVER SIDE DATABASE PROBLEM or SQLNET LISTENER (server side) PROBLEM.  The client side should initially be ignored and instead the server should be investigated. In rare cases, this can be caused by client
    side memory or other resource problem, or a DLL version mismatch, but this is
    unlikely.
    Enlist the assistance of your DBA.  Then reproduce the ORA-3113 error on your
    client application.  Ask your DBA to look at the database side Alert.log and
    trace files and look for ANY activity.  Any activity that coincides with your
    ORA-3113 will be a clue.
    REgards
    Vinod

  • EXEC SQL join in ABAP program

    Hi All,
    I am using EXEC SQL join in my ABAP report,but it is giving dump.could you please correct my following code?
    START-OF-SELECTION.
      CONCATENATE '%' pa_match '%' INTO tp_match.
      EXEC SQL.
        OPEN dbcur FOR
        SELECT  kunnr,name1, banks
               FROM  kna1 as a inner join
               knbk as b
               on akunnr = bkunnr
               WHERE a.kunnr = b.kunnr and
               upper(a~name1) LIKE :tp_match
      ENDEXEC.
      DO.
        EXEC SQL.
          FETCH NEXT dbcur INTO :wa_name1
        ENDEXEC.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        APPEND wa_name1 TO ta_name1.
        COLLECT wa_name1 INTO ta_name1.
      ENDDO.
      EXEC SQL.
        CLOSE dbcur
      ENDEXEC.

    Remove the 'As' from the statement
    EXEC SQL.
      OPEN dbcur FOR
      SELECT kunnr,name1, banks
      FROM kna1 a inner join        "Delete 'AS' here
      knbk b
      on a~kunnr = b~kunnr
      WHERE a.kunnr = b.kunnr and
      upper(a~name1) LIKE :tp_match
    ENDEXEC.

  • Exec sql help

    Hi,
    I have this abap/exec sql code to extract data from as400/db2.
    I am getting data by a "select" statement and i am trying to append the records with append statements.
    but, not works.
    EXEC SQL.
        CONNECT TO 'SATDBR'
      ENDEXEC.
      EXEC SQL.
    --->(HERE THE PROBLEM)  OPEN C1 FOR.
          SELECT A,B,C,D
          FROM SAPTEST.XX1
      ENDEXEC.
        EXEC SQL.
          OPEN C1
          FETCH NEXT C1 INTO
         :ZTABLE.AA, :ZTABLE.BB, :ZTABLE.CC, :ZTABLE.DD 
    ENDEXEC.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          APPEND ZTABLE.
        ENDIF.
      ENDDO.
    EXEC SQL.
      CLOSE C1
    ENDEXEC.
      EXEC SQL.
        DISCONNECT 'SATDBR'
      ENDEXEC.
    I need to declare the cursor??? whats wrong in my code :S
    the runtime error is "A SQL mistake has appeared by the execution of Native SQL."
    i would appreciate your help.
    thanks
    vicky

    hi,
    I recommend you, make the select and test it first in the DB2 console.
    Only delcare your internal tables, your variable with abap code.
    To extract the data with the select statement is enough, to fill the table with several records use this code:
    EXEC SQL.
    CONNECT TO 'DB2' " the name of the connection
    ENDEXEC.
    EXEC SQL.
    OPEN C1 FOR
    SELECT A,B,C,D
    FROM SAPTEST.XX1
    ENDEXEC.
    DO
    EXEC SQL.
    OPEN C1
    FETCH NEXT C1 INTO
    :ZTABLE
    ENDEXEC.
    IF sy-subrc <> 0.
    EXIT.
    ELSE.
    APPEND ZTABLE.
    ENDIF.
    ENDDO.
    EXEC SQL.
    CLOSE C1
    ENDEXEC.
    EXEC SQL.
    DISCONNECT 'DB2'
    ENDEXEC.
    The ZTABLE must have the same order in which you put on the fields in the "select"
    DATA:   BEGIN OF  ztable OCCURS 0,
    A(1) TYPE c
    B(8) TYPE c
    C(17)TYPE N
    D(19 TYPE c
            DATA:   END   OF ZTABLE.
    I HOPE THIS INFORMATION HELPS YOU!!
    REGARDS
    VICKY
    Message was edited by: Victoria León

  • EXEC SQL with IN Clause

    Hello,
    I'm trying to run an EXEC SQL statement with an IN clause.  Here's my SQL code:
    EXEC SQL.
          OPEN C FOR
          SELECT name
                 FROM sv_hoover_data
                 where dunsNum in :DUNS_NUMBERS
        ENDEXEC.
    My DUNS_NUMBERS variable is of type String and contains the following data:
    ('12334223','4353434','54674563')
    When the statement is executed, I receive the following error message in SM21:
    Line 1: Incorrect syntax near '@P1'.
    Also, the underlying database is MS SQL Server.  When I run the query via MS Query Ananlyzer, it runs fine.
    Does any know if EXEC SQL can handle IN clauses, and if so, how they're written?
    Thanks,
    Matt

    I haven't used it myself (yet), but this is what I found in the help:
    EXEC SQL - EXECUTE
    Syntax
    EXEC SQL.
      EXECUTE PROCEDURE proc ( IN    p_in1    IN    p_in2 ...,
                               OUT   p_out1   OUT   p_out2 ...,
                               INOUT p_inout1 INOUT p_inout2 ... )
    ENDEXEC.
    Effect
    In database systems, you can define procedures as so-called "stored procedures". Since the syntax for calling such procedures and the pertinent parameter transfer for various database systems can vary widely, a uniform command exists in Native SQL.
    The statement EXECUTE PROCEDURE calls a procedure proc stored in the database. For all formal parameters of the procedure, you must specify the actual parameters, separated by commas. You must specify IN, OUT or INOUT before every actual parameter, in order to indicate whether the parameter is an input, output, or input/output parameter. You can use literals or Host Variables labeled by a colon(:)for the actual parameters.
    Example
    This example defines a selfunc procedure using database specific SQL-Statements (Informix). It also calls the procedure using the SAP-specific Native-SQL-Statement EXECUTE PROCEDURE in a LOOP-loop by means of a Selection Table, and deletes the the procedure using an SQL-Statement. In the case shown here, the procedure is a function whose return value output in EXECUTE PROCEDURE is copied to the host variable name.
    DATA scarr_carrid TYPE scarr-carrid.
    SELECT-OPTIONS s_carrid FOR scarr_carrid NO INTERVALS.
    DATA s_carrid_wa LIKE LINE OF s_carrid.
    DATA name TYPE c LENGTH 20.
    TRY.
        EXEC SQL.
          CREATE FUNCTION selfunc( input CHAR(3) )
            RETURNING char(20);
            DEFINE output char(20);
            SELECT carrname
                   INTO output
                   FROM scarr
                   WHERE mandt  = '000' AND
                         carrid = input;
            RETURN output;
            END FUNCTION;
        ENDEXEC.
        LOOP AT s_carrid INTO s_carrid_wa
                         WHERE sign = 'I' AND option = 'EQ'.
          TRY.
             EXEC SQL.
                EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low,
                                           OUT :name )
              ENDEXEC.
              WRITE: / s_carrid_wa-low, name.
            CATCH cx_sy_native_sql_error.
              MESSAGE `Error in procedure execution` TYPE 'I'.
          ENDTRY.
        ENDLOOP.
        EXEC SQL.
          DROP FUNCTION selfunc;
        ENDEXEC.
      CATCH cx_sy_native_sql_error.
        MESSAGE `Error in procedure handling` TYPE 'I'.
    ENDTRY.

  • TRY ... CATCH doesn't work with EXEC SQL?

    When I created a native SQL statement, I knew before, that it would take a few tries to get it working. I decided to use exception classes to avoid short dumps, but it didn't work.
    Following code causes a short dump because of the dot after :xp_stras in the native SQL SELECT statement:
       try.
           EXEC SQL                     PERFORMING  list.
             SELECT LIFNR, NAME1, STRAS
                                    INTO  :xsl
                                    FROM  LFA1
             WHERE  UPPER( NAME1 )  LIKE  :xp_name1
             AND    UPPER( STRAS )  LIKE  :xp_stras.
           ENDEXEC.
                                                                                    catch CX_SY_NATIVE_SQL_ERROR.
           write: /1 'CX_SY_NATIVE_SQL_ERROR'.
       catch CX_SY_SQL_ERROR.
           write: /1 'CX_SY_SQL_ERROR'.
       catch CX_DYNAMIC_CHECK.
           write: /1 'CX_DYNAMIC_CHECK'.
       catch CX_ROOT.
           write: /1 'CX_SY_ROOT'.
       endtry.
    In ST22 you can see
    Name of runtime error: DBIF_DSQL2_SQL_ERROR
    Exception:
    The name of the exception is empty, in other short dumps you can find there the name of the exception class. Maybe that's the reason for CATCH does'nt work, but I don't understand it.
    Online help for EXEC SQL says:
    Catchable Exceptions
    CXSY_NATIVE_SQL_ERROR_
    Cause: SQL-Error at the execution of a Native SQL-command.
    Runtime Error: DBIF_DSQL2_SQL_ERROR
    We have SAP ECC 6.0 with SAP_BASIS rel. 700 lvl. 0013.
    If You have an idea why CATCH doesn't work, please tell me!
    Regards,
    Klaus

    Hi Rob,
    I tried out Your original code as program ZTEST5 and got a short dump (sorry, some of the short dump symbols are formatting this post in a wrong way ...):
    Short text
        An SQL error occurred when executing Native SQL.
    What happened?
        The error 919 occurred in the current database connection "DEFAULT".
    What can you do?
        Note down which actions and inputs caused the error.
        To process the problem further, contact you SAP system
        administrator.
        Using Transaction ST22 for ABAP Dump Analysis, you can look
        at and manage termination messages, and you can also
        keep them for a long time.
    How to correct the error
        Database error text........: "ORA-00919: invalid function"
        Database error code........: 919
        Triggering SQL statement...: "FETCH NEXT "
        Internal call code.........: "[DBDS/NEW DSQL]"
        Please check the entries in the system log (Transaction SM21).
        If the error occures in a non-modified SAP program, you may be able to
        find an interim solution in an SAP Note.
        If you have access to SAP Notes, carry out a search with the following
        keywords:
        "DBIF_DSQL2_SQL_ERROR" " "
        "ZTEST5" or "ZTEST5"
        "START-OF-SELECTION"
        If you cannot solve the problem yourself and want to send an error
        notification to SAP, include the following information:
        1. The description of the current problem (short dump)
           To save the description, choose "System->List->Save->Local File
        (Unconverted)".
        2. Corresponding system log
           Display the system log by calling transaction
           Restrict the time interval to 10 minutes befor
        after the short dump. Then choose "System->List->
        (Unconverted)".
        3. If the problem occurs in a problem of your own
        program: The source code of the program
           In the editor, choose "Utilities->More
        Utilities->Upload/Download->Download".
        4. Details about the conditions under which the e
        actions and input led to the error.
    System environment
        SAP-Release 700
        Application server... "lux01617"
        Network address...... "195.217.80.104"
        Operating system..... "Linux"
        Release.............. "2.6.5-7.283-smp"
        Hardware type........ "x86_64"
        Character length.... 16 Bits
        Pointer length....... 64 Bits
        Work process number.. 5
        Shortdump setting.... "full"
        Database server... "lux09208"
        Database type..... "ORACLE"
        Database name..... "D10"
        Database user ID.. "SAPDAT"
        Char.set.... "C"
        SAP kernel....... 700
        created (date)... "Dec 2 2007 20:18:08"
        create on........ "Linux GNU SLES-9 x86_64 cc3.3.3"
        Database version. "OCI_102 (10.2.0.2.0) "
        Patch level. 138
        Patch text.. " "
        Database............. "ORACLE 9.2.0.., ORACLE 10.1.0.., ORACLE 1
        SAP database version. 700
        Operating system..... "Linux 2.6"
        Memory consumption
        Roll.... 16192
        EM...... 16759392
        Heap.... 0
        Page.... 98304
        MM Used. 694160
        MM Free. 3493088
    User and Transaction
        Client.............. 500
        User................ "Z0000D2P"
        Language key........ "E"
        Transaction......... "SE38 "
        Transactions ID..... "48FE92EB921F51C3E1000000C3D95068"
        Program............. "ZTEST5"
        Screen.............. "SAPMSSY0 1000"
        Screen line......... 6
    Information on where terminated
        Termination occurred in the ABAP program "ZTEST5" - in "START-OF-SELECTION".
        The main program was "ZTEST5 ".
        In the source code you have the termination point in line 16
        of the (Include) program "ZTEST5".
    Source Code Extract
    Line  SourceCde
        1 REPORT ztest LINE-SIZE 80 MESSAGE-ID 00.
        2
        3 TABLES: lfa1.
        4
        5 DATA: BEGIN OF xsl,
        6         lifnr TYPE lfa1-lifnr,
        7         name1 TYPE lfa1-name1,
        8         stras TYPE lfa1-stras,
        9       END   OF xsl.
       10
       11 DATA: xp_name1 TYPE lfa1-name1,
       12       xp_stras TYPE lfa1-stras.
       13
       14 TRY.
       15     EXEC SQL PERFORMING list.
    >>>>>       SELECT LIFNR, NAME1, STRAS
       17       INTO :xsl
       18       FROM LFA1
       19       WHERE UPPER( NAME1 ) LIKE :xp_name1
       20       AND UPPER( STRAS ) LIKE :xp_stras.
       21     ENDEXEC.
       22
       23   CATCH cx_sy_native_sql_error.
       24     WRITE: /1 'CX_SY_NATIVE_SQL_ERROR'.
       25   CATCH cx_sy_sql_error.
       26     WRITE: /1 'CX_SY_SQL_ERROR'.
       27   CATCH cx_dynamic_check.
       28     WRITE: /1 'CX_DYNAMIC_CHECK'.
       29   CATCH cx_root.
       30     WRITE: /1 'CX_SY_ROOT'.
       31 ENDTRY.
       32
       33 &----
       34 *&      Form  LIST
       35 &----
    Edited by: Klaus Babl on Oct 22, 2008 6:42 AM

  • SELECT on TIMESTAMP field from ABAP with EXEC SQL

    Hello,
    I'm trying to get a field of one table which is defined as TIMESTAMP. MaxDB parameter DATE_TIME_FORMAT is set to INTERNAL. When I do the SELECT in SQL Studio I get ISO format 'YYYY-MM-DD HH:MM:SS.MMMMMM' back. So I tried a SELECT with ISO in WHERE clause, but I'm always getting a shortdump with this error:
    Database error text........: "POS(82) Invalid date input value"
    Database error code........: "-3065"
    Then I did a SELECT without a WHERE clause in ABAP and got value '06-FEB-09' back from this field. So I tried with this ABAP statement and got no shortdump, but I also need to add time and not only the date.
      EXEC SQL.
        SELECT recv_time INTO :l_time FROM ztest WHERE sent_recv_time = '06-FEB-09'
      ENDEXEC.
    I'm using Native SQL because the SELECT is on a table which is not located in SAP Schema User. "SELECT recv_time FROM ztest WHERE recv_time = '2009-02-24 10:02:55.888000'" works in SQL studio, but not from ABAP.
    Does anyone know which format I need to specify in the WHERE clause?
    Regards
    Markus Karsch
    Edited by: Markus Karsch on Feb 26, 2009 4:22 PM

    >
    Thomas Theodor Koetter  wrote:
    > Hello Markus
    >
    > I don't know whether this will work from ABAP, but at least MaxDB can internally handle the ODBC literals for time, date and timestamp.
    >
    > Therefore literals like
    >
    > "{d'0001-02-03'}"
    > "{t'01:02:03'}"
    > "{ts'0001-02-03 04:05:06'}"
    >
    > might work. See [http://msdn.microsoft.com/de-de/library/ms190234(SQL.90).aspx]
    >
    >
    > HTH & regards  Thomas
    Hi Thomas,
    Thanks for your help. Unfortunately doesn't seem to work, I get following shortdumps (tried with 3 different notations):
    Database error text........: " "
    Database error code........: "-4005"
    Triggering SQL statement...: "SELECT xxxxxx, status, sent_xxxx_time FROM
    xxx_xxxxxxxxx WHERE sent_recv_time = "{ts'2009-02-06 04:05:06'}""
    Database error text........: "POS(87) Invalid keyword or missing delimiter"
    Database error code........: "-3008"
    Triggering SQL statement...: "SELECT xxxxxx, status, sent_xxxx_time FROM
    xxx_xxxxxxxxx WHERE sent_recv_time = '{ts' 2009-02-06 04:05:06 '}'"
    Database error text........: "POS(81) Missing value specification"
    Database error code........: "-5010"
    Triggering SQL statement...: "SELECT xxxxxx, status, sent_xxxx_time FROM
    xxx_xxxxxxxxx WHERE sent_recv_time = { ts '2009-02-06 04:05:06.000' }"
    Regards
    Markus

  • EXEC SQL / EXECUTE PROCEDURE

    Hi,
    I´ve been asked to develop a program that should be run in background as a job.
    The aim of this program is to select certain data from SAP an then pass it to a DB (sql) outside SAP so that this DB always gets the most updated data.
    I´ve already set up an entry in table
    DBCON.
    My problem is that when I change the DB name in table DBCON the program does not work because it always “remembers” the former entry, that is, it re-uses the stored procedure already used in the former execution of the program. 
    Here goes the code:
      EXEC SQL.
        SET CONNECTION DEFAULT
      ENDEXEC.
      EXEC SQL.
        CONNECT TO 'TOMAS3' AS 'con'
      ENDEXEC.
      EXEC SQL.
        SET CONNECTION 'con'
      ENDEXEC.
      LOOP AT ti_vbap INTO wa_vbap.
        CLEAR: wa_itab, g_input.
        wa_itab-sapOrdID  = wa_vbap-vbeln.
        …………… etc
        CONCATENATE
                    wa_itab-sapOrdID
                    wa_itab-CopPos
                    wa_itab-isbn
                    wa_itab-isbnOLD
                    wa_itab-sta
                    wa_itab-dat
                    wa_itab-pte
                    wa_itab-snu INTO g_input.
    call to the stored procedure that updates the external DB
            EXEC SQL.
              EXECUTE PROCEDURE RefrescaCOPdeSAP_JOBSAP2 ( IN :g_input )
            ENDEXEC.
      ENDLOOP.
    *Close connection to external DB
      EXEC SQL.
        DISCONNECT 'con'
      ENDEXEC.
    Is there an statement like BEGIN TRANS… / COMMIT that is missing?
    Have you got an example so that I may have an idea of how to deal with this situation?.
    Best regards.

    Hi,
    i think i´ve found out where the problem is.
    In table
    DBCON i´ve got the following entry:
    MSSQL_SERVER=1XX.X0.X.X2 MSSQL_DBNAME=ESPAÑA
    it seems as if the character 'Ñ' causes the connection to fail.
    i´ve tried to connect to another DB where MSSQL_DBNAME=ESPANA (coy of the former one) and there was no problem.
    could it be that the character 'Ñ' is the cause of the problem?.Best regards.

Maybe you are looking for

  • How to display Base values (AFS Grid) in the Report

    Hi Friends, We ar using AFS, in that we have Grid value like 0003A34 (8 chars: first 4 chars colour (0003), A represents Cup, 34 represents size of the Material), in that we can able to store the Base values like for International or US, and for size

  • Import statement question

    what's the difference between import java.util.Vector; and import java.util.*; is there any difference in bytecode generated? or time takes to compile? what's the best practice?

  • Proxy Login

    Urgent help needed. I am very confused with how my applets perform on my intranet. When the applets are loaded on a machine within the domain the server is held, there is no problem as to what the applets can do, but when they are loaded outside the

  • How can I "unrevision" a script?

    I've went through a couple of revisions on my script and want to start new with all existing revisions collpsed into a new version. So no different colors and almost blank pages. All the best, Jochen

  • Note: ImageViewer.java uses or overrides a deprecated API.

    hi, iam gettin this error after compilation Note: ImageViewer.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. & am running it on j2sdk1.5.0 Plzzz help