Select from database dynamically

Hello colleague,
i am trying to read a database whose name is dynamically identified. There are several fields but i am interested in one. I want all the entries for that field in the table. The field "trace_fct_id" is type SYSUUID_x(16). I want it to be populated in the CHAR32 field ie GUID.
  LOOP AT lt_tabname INTO ls_tablename.
    CREATE DATA dref TYPE STANDARD TABLE OF (ls_tablename-name).
    ASSIGN dref->* TO <itab>.
    SELECT DISTINCT trace_fct_id FROM (ls_tablename-name) INTO CORRESPONDING FIELDS OF TABLE <itab>.
    MOVE <itab> TO et_func_ids.
  ENDLOOP.
I get all the entries from the table but i just want to return the ID, and the move does not copy it in the internal table as the column name is different.
Could you please help?
Thanks in advance.
Best Regards,
Piyush

Check if this helps:
DATA: dref TYPE REF TO data,
      lt_tabname TYPE STANDARD TABLE OF tabname,
      ls_tablename TYPE tabname,
      et_func_ids TYPE STANDARD TABLE OF sysuuid_x,
      es_func_ids TYPE sysuuid_x.
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE,
               <wa> TYPE ANY ,
               <val> TYPE ANY.
DATA: v_err TYPE string,
      lcx_root TYPE REF TO cx_root.
LOOP AT lt_tabname INTO ls_tablename.
  CREATE DATA dref TYPE STANDARD TABLE OF (ls_tablename).
  ASSIGN dref->* TO <itab>.
  TRY .
      SELECT DISTINCT trace_fct_id FROM (ls_tablename)
      INTO CORRESPONDING FIELDS OF TABLE <itab>.
      CHECK sy-subrc = 0.
      LOOP AT <itab> ASSIGNING <wa>.
        ASSIGN COMPONENT 'TRACE_FCT_ID' OF STRUCTURE <wa> TO <val>.
        CHECK sy-subrc = 0.
        es_func_ids = <val>.
        APPEND es_func_ids TO et_func_ids.
        CLEAR et_func_ids.
      ENDLOOP.
    CATCH cx_sy_open_sql_error INTO lcx_root."Catch block for SQL errors
      v_err = lcx_root->get_text( ).
      WRITE: / v_err.
  ENDTRY.
  REFRESH <itab>.
ENDLOOP.
BR,
Suhas

Similar Messages

  • LTR - Error occurred when selecting from database

    Hi,
    We created couple of configurations using LTRC in our SLT systems. When i try to check these in transaction LTR, they are not displayed, just getting the error - Error occurred when selecting from database (Attached screenshot). All the required SICF for SLT has already been activated. Any suggestions how to fix this issue?
    Thanks,
    Saravanan

    Hi Experts,
    Did anybody get the solution of this error ,if yes please reply?
    I am getting below error when I am refreshing the current config or creating a new one in LTR
    " Error occurred when selecting from database"
    Thanks for your help,
    Balwant

  • Dynamic table  selection from database

    Hi ;
    I want to create  variable field that I will use at database selection.I tried to do it with   select *  from ( tabname )..... but I couldn't do it how you any offer fot this issue.

    Hi,
    DATA FCAT1 TYPE LVC_T_FCAT."fieldcat of type internal table
    DATA:DYN_ITAB TYPE REF TO DATA,"holding the dynamic internal table
    WA TYPE REF TO DATA."holding the wa for dynamic internal table
    FIELD-SYMBOLS: <DISP_TABLE> TYPE TABLE,
    <WA> TYPE ANY.
    SELECT SINGLE tab_name FROM table INTO DB_TABLE.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
            EXPORTING
              I_STRUCTURE_NAME = DB_TABLE
            CHANGING
              CT_FIELDCAT      = FCAT1[].
    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE"creating dynamic internal table using fieldcat
        EXPORTING
        IT_FIELDCATALOG = FCAT1[]
        IMPORTING
        EP_TABLE = DYN_ITAB.
        ASSIGN DYN_ITAB->* TO <DISP_TABLE>."creating internal table by refering the dynamically generated internal table structure
        CREATE DATA WA LIKE LINE OF <DISP_TABLE>."creating work area for the internal table
        ASSIGN WA->* TO <WA>.
        SELECT * FROM (DB_TABLE) INTO <WA> UP TO MAX_HITS ROWS."filling the internal table
        APPEND <WA> TO <DISP_table>.
        ENDSELECT.
    <b>REWARD ALL HELPFUL ANSWERS.</b>
    rgds,
    bharat.
    Message was edited by:
            Bharat Kalagara

  • Creating and selecting from a dynamic table

    Hi,
    Iam trying to create a table dynamically and selecting from it in same plsql block, but am getting "table doesnot exist" error. however if i just create a table dynamically and then do a select on it seperately it works..
    below is sample code for the same,
    working
    Line: -----
    DECLARE
    loc VARCHAR2(20):='bglr';
    l_cnt pls_integer;
    BEGIN
    -- create an employee information table
    EXECUTE IMMEDIATE
    'CREATE TABLE ' || 'emp_bglr' ||
    empno NUMBER(4) NOT NULL,
    ename VARCHAR2(10),
    job VARCHAR2(9),
    sal NUMBER(7,2),
    deptno NUMBER(2)
    end;
    select count(*) from emp_bglr ...works and return me 0 rows
    Line: -----
    but when i include select in plsql block ..it throws "Table does not exists" error...(iam running below plsql block after dropping the created table)
    not working
    Line: -----
    DECLARE
    loc VARCHAR2(20):='bglr';
    l_cnt pls_integer;
    BEGIN
    -- create an employee information table
    EXECUTE IMMEDIATE
    'CREATE TABLE ' || 'emp_bglr' ||
    empno NUMBER(4) NOT NULL,
    ename VARCHAR2(10),
    job VARCHAR2(9),
    sal NUMBER(7,2),
    deptno NUMBER(2)
    --COMMIT;
    END;
    Select count(*) into l_cnt from emp_bglr;
    dbms_output.put_line('cnt is '||l_cnt);
    end;
    Line: -----

    Becuase your code is first checked for syntax/object existance during compilation and throws an error saying the table does not exist.
    Try this:
    SQL> ed
    Wrote file afiedt.buf
      1   DECLARE
      2   loc VARCHAR2(20):='bglr';
      3   l_cnt pls_integer;
      4   BEGIN
      5   -- create an employee information table
      6   EXECUTE IMMEDIATE 'CREATE TABLE emp_bglr(
      7   empno NUMBER(4) NOT NULL,
      8   ename VARCHAR2(10),
      9   job VARCHAR2(9),
    10   sal NUMBER(7,2),
    11   deptno NUMBER(2)
    12   )';
    14  Select count(*) into l_cnt from all_objects where object_name = 'EMP_BGLR';
    15  dbms_output.put_line('tab cnt is '||l_cnt);
    16  IF (l_cnt = 1) THEN
    17  l_cnt := 0;
    18  EXECUTE IMMEDIATE 'SELECT count(*) from apps.emp_bglr' into l_cnt;
    19  dbms_output.put_line('data cnt is '||l_cnt);
    20  END IF;
    21* end;
    SQL> /
    tab cnt is 1
    data cnt is 0
    PL/SQL procedure successfully completed.
    SQL> Edited by: AP on Aug 5, 2010 5:51 AM
    Edited by: AP on Aug 5, 2010 5:52 AM

  • Why does "SELECT * FROM [database].[schema].[table]" not work in Azure ?

    Hi all
    In Microsoft Azure I have 2 databases.
    I work since more than 10 years with T-SQL and I always use
    fully qualified object names, means "[database].[schema].[table]".
    When I now make a connection to my database "A" in Azure and
    write a Query against database "B" ("SELECT * FROM [B].[schema].[table]")
    I get an exception. Of course when I connect to database "B" it works
    but again not to database "A". When I use "SELECT * FROM [schema].[table]"
    with the right database connected, it also works in Azure.
    Hope you understand what I mean :-)
    In MS-SQL, this of course works fine.
    Well my question is: What sense does this make ??
    Do I now have to re-write everything just for azure or will this behavior changed sometimes ?
    I know MS-SQL is not the same like Azure-SQL, but hey; does Microsoft think all projects have only one database ?? :-)
    Thanks for any answer
    Frank

    Hi Frank,
    According to your description, you want to retrieval data cross database in SQL Azure, right?
    As June said, Currently cross database joins are not supported in SQL Azure. Also you cannot change database mid query so you cannot, for example, put a USE [MyDB] in your query either. Please refer to the link below to see the details.
    http://www.britishdeveloper.co.uk/2011/11/cross-database-joins-in-sql-azure.html
    If you have any concern about this behavior, you can submit a feedback at
    http://connect.microsoft.com/SQLServer/Feedback and hope it is resolved in the next release of service pack or product. Your feedback enables Microsoft to make software and services the best that they can be, Microsoft might consider to add this feature
    in the following release after official confirmation.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Procedure containg select from Database link

    Hi,
    I have one database link xxx which is getting some data from one table from Sqlserver database.
    Now I am writing one procedure which contain
    if(c=1) --get from databaselink
    select name,num from table1@xxx;
    else --get from the Oracle table;
    Now iam calling that procedure from .net application which is giving the following error :ORA-01002: fetch out of sequence
    ORA-02063: preceding line from FSPDEV_TO_AVERY_ORGRPT
    it is giving the above error if c=1 otherwise the else part is working fine.
    What i need to do?
    Thanks

    Hi,
    Thanks for your response.
    my procedure is like this:
    Cur_Out sysrefcursor
    if(c=1) --get from databaselink
    Open Cur_out for
    select name,num from table1@xxx;
    else --get from the Oracle table;
    Open Cur_out for Select from Oracle table;
    I will try to execute the procedure from SQLPLUS.
    thanks

  • Selection from database tables

    Hi Experts,
    In one program I'm selecting data from tables <b>VBAK, VBAP,VBRK,VBRP,LIKP,LIPS</b>. As the tables have huge data, it's taking forever to get the data into internal tables.
    Could you please suggest  me to better the performance.
    Thnx much.

    hi dev,
      do not use select .. endselect statement and include all the key fields in your select statement.
    instead of select .. endselect statement use
    select * from <table> into table itab where < conditions)
    Regards,
    Santosh
    Message was edited by: Santosh Kumar P

  • Selecting from database view

    is it the same to get the values from view and table?
    plz help me with example...

    Yes its the same:
    SELECT *  FROM <view / table> INTO TABLE ITAB WHERE <condition>.
    Provided the ITAB is having view / table structure.
    Thanks

  • Select from database table

    Hi Experts,
    I have a database table having fields
    entity account period category value  filename
    A         1         001      ABC       100   abc.xls
    A          1        002      ABC        200  abc.xls
    B         2         001      DEF        300   sef.xls
    I now need to update a control table from the database table which will select all the distinct filenames , from the database table .
    how to do this
    Thanks
    Ankit

    Hi,
       In the select query write:
    select distinct ( filename) from dtab.

  • Select from a dynamically chosen table

    Hi everyone,
    I'm willing to retrieve information stored in a given column of a given table, both generated dynamically. Thus, I have a string S1 with the table name and a string S2 with a column name of this table.
    My aim would be to do something like that :
    +select single * into corresponding fields of X
    from (S1)
    where Y = 'SomeValue'.+
    X being like a line of the table (S1)
    Y being the column name stored in S2.
    But for this, I need to fine a correct way to define X and Y from S1 and S2, which I failed to do until now. My first idea was to use field-symbols but it didn't help me. It might be quite easy or maybe impossible, I don't even know as my knowledge in ABAP is far from being excellent, but any reply would be welcome.
    Best regards,
    François

    Hi,
    if you only want to select only the given column(s)
    (here 'BUTXT') use the 2nd alternative:
    REPORT  YMI_SG_NACHWEIS_A NO STANDARD PAGE HEADING.
    FIELD-SYMBOLS:
    <t001>, <fs>.
    DATA:
    lr_t001 TYPE REF TO data.
    CONSTANTS:
    s1(30) VALUE 'T001',
    s2(30) VALUE 'BUKRS',
    s3(30) VALUE 'BUTXT'.
    DATA:
    lt_where(72) OCCURS 0 WITH HEADER LINE,
    lt_field(72) OCCURS 0 WITH HEADER LINE.
    append s3 to lt_field.
    CREATE DATA lr_t001 TYPE (s1).
    ASSIGN lr_t001->* TO <t001>.
    ASSIGN (s1) TO <fs>.
    CONCATENATE s2 '=' '3000' INTO lt_where SEPARATED BY space.
    APPEND lt_where.
    SELECT *
    INTO <t001>
    FROM (s1)
    WHERE (lt_where).
      ASSIGN COMPONENT s3 OF STRUCTURE <t001> TO <fs>.
      WRITE: / s3, ': ', <fs>.
    ENDSELECT.
    *2nd alternative
    skip 2.
    write:/'2nd'.
    uline.
    select (lt_field) into corresponding fields of <t001>
    FROM (s1)
    WHERE (lt_where).
      ASSIGN COMPONENT s3 OF STRUCTURE <t001> TO <fs>.
      WRITE: / s3, ': ', <fs>.
    ENDSELECT.
    grx
    Andreas

  • Problem while populating data from database dynamically.

    I am having two combo box
    First one displays list of table Names
    Second one displays list of the corresponding field Names.
    Now when the user selects the table name the corresponding field names appear in the second combo box & now when the user selects the field name then the requirement is to get the data of the corressponding field of the table on the screen on the button click.
    I want to do this thing dynamically through coding.
    My requirement is only the data of those columns that have been queried should appear on the screen whereas other column data should not appear.
    Can any body help me out.

    I'm not sure if you want to populate the combobox dynamically based on any selected data source.
    If so it is kind of tricky, but do-able. You need to write little bit of coding yourself.
    First you need to get the Database metadata. For details see
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html
    where you can get the table names.
    Then using the result set metadata of the selected table you can get the column information. For details see
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSetMetaData.html
    If you want to display the data of selected table and column value (statically filled combo box), then it is easy.
    you can create your own SQL statement based on the selected tabe and column and set it to the rowset dynamically in the code (may be in the method beforerenderresponse).
    - Winston

  • Populating drop down menu's from database dynamically

    Hi
    I m facing a problem of populating the drop down menu from a MS Access database using JSP. But i m not able to do it. Can you please help me out?
    this works perfectly for textarea
    <textarea cols="20" rows="20">
    <% for(int i =1; i <=rsmd.getColumnCount();++i)
    out.println(rsmd.getColumnName(i)); %>
    </textarea>
    but for drop down box it gives problems
    Heres the code!
    <select name="aa" ID = "aa">
    <option value="<% for(int i =1; i <= rsmd.getColumnCount();++i)
    out.println(rsmd.getColumnName(i)); %>" > </option>
    </select>
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 61 in the jsp file: /gv/event.jsp
    Generated servlet error:
    i cannot be resolved
    wat can be the alternative? Please hlp
    Regards
    Sami

    Hi i m facing a problem in jsp while filling the dropdown box<select name="combosubject"  width="10%" maxlength="20"/>
                                  <option ></option>
                                  <%
                                                System.out.println("1st time");
                                                rs=stmt.executeQuery("select subject.name from subject order by name");
                                                while(rs.next())
                                                  subject = rs.getString(1);
                                             %>     
                                             <option ><%=subject%></option>
                                             <%
                             rs.close();
                             stmt.close();
                       %>the problem is that when i execute this code for the first time it works fine and after that it keeps on throwing exception like "No data found", "Column not found"
    on <form> action i have recalled this function that is when i click the search button this page is executed again and at this moment i got the exception

  • To select from database table based on date range

    hi
    i have a selection screen in which date range is being given
    say eg 23/06/07  to 23/12/08
    based on this date i want to select data from a ztable
    eg i want to select a field amount from table
    and three is a field date range on the table
    for this particular field i want to select all records for amount field  and factual field falling wiithing this date range and sum it
    eg
    based on date range as in selcetion screen
    select amount( field1)  factual ( field2) from ztable into it_ztable where date = ?....
    please give me code for it  and how to sum all values as i will get from the ztable into internal table the two values as fetched from the ztable
    please suggest asap
    regards
    arora

    hi
    i am using
    sELECT field1 field2 FROM Ztable  INto it_matu
                       where DATE GE sl_dat-low    
                        AND  DATE LE sl_dat-high.   
    i am getting data in internal table but
    say i have twelve records now i want to sum it the both the columns into and use that sum final amount to display
    let me know how to use sume in the intrranal tabl do i need to use control statement
    how to use the sum for two columns and take into a serperate variable to display
    regards
    aRora

  • I would like to replace the file dialog box with a programmab​le dialog box, that generates its selections from Database Informatio​n

    Where would be the best place to achieve this?
    I have been thinking about these options:
    - Modification of the Operator Interface.
    - Modification of the Sequence Model.
    - Use callbacks to modify the sequence model.
    - Use callbacks to modify the Engine (ie the Auto.seq example)
    Or combinations of the above.
    The biggest requirement I have in developing this project is in the reuse of code and I believe that callbacks in the seq would be the way to achieve this.
    But I am not familiar with the usage of callbacks in teststand (yet) and I don't know where to look for information/examples on what I can do with them.
    Has anybody done anythin
    g similar?
    Any suggestions would be great!
    Tim

    I am trying to replace the operators interface's sequence file dialog box. I am also trying to hide the standard operators interface.
    What I am after is to replicate a user experience!
    Teststand is being used to replace an ATE written in LV where each of the tests are hardcoded in. The user selected the product and test types from a button based dialog boxes.
    I am using TS to overcome all of the limitations of the original ATE, but one of the requirements is the system has to have the same look and feel of the original.
    I originally though that I would have to modify an operators interface, but I would prefer not too, and would rather change the process models and use engine and station callbacks.
    If I have to change an operatos interface, I would pre
    fer if the changes didn't affect the normal running of standard TS sequences.
    I have attached the process model, i am trying to achieve, (its in Visio).
    Tim
    Attachments:
    ATE_Process_Model.vsd ‏123 KB

  • Select only numbers from database

    Hi All,
    I need to retrieve numerical data's from the database. Data base table has both numerical and text values. now I want to retrieve only numerical data's.
    Can any one help me on this,
    Thanks and helps will be appreciated.

    Hi,
    did you try like this ?
    SELECT * FROM database INTO t_inter WHERE field1 = crit1.
    LOOP AT t_inter into w_intern WHERE field1 CO '0123456789'.
    ENDLOOP.
    or
    LOOP AT t_inter into w_intern.
    CHECK w_intern-field1 CO '0123456789'
    ENDLOOP.
    Regards,
    David

Maybe you are looking for