SQL in ABAP

Hi!
Someone can explain me the process to read database tables with sql in abap, and where can i see this tables.
Thanks. Bty.

Hi,
If you want to see the table definition in SAP, go to transaction SE11 and give your table name and click Display.
If you want to see the data in the table, go to transction SE16 and give your table name and click Table contents and execute.
You can use select statement in ABAP to fect data from database tables.
Click the below link to know more in the SAP Help Documentation.
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3969358411d1829f0000e829fbfe/frameset.htm
Thanks,
Ramakrishna

Similar Messages

  • Reading BLOB in Native SQL from ABAP program

    Hello,
    I'm trying to read content of a BLOB field from a table with Native SQL in ABAP like this:
    DATA: l_bytes type xstring.
    EXEC SQL.
      SELECT bytes INTO :l_bytes FROM tablename
    ENDEXEC.
    But when I'm using xstring it returns only 32768 bytes. When using type x length 65000 for l_bytes it returns 65000 bytes, but x is limited to 65535 bytes only. So why it returns only 32768 bytes in direct sql? For DB2 I found note 610342 where you need to add \lob to the statement, I tried with Oracle but doesn't work.
    DATA: CLOB_VAR TYPE STRING.
    DATA: BLOB_VAR TYPE XSTRING.
    EXEC SQL.     
      SELECT FCLOB, FBLOB FROM ZZTAB        INTO :CLOB_VAR\lob, :BLOB_VAR\lob
    ENDEXEC.
    Regards
    Markus

    Hi Markus,
    you have to read it in chunks (remember a blob could be up to 4 Gbyte!).
    I assume you store the byte stream in the field (no bfile pointer to a file ).
    Give you a pseudocode that you get the picture.
    Would recommend that you read the Oracle manual (db Version?)
    9i
    http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_lob2.htm#1008611
    10g
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#ARPLS600
    chunksize = 32768 .  " or use 65000 . This is the amount of the blob part you want to read
    offset = 1.
    *get the row of interest and retrieve blob's length
    Exec sql.
    select  dbms_lob.getlength(your_blob)  :blob_length from blob_table where my_primary_key = 1
    end exec.
    *calculate times to read from blob  until the end (well, leave the adjustment to you
    * in case of an uneven  fraction)
    ntimes = blob_length / chunksize .
    Do ntimes
    *loop and get the chunks into your variable:
    * start reading from offset chunksize of bytes
    exec sql.
    select dbms_lob.substr(your_blob, :chunksize,:offset) into  :xblobvar  from blob_table
    where my_primary_key = 1
    endexec.
    *don't know what you want to do with the blob chunk...
    *process  :xblobvar
    offset = chunksize * ntimes .
    enddo.
    bye
    yk

  • Are there any risks to use native sql in ABAP to access external DB

    here is a requirement to use native sql in abap program to access external DB to load some data into sap. Are there any risks and effects which SAP not recommend ?
    Can anybody show some official document to me because I want to know some risks and dangerous to report to my manager..thanks very much.

    hi Anversha s 
    thank you for your reply
    I means what's the risk when to use native sql to access external DB..
    can you show me some examples about open sql which is used to access external DB...
    Now I am investigating the technique about the connection
    between SAP (by abap program) and external DB...the supporter suggestion is to use native sql to access external DBs.but my manager is afraid of the risks when to use native sql,So I have to report the effective document (example: SAP official document) to explain  to my manager.
    thanks very much

  • Native SQL in ABAP

    I need a query or stored procedure to get data from a table name specified by a variable (here 'TableName').
    The stored procedure would be called everytime with a parameter that specifies the tablename to be queried.
    The following piece of code works in Oracle, but when I use it in ABAP it gives a 'Table Access Error'.
    DECLARE @Query varchar(300), @TableName varchar(30)
    SET @TableName = 'Tab1'
    SET @Query = 'SELECT * FROM ' + @TableName
    EXEC (@Query)
    Please help me out.

    Hello again,
    Sorry for the misunderstanding!!
    Have you tried to concatenate the table??
    I mean to concatenate the values as a string??
    I have never done it before, but it could work. Try to write it like a dynamic select:
    column_syntax = `car name plate`.
    dbtab_syntax = `zcars_names`.
    SELECT (column_syntax)
           FROM (dbtab_syntax)
           INTO CORRESPONDING FIELDS OF TABLE itab.
    try to concatenate or assign a value on a string variable.
    myvar = 'tab1'
    SET @TableName = myvar
    Will it work, i dont know?? Try it!!...
    Be careful with the quotation marks...you know how SQL make us crazy with it!!
    Gabriel
    Message was edited by: Gabriel Fernando Pulido V.

  • SAP BW 7.4 on MS SQL- With ABAP & JAVA Stack as same SID

    Dears,
    If you have any experience or idea for SAP NetWeaver Business Warehouse 7.4 installation on MS SQL or Oracle Database with ABAP Stack and Java Stack as same SID.
    Kindly help for this possibility.
    Regards,
    Sri

    Hi Experts,
    Great for viewers.
    But still expecting some ideas above questions kindly answer.
    Also i got some important points.
    Java Stack for BW on HANA
    At least any one answer the purpose of BW Java Stack.
    Regards,
    V Srinivasan

  • Using Native SQL in ABAP for DB2 database

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

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

  • Accessinng Table using Native SQL in ABAP Program

    Hi Experts,
    I need to access a table that is created in Oracle.
    But while writing a select query as below:
      EXEC sql.
       SELECT MAX(ID_EVENTO)
         INTO :LV_ID_EVENTO
         FROM ZTAB.
      ENDEXEC.
    I am getting a dump saying "ZTAB doesnot exist" or IF I use ZTAB@ifsap then it dumps saying "Database name is missing a component".
    Do I need to add some suffix to the table name like @ifsap to ZTAB?
    Also, can I use SY-SUBRC to check to the success and failure for SELECTION OR INSERTION Operation?
    Thanks
    Depesh

    Hello,
    Try using SAP<SID>.ZTAB in your query.
    For example SAPC05.ZTAB
    Regards,
    Yoganand.V

  • How to use Dynamic SQL in ABAP

    If I have mara table and I have an selection screen where I have allowed user to select the fields of MARA,Now What I want is depending on his selection we should be able to execute the sql command.
    E.g.
    Tables: mara.
    selection-screen
    MATNR , ERSDA , ERNAM , MTART , MEINS.
    NOW THE OUTPUT SHOULD BE ABLE TO DISPLAY ONLY THE SELECTED FIELD VALUE.

    Hello Nandan,
    Try the following code. It works.
    tables: mara.
    data: tablename  type tabname,
          fname      type fieldname,
          fieldnames type fieldname occurs 0.
    field-symbols : <fs_tableline> type any,
                    <fs_fieldval>  type any.
    initialization.
      tablename = 'MARA'.
      assign (tablename) to <fs_tableline> .
      fname = 'MATNR'.
      append fname to fieldnames.
      fname = 'MTART'.
      append fname to fieldnames.
    select (fieldnames)
      from (tablename)
      up to 20 rows
      into corresponding fields of <fs_tableline>.
      loop at fieldnames into fname.
        assign component fname of structure <fs_tableline> to <fs_fieldval>.
        write : <fs_fieldval>.
      endloop.
      new-line.
    endselect.
    The <b>tables</b> statement is very important. You should at least have the list of the tables which you expect the user to enter.
    Please do get back if you have any doubts. If you think the question is answered, please reward the points to the useful answers and close the thread.
    Regards,
    Anand Mandalika.

  • How to specify a particular index for DB2 database when using SQL in ABAP

    Is this format for Oracle?
      select *
       into -
       from  vbrk CLIENT SPECIFIED
    where erdat in erdat
        and mandt EQ sy-MANDT
        %_HINTS ORACLE 'INDEX("VBRK" "VBRK~ZER")'
    For the index 'VBRK~ZER' was defined before,it only includes one field 'VBRK-ERDAT'.
    How can i tell Sap to use this index while processing SQL in DB2?
    Thanks advance.

    There are different hints for the different database platforms.
    For up-to-date information please read the SAP notes, search 'hint DB2'.
    Siegfried

  • Native SQL from ABAP - ORA 02396 max idle time exceeded

    Hello,
      I am trying to read a table outside of the R/3 environment using native SQL statements. I'm getting the data just fine. But every other time (depending on elapsed time), I get the ORA-02396 exceeded maximum idle time, connect again. Here's the SQL code I'm using and I'm obviously not getting disconnected but I'm not sure why. Any help?
    Open a native SQL connection.
      EXEC SQL.
        connect to 'ONECD'
      ENDEXEC.
    Retrieve information from the BVER tables.
      EXEC SQL PERFORMING read_dental.
        select emp_ssn_num, emp_fname, emp_lname,
               to_char(start_date, 'YYYYMMDD') as start_date,
               rec_type,
               to_char(eff_date, 'YYYYMMDD') as eff_date,
               vendor_plan_id
            into :dental
            from opr$8oc.BVER_CURR_DENTAL_MASTER
      ENDEXEC.
      EXEC SQL PERFORMING read_medical.
        select emp_ssn_num, emp_fname, emp_lname, rec_type,
               to_char(start_date, 'YYYYMMDD') as start_date,
               to_char(eff_date, 'YYYYMMDD') as eff_date,
               network_code, pcp_number, patient_flag,
               vendor_plan_id,
               to_char(network_eff_date, 'YYYYMMDD') as
                       network_eff_date,
               to_char(pha_eff_date, 'YYYYMMDD') as
                       pha_eff_date
             into :medical
             from opr$8oc.BVER_CURR_MEDICAL_MASTER
      ENDEXEC.
    Disconnect from the native SQL connection.
      EXEC SQL.
        DISCONNECT 'ONECD'
      ENDEXEC.
    The system log has messages like 'Work process is in reconnect status' and 'Work process has left reconnect status' after the ORA-02396 message. And I specifically do a disconnect at the end and a connect at the beginning, but it looks like it is trying to do a reconnect?
    Thanks,
    Diane

    Hi Daine,
    Oracle Parameter IDLE_TIME set by the administrator.
    1. Since you are using Secondary database
       connection, the connection must
       have been made with the help of BASIS Team.
    2. This secondary database ORACLE
       has some settings/parameters
       which have been set to say 10 minutes, 60 minutes etc.
       , so what happens,
       if there is NO ACTIVITY / NO SQL / NO INTERACTION
       with the database ,
       the connection is IDLE
       and hence ORACLE then disconnects by itself.
    3. Contact your basis team / oracle administarotr
      team to INCREASE this setting.
      (they do it for some security purpose, firewall etc)
    I hope it helps.  
    Regards,
    Amit M.
    Message was edited by: Amit Mittal

  • Reset or Bypass SQL Buffer ABAP Program

    Hi,
    How to bypass or reset the use of the buffer table in an ABAP program with the purpose of evaluating their performance access. I can not change the program because it is in production.
    Thanx.
    Diovani

    Hi ,
    I am giving you the SAP standrad help  comments here  as prescriblely :
    FROM clause
    Specifies the database tables from which the data in the selection in the SELECT clause is to be read.
    Syntax
    ... FROM [<tab> [INNER]|LEFT [OUTER] JOIN] <dbtab> [AS <alias>]
                                   [ON <cond>]
             [CLIENT SPECIFIED]
             [BYPASSING BUFFER]
             [UP TO <n> ROWS]
    You can read a single table <dbtab> or more than one table, using inner and outer joins to link tables with conditions <cond>, where <tab> is a single table or itself a join condition. You can specify individual database tables either statically or dynamically, and you can replace their names with an alternative <alias>. You can bypass automatic client handling with the CLIENT SPECIFIED addition, and SAP buffering with BYPASSING BUFFER. You can also restrict the number of lines read from the table using the UP TO <n> ROWS addition.
    For More Information please see this link  : using keyword  in find "BYPASSING BUFFER"
    Link: [http://help.sap.com/saphelp_46c/helpdata/en/87/56d00722c011d2954a0000e8353423/frameset.htm]
    Regards,

  • How would you write tthis oracle sql in ABAP. Thank you verry verry much

    SELECT
    to_char(sum(dmbtr)),s.budat,shkzg,hkont
    FROM
    sapr3.bsas s,
    sapr3.bkpf k
    WHERE
    s.belnr=k.belnr AND s.gjahr=k.gjahr AND s.bukrs=k.bukrs AND k.bukrs='02' AND k.gjahr>=EXTRACT(YEAR FROM ADD_MONTHS(SYSDATE,-12)) GROUP BY s.budat,shkzg,hkont;

    GO THRU THE JOINS IN SELECT STATEMNET IN ABAP.
    I JOINED FOUR TABLES WITH DECLARED FIELDS.
    DATA: BEGIN OF I_KNA1 OCCURS 1,
          KUNNR LIKE KNA1-KUNNR,
          LAND1 LIKE KNA1-LAND1,
          NAME1 LIKE KNA1-NAME1,
          ORT01 LIKE KNA1-ORT01,
          END OF I_KNA1.
    DATA: BEGIN OF I_VBAK OCCURS 1,
          KUNNR LIKE VBAK-KUNNR,
          VBELN LIKE VBAK-VBELN,
          ERDAT LIKE VBAK-ERDAT,
          ERNAM LIKE VBAK-ERNAM,
          END OF I_VBAK.
    DATA: BEGIN OF I_VBAP OCCURS 1,
          VBELN LIKE VBAP-VBELN,
          POSNR LIKE VBAP-POSNR,
          MATNR LIKE VBAP-MATNR,
          CHARG LIKE VBAP-CHARG,
          END OF I_VBAP.
    DATA: BEGIN OF I_MARA,
          MATNR LIKE MARA-MATNR,
          MBRSH LIKE MARA-MBRSH,
          MTART LIKE MARA-MTART,
          MEINS LIKE MARA-MEINS,
          END OF I_MARA.
    DATA: BEGIN OF I_DEST OCCURS 1,
          KUNNR LIKE KNA1-KUNNR,
          LAND1 LIKE KNA1-LAND1,
          NAME1 LIKE KNA1-NAME1,
          ORT01 LIKE KNA1-ORT01,
          VBELN LIKE VBAK-VBELN,
          ERDAT LIKE VBAK-ERDAT,
          ERNAM LIKE VBAK-ERNAM,
          POSNR LIKE VBAP-POSNR,
          MATNR LIKE VBAP-MATNR,
          CHARG LIKE VBAP-CHARG,
          MBRSH LIKE MARA-MBRSH,
          MTART LIKE MARA-MTART,
          MEINS LIKE MARA-MEINS,
          END OF I_DEST.
    SELECT KKUNNR KLAND1 KNAME1 KORT01 VVBELN VERDAT VERNAM PPOSNR
    PMATNR PCHARG INTO TABLE I_DEST FROM KNA1 AS K INNER JOIN VBAK AS V ON
    KKUNNR = VKUNNR INNER JOIN VBAP AS P ON VVBELN = PVBELN INNER JOIN
    MARA AS M ON PMATNR = MMATNR.
    LOOP AT I_DEST.
    WRITE: / I_DEST-KUNNR, I_DEST-LAND1, I_DEST-NAME1, I_DEST-ORT01,
    I_DEST-VBELN, I_DEST-ERDAT, I_DEST-ERNAM, I_DEST-POSNR, I_DEST-MATNR,
    I_DEST-CHARG, I_DEST-MBRSH, I_DEST-MTART, I_DEST-MEINS.
    ENDLOOP.
    CHEERS.

  • How to access External SQL via ABAP/4?

    Hi,
    I have maintailed connection via tcode DBCO, and tried to connect to external SQL server via following codes, but failed all the time, can anybody tell me how to do?
    EXEC SQL.
    CONNECT TO 'DAN1'
    ENDEXEC.
    EXEC SQL.
    SET CONNECTION 'DAN1'
    ENDEXEC.
    EXEC SQL.
    Thanks and best regards.

    check...
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/05058e8d-0c01-0010-c986-fdc8eaebf37c

  • Dynamic SQL in abap

    i have a requirement to retrieve only selected fields from db table. i have to use this code with jco, so i can't go with ALV. my requirement is as follows,
    list of fields from mara and marc table will be shown as checkbox and user will be allowed to select the required fields. that selected fields only retrieved from the table. please gimme some idea.
    Thanks in advance.

    Hii
    data : lv_tab(8) type c ,
              lv_from(200) type c ,
              lv_where(1024) type c ,
              lv_fld(200) type c,
              lv_temp_kbetr type konp-kbetr .
       concatenate 'mara' into lv_tab .
       concatenate lv_tab ' inner join marc on ' into lv_from separated by
       space .
       concatenate 'mara~matnr = marc~matnr' into lv_from .
    loop  at itab where chk = 'X'.
       concatenate lv_fld itab-fld into lv_fld.  
    endloop.
    select single (lv_fld)
         into lv_temp_kbetr
         from  (lv_from)
         where WERKS = <input>.
    Kindly check the code above, it would be like that.
    Many Thanks/  HImanshu Gupta

  • Remote Connection from SAP to MS-SQL server

    Hello Experts,
    We have been following 2 options so far and we have come across some issues
    The first Option is to call a stored procedure (this is our preferred method) which does the data transfer for us
    We have been able to test this scenario successfully from SQL Server side
    However, while calling the stored proc via native SQL from ABAP we have come across an issue which is due to SQL 2005 changes (Schema implementation and difference in the security context)
    While calling the stored procedure from the ABAP Code we have an error
                The program short dumps with runtime error DBIF_DSQL2_SQL_ERROR, exception CX_SY_NATIVE_SQL_ERROR. The database error code is 15274, and the error text is
                 "Access to the remote server     is denied because the current security context is not trusted."
    This issue is new after the SQL Server 2005.
    We are trying to resolve that.
    Secondly we have been trying the DBCON option as well as per OSS Note 323151
    We have a few things thatu2019s impacting our scenario:
    The remote servers are in a different domain
    The remote servers are located  in DIZ
    Remote server is a named instance
    Remote server has been configured with a different port than standard (1565) u2013 All Connection strings will need port in there
    The Database name starts with a numeric value
    Due a combination of factors as mentioned above the standard approach does not work
    Have any of you used this approach while connecting from SAP to MS-SQL server? Do you know of any successful methods to connect to SQL using ABAP (or not) from SAP.
    Thanks in advance,

    Yes,
    DBConnect & UDConnect.
    Works like a charm.
    We write data into a MS-SQL database via DBConnect & an ABAP program (using open sql).

Maybe you are looking for

  • How to get set file name for MessageFileUploadBean in Advanced Table

    Hello Everyone.     I have a MessageFileUpload item in a advanced table. My requirement is to show file names instead of view when user uploads files. I know how to do this if the item is not inside advancedtable  (by using  uploadBean.setAttributeVa

  • Magsafe caught on fire!

    hey everyone... when using my macbook pro today my magsafe caught on fire and melted. there was a bright flame and lots of smoke. the smell was terrible. i quickly pulled the cord from my computer and disconnected it from the wall. I was lucky that i

  • Line item and Cardinality (DB2)

    I have 2 issues with a cube. Issue 1: I read everywhere in this forum that if Line Item is marked for a dimension that there will be no index/sid table for this dimension. In stead the sid table of the InfoObject would be used. I have however an exam

  • Data source failure in process chain.

    Dear All, Iam getting data from 2LIS_13_VDHDR today the process chain got failed the error is as follows: There is no active delta initialization for this. IS/QS/DATA source This chain got failed from 2 days please as it is of high prority give ur va

  • My iPhone will not sync to my iTunes

    OK, my iphone will not sync with my itunes. My phone is updated to iOS 7.0.4  and my itunes is updated to the 11.1.3 or whatever it is. I had over 1000 songs on my phone. When I hooked it up to sync some more music it deleted over 400 songs that I di