Dynamic selection need from a table

Hi,
I have a requirement to select the data from a table dynamically. Only during run time I will know the structure of that table & table name. In this case can anyone give any tips/sample code how it can be accomplished. Help appreciated.
Thanks,
Abhi

Sure, check out this sample program.  It is a dynamic table read.
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
       wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
      new_line  type ref to data,
      wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
  clear wa_it_fldcat.
  wa_it_fldcat-fieldname = wa_details-name .
  wa_it_fldcat-datatype = wa_details-type_kind.
  wa_it_fldcat-inttype = wa_details-type_kind.
  wa_it_fldcat-intlen = wa_details-length.
  wa_it_fldcat-decimals = wa_details-decimals.
  append wa_it_fldcat to it_fldcat .
endloop.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table.
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
* Select Data from table.
select * into table <dyn_table>
           from (p_table).
* Write out data from table.
loop at <dyn_table> into <dyn_wa>.
  do.
    assign component  sy-index  of structure <dyn_wa> to <dyn_field>.
    if sy-subrc <> 0.
      exit.
    endif.
    if sy-index = 1.
      write:/ <dyn_field>.
    else.
      write: <dyn_field>.
    endif.
  enddo.
endloop.
Welcome to SDN.  Please remember to award points for helpful answers and mark you post as solved when solved completely.  Thanks.
Regards,
Rich Heilman
Fixed Code
Message was edited by: Rich Heilman

Similar Messages

  • I need below fields at my selection screen.From which table we can find the

    Sales Org > only one selection field
    Division > only one selection field
    Channel > from u2013 to fields
    Sales Office Channel > from u2013 to fields
    Sales Rep Channel > from u2013 to fields
    User ID of the CSR Channel > from u2013 to fields
    Customer Channel > from u2013 to fields
    Material Channel > from u2013 to fields
    Date: Channel > from u2013 to fields
    I need these fields at my selection screen.From which tables I find these things.I need this logic also.

    I need help

  • Dynamic record deletion from database table

    Hi,
    I need to delete selected records from database table(dynamic names). Table names are being passed from main program with some of their field names. The record to be deleted from the database table is being decided based on the fields passed for the table and their contains passed from the main program.
    It is not possible to write dynamic where clause for DELETE statement directly.
    So, I created a dynamic internal table and i am trying to fetch all records using SELECT statement(for which we can write dynamic where condition, something like...SELECT...WHERE (itab).  ) which need to be deleted in the iternal table.
    Piece of code :
              CONCATENATE c_im v_tablefield1 INTO v_imprtfield1.
              CONCATENATE v_tablefield1 c_in v_imprtfield1
                       into s_condition separated by space.
              APPEND s_condition TO t_condition.
              PERFORM GET_DYNAMIC_ITAB USING s_flds_agtab-tabname
                                    changing t_itab.
              ASSIGN t_itab->* TO <itab>.
    *Select the data (to be deleted) from the database table
               SELECT * FROM (s_flds_agtab-tabname) INTO TABLE <itab>
                 WHERE (t_condition).
    *Delete the records from the table
               IF SY-SUBRC = 0.
                 DELETE (s_flds_agtab-tabname) FROM TABLE <itab>.
               ENDIF.
    Here t_condition is of standard table of WHERETXT.
    t_condition at the run time before giving dump was:
    SPART IN IM_SPART
    AND KUNNR IN IM_KUNNR
    Here IM_SPART is renge type of SPART and IM_KUNNR is renge of KUNNR.
    I am getting a DUMP:
    The WHERE condition has an unexpected format.
    Error analysis                                                                               
    The current ABAP/4 program attempted to execute an ABAP/4 Open SQL
    statement containing a WHERE condition of the form WHERE (itab) or
    WHERE ... AND (itab). The part of the WHERE condition specified at
    runtime in the internal table itab contains the operator         
             IN (v1, ..., vn)                                        
    in incomplete form.                                              
    How to correct the error
    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:                                                 
    "SAPSQL_IN_ILLEGAL_LIST"                               
    "SAPLZSD_TAB_REFRESH " or "LZSD_TAB_REFRESHU01 "       
    "Z_SD_REFRESH_AGTABLES"                                
    If you cannot solve the problem yourself, please send the
    following documents to SAP:                             
    I would like to know whether "IN" operator is allowed in (itab) of WHERE clause. While testing I changed the "IN" to "=" specifying a suitable value there. It worked. So please let me know if i can give "IN" operator using renge table in the dynamic where clause.
    Thanking you,
    Surya

    Hi again,  so if you can not use the IN in a dynamic where clause you might be forced to dynamically build the entire select statement,  Here is a sample program which may give you some ideas, notice that we are writing the select statement code, putting it in another program and generating the subroutine at runtime, then call this routine.  I'm sure that this will help you see what you need to do.
    report zrich_0003 .
    tables: kna1.
    types: t_source(72).
    data: routine(32) value 'DYNAMIC_SELECT',
                 program(8),
                 message(128),
                 line type i.
    data: isource type table of t_source,
                xsource type t_source.
    ranges:
            r_kunnr for kna1-kunnr.
    data: ikna1 type table of kna1.
    data: xkna1 type kna1.
    r_kunnr-sign = 'I'.
    r_kunnr-option = 'EQ'.
    r_kunnr-low    = '0001000500'.
    append r_kunnr.
    xsource = 'REPORT ZTEMP.'.
    insert xsource  into isource index 1.
    xsource = 'FORM dynamic_select'.
    insert xsource  into isource index 2.
    xsource = 'Tables r_kunnr ikna1.'.
    append xsource to isource.
    xsource = 'select * into table ikna1 from kna1'.
    append xsource to isource.
    xsource = 'where kunnr in r_kunnr.'.
    append xsource to isource.
    xsource = 'ENDFORM.'.
    append xsource to isource.
    generate subroutine pool isource name program
                             message message
                             line line.
    if sy-subrc = 0.
      perform (routine) in program (program) tables r_kunnr
                                                    ikna1.
    else.
      write:/ message.
    endif.
    loop at ikna1 into xkna1.
      write:/ xkna1-kunnr.
    endloop.
    Regards,
    Rich Heilman

  • Copy selected values from a table control into another table control

    hi there,
    as seen in the subject i need to copy selected values from a table control into another table control in the same screen. as i dont know much about table controls i made 2 table controls with the wizard and started to change the code... right now im totally messed up. nothing works anymore and i don't know where to start over.
    i looked up the forums and google, but there is nothing to help me with this problem (or i suck in searching the internet for solutions)
    i have 2 buttons. one to push the selected data from the top table control into the bottom tc and the other button is to push selected data from the bottom tc into the top tc. does somebody has a sample code to do this?

    you're funny
    i still don't get it... can't believe, there is no tutorial or sample code around how to copy multiple selected rows from a tc.
    here's my code, maybe you can tell me exactly were i have to change it:
    tc1 = upper table control
    tc2 = lower table control
    SCREEN 0100:
    PROCESS BEFORE OUTPUT.
      MODULE status_0100.
      MODULE get_nfo. --> gets data from the dictionary table
      MODULE tc1_change_tc_attr.
      LOOP AT   it_roles_tc1
           INTO wa_roles_tc1
           WITH CONTROL tc1
           CURSOR tc1-current_line.
      ENDLOOP.
      MODULE tc2_change_tc_attr.
      LOOP AT   it_roles_tc2
           INTO wa_roles_tc2l
           WITH CONTROL tc2
           CURSOR tc2-current_line.
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP AT it_roles_tc1.
        CHAIN.
          FIELD wa_roles_tc1-agr_name.
          FIELD wa_roles_tc1-text.
        ENDCHAIN.
        FIELD wa_roles_tc1-mark
          MODULE tc1_mark ON REQUEST.
      ENDLOOP.
      LOOP AT it_roles_tc2.
        CHAIN.
          FIELD wa_roles_tc2-agr_name.
          FIELD wa_roles_tc2-text.
        ENDCHAIN.
        FIELD wa_roles_tc2-mark
          MODULE tc2_mark ON REQUEST.
      ENDLOOP.
      MODULE ok_code.
      MODULE user_command_0100.
    INCLUDE PAI:
    MODULE tc1_mark INPUT.
      IF tc1-line_sel_mode = 2
      AND wa_roles_tc1-mark = 'X'.
        LOOP AT it_roles_tc1 INTO g_tc1_wa2
          WHERE mark = 'X'.    -
    > big problem here is, that no entry has an 'X' there
          g_tc1_wa2-mark = ''.
          MODIFY it_roles_tc1
            FROM g_tc1_wa2
            TRANSPORTING mark.
        ENDLOOP.
      ENDIF.
      MODIFY it_roles_tc1
        FROM wa_roles_tc1
        INDEX tc1-current_line
        TRANSPORTING mark.
    ENDMODULE.                    "TC1_MARK INPUT
    MODULE tc2_mark INPUT.
      IF tc2-line_sel_mode = 2
      AND wa_roles_tc2-mark = 'X'.
        LOOP AT it_roles_tc2 INTO g_tc2_wa2
          WHERE mark = 'X'.             -
    > same here, it doesn't gets any data
          g_tc2_wa2-mark = ''.
          MODIFY it_roles_tc2
            FROM g_tc2_wa2
            TRANSPORTING mark.
        ENDLOOP.
      ENDIF.
      MODIFY it_roles_tc2
        FROM wa_roles_tc2
        INDEX tc2-current_line
        TRANSPORTING mark.
    ENDMODULE. 
    thx for anybody who can help with this!

  • How to get selected entity from ADF Table

    I'm using EJB and ADF Faces.
    I have an ADF Table, and when a row is selected I'd like to be able to get the EJB Entity that was selected, is this feasible?
    The reason I would like to do it, is for a Dialog. I have a popup dialog, and in the popup the user can do a search. The results are displayed in the ADF table. When supplying the return value from the dialog:
    AdfFacesContext.getCurrentInstance().returnFromDialog(?, null);
    I would like ? to be the EJB entity representing the row, because I need to return the value of more than one of the columns. Is this not realistic, or should I just add then to a List and pass that back?
    thanks
    R

    Thanks KUBA,
    I hacked some code from the inbuilt JDeveloper Help. Are you saying there is an easier way than this, or did I state the question poorly and you gave an answer to something else? My english is not always perfect.
    This is the code that works for me. (cmdSelect is the submit button on the table)
    public String cmdSelect_action() {
    //Access the tableSelectMany1 table. Note that the table name
    //is taken from the id of the table in the JSF page.
    CoreTable table = this.getUserResultsTable();
    //Obtain a list of all selected rows from the table
    Set rowSet = table.getSelectionState().getKeySet();
    Iterator rowSetIter = rowSet.iterator();
    //Use the declarative method to get the ADF bindings
    BindingContainer bindings = getBindings();
    //Get the object to delete. To do this, you must get the
    //iterator binding for the Products in the page definition file,
    //and cast it to DCIteratorBinding for further processing
    DCIteratorBinding pr_dcib = (DCIteratorBinding)
    bindings.get ("queryUserVFindByFullNameIter");
    //Loop through the set of selected row numbers and delete the
    //equivalent object from the Products collection.
    UserV userV = null;
    while (rowSetIter.hasNext()){
    //get the table row
    Key key = (Key) rowSetIter.next();
    //set the current row in the ADF binding to the same row
    pr_dcib.setCurrentRowWithKey(key.toStringFormat(true));
    //Obtain the Products object to delete
    RowImpl prRow = (RowImpl) pr_dcib.getCurrentRow();
    //using the generated code to execute the declarative method
    userV = (UserV)prRow.getDataProvider();
    break;
    AdfFacesContext.getCurrentInstance().returnFromDialog(userV, null);
    return null;
    }

  • Select data from two tables...!

    HI Experts...!
    i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
    SELECT prps~pspnr
           prps~objnr
           prps~psphi
           proj~ernam
           proj~erdat
           proj~pspnr
    INTO  table itab   -
    itab is internal table
    FROM prps inner join proj
    WHERE pspnr in p_no and prpspsphi = projpspnr.
    but there is error in from clause ..please help me....
    Advance thanx....

    Hi,
    check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
    TABLES: prps, proj.
    TYPES:  BEGIN OF ty_test,
            pspnr LIKE prps-pspnr,
            objnr LIKE prps-objnr,
            psphi LIKE prps-psphi,
            ernam LIKE proj-ernam,
            erdat LIKE proj-erdat,
            END OF ty_test.
    DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
    SELECT-OPTIONS: p_no FOR prps-pspnr.
    SELECT  prps~pspnr
            prps~objnr
            prps~psphi
            proj~ernam
            proj~erdat
    *        proj~pspnr " No need for this you have selected this in
    *     the first line because it is commone so you only need to select from any one
            INTO TABLE itab
    FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr  )
    WHERE prps~pspnr IN p_no.
    Best Regards,
    Faisal
    Edited by: Rob Burbank on Dec 24, 2009 12:24 PM

  • Selecting data from two tables

    I am trying to select data from two tables.  The only problem that I am running into, is that i am only seeing results from my 'uploads' table.  there is also a record in documents where user = 1 that should show up.  here is my sql:
    $userIDNum = 1;
    $sql="Select *
    from uploads, documents
    WHERE uploads.user = documents.user AND uploads.user = $userIDNum
    ORDER BY uploads.title ASC, documents.title ASC";

    You'll need to explain a little more about your data and what you are trying to accomplish. Your current sql will select all columns from both the uploads and documents tables but only rows where the user id in both tables match, AND the user id equals 1. Is that not what you are seeing? Where's the code that outputs the results?

  • Disable the Dynamic Selection Icon from T.Code FBL1N

    Hi,
    I want to disable the Dynamic Selection Icon from T.Code FBL1N...
    Please Note that i found a link where some code is given for this problem.
    Remove the dynamic selection screen.......
    Please tell me where i paste that code....after initialization or where....
    Thanks...
    Edited by: Prince Kumar on May 16, 2009 8:59 AM

    Hi,
    1) COPY the program RFITEMAP and create a ZRFITEMAP
    2) and added this code in the INITILIZATION event. You can search ZRFITEMAP with INITIALIZATION and add below code there.
      INTIALIZATION.
      DATA: t_exclude TYPE STANDARD TABLE OF sypfkey.
      APPEND 'DYNS' TO t_exclude.
      "DYNS is the dynamic selection screen function code.
      CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
        EXPORTING
          p_status        = sy-pfkey
        TABLES
          p_exclude       = t_exclude
    Regards
    Shital

  • Error while selecting date from external table

    Hello all,
    I am getting the follwing error while selecting data from external table. Any idea why?
    SQL> CREATE TABLE SE2_EXT (SE_REF_NO VARCHAR2(255),
      2        SE_CUST_ID NUMBER(38),
      3        SE_TRAN_AMT_LCY FLOAT(126),
      4        SE_REVERSAL_MARKER VARCHAR2(255))
      5  ORGANIZATION EXTERNAL (
      6    TYPE ORACLE_LOADER
      7    DEFAULT DIRECTORY ext_tables
      8    ACCESS PARAMETERS (
      9      RECORDS DELIMITED BY NEWLINE
    10      FIELDS TERMINATED BY ','
    11      MISSING FIELD VALUES ARE NULL
    12      (
    13        country_code      CHAR(5),
    14        country_name      CHAR(50),
    15        country_language  CHAR(50)
    16      )
    17    )
    18    LOCATION ('SE2.csv')
    19  )
    20  PARALLEL 5
    21  REJECT LIMIT UNLIMITED;
    Table created.
    SQL> select * from se2_ext;
    SQL> select count(*) from se2_ext;
    select count(*) from se2_ext
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04043: table column not found in external source: SE_REF_NO
    ORA-06512: at "SYS.ORACLE_LOADER", line 19

    It would appear that you external table definition and the external data file data do not match up. Post a few input records so someone can duplicate the problem and determine the fix.
    HTH -- Mark D Powell --

  • Get selected elements from a table

    Hi all,
    I have a requirement like i m enhancing standard component in that i have added one button on click of that i want fetch the selected line item from the table ( which is a normal table). selection mode is auto.
    i tried with  the following code.
    DATA:lr_element                   TYPE REF TO if_wd_context_element,
           lv_index                     TYPE i.
    *--Get selected element
      lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
    ****Here itself its throughing dump because lr_element is initial***************
    *--get selected element index.
      lv_index = lr_element->get_index( ).
    can any one help me what is the wrong.. else suggest me how to get the selected elements from a table....
    Thanks in advance.

    *--Get selected element
    lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
    if  lr_element is bound.
    lv_index = lr_element->get_index( ).
    endif.
    Instead you can directly read the node if that row is a lead selected one.
    lo_node = wd_context->get_child_node( name = 'EMP' ).  "Emp is node name
    lo_ele = lo_node->get_lead_selection( ).
    or
    lv_index = lo_node->get_lead_selection_index( ).
    where is the above code written..is it written in OnLeadSelect event of the TABLE..
    can any one help me what is the wrong.. else suggest me how to get the selected elements from a table....
    As the selection mode is Auto there is no multiple selection..hence try to use the lead selection only.
    Edited by: Lekha on Jan 3, 2012 6:47 PM

  • How to select data from a table using a date field in the where condition?

    How to select data from a table using a date field in the where condition?
    For eg:
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
                                                      and bdatu = '31129999'.
    thanks.

    Hi Ramesh,
    Specify the date format as YYYYMMDD in where condition.
    Dates are internally stored in SAP as YYYYMMDD only.
    Change your date format in WHERE condition as follows.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and bdatu = <b>'99991231'.</b>
    I doubt check your data base table EQUK on this date for the existince of data.
    Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and <b> bdatu <= '99991231'.</b>
    Thanks,
    Vinay
    Thanks,
    Vinay

  • How to select data from a table by passing document number from another tab

    How to select data from a table by passing document number from another table.
    for eg:-
    I want to display name, adres, region from ADRC table
    by using field delivery document number
    Kind Regards,
    Shanbagavalli.S

    Hi Shanbagavalli,
    There are multiple solutions to this questions a few i will try to answer and then you can take the best required for your requirements.
    **Consider that you have a Internal table having document number from other table..
    SELECT NAME ADRES REGION FROM ADRC
           INTO IT_ADRC
           FOR ALL ENTRIES IN IT_DOC
           WHERE DOCUMENT_NO = IT_DOC-DOCUMENT_NO.
    **Consider that you have 1 document number then
    SELECT NAME ADRES REGION FROM ADRC
         INTO IT_ADRC
         WHERE DOCUMENT_NO = W_DOCUMENT_NO.
    Hope this solves your problem.
    Regards,
    Kunjal

  • Selecting data from a table which has a LONG column

    hi all,
    In the table user_views there is a LONG column. Now i want to select rows from that table based on this LONG column. like....
    select *from user_views where text like '%account%;
    but i am getting the error.."ORA-00932: Inconsistent datatypes:Expected NUMBER got LONG".
    How do I overcome this error.
    Please give me some suggestions.
    Thanks & Regards,
    Vijay

    In the table user_views there is a LONG column. Now i want to select rows from that >table based on this LONG column. like....LONG columns cannot appear in a WHERE or
    AND clause.

  • How to make validation in Bean and select value from another table

    I want to know how to select data from table in backing bean according to primary key i have
    the problem is that
    i have a table Employee_Salary contains Employee ids and their salary
    Empoloyee_Salary table
         Employee_ID      Number
         Employee_salary Number
    And Another table Called Employees
    Employees table
         Employee_ID     Number
         IsManager Varchar2 its value is [*Yes or NO*]
    and other columns that i don't care about this table
    i have on a jsff page an <af:table> this table is editable this is the Empoloyee_Salary table
    *i want to check before save or after insert if this employee is Manager [from Employees tabke(yes or no)] the salary*
    cannot be less that 100
    i want to know how to make this how to select the value from employees table according to the id i have in the employee_salary table how to make this and make this validation
    i have to select IsManager from Employees Table to see if this manager or no
    i want to know how to make this in a bean
    i use jdeveloper 11g
    and my project is ADF Fusion project
    and the page that have the Emplpyee_Salary table is JSFF
    thanks in advance

    You might want to write this code in a validator on the entity object if it should apply from every screen.
    If you want to access view objects from a backing bean the basics are here: http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcservices.htm#sthref918

  • How can I select columns from a table EMP, using Select statement?.

    Hi Friends,
    How can I select columns from a table EMP?.
    I want to select columns of EMP table, using select statement.
    Please reply me urgently.
    Shahzad

    Something like this:
    scott@DBA> select empno,ename,job from emp;
         EMPNO ENAME      JOB
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 JAMES      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
    14 rows selected.Check the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    Message was edited by:
    Delfino Nunez

Maybe you are looking for

  • DBA studio: Error add/connect database "Failed to parse tnsnames.ora file"

    I have Oracle (version 8.1.7) installed in my XP machine and when I try to (having chosen "Launch DBA Studio standalone") to open a connection I get: "Failed to parse tnsnames.ora file ERROR: 100 -- NLNV-NLNV String Format Error". Also got this when

  • New apps does not starts

    I had this problem for a while now with small applications for OSX Mountain Lion that doesnt need to run installation. I can't start them, after double clicking nothing happens. When I do the same on another OSX computer they work fine. Does anybody

  • Export Graphic w/Transparency, CS6 Server, Fail

    I have a script that loops through all graphics inside an adobe indesign document. The script senses what type of graphic file it is (JPEG, TIFF, EPS, PSD, etc), and, based on some simple rules, the graphic will get exported as either a JPEG, or a PN

  • UDF retrieval help

    Hey All, Can anyone tell me how I can properly read a UDF field from the UDF form on the purchase order screen? Usually i just read the text value from the activeform but of course this does not work for the UDF form as it is not the active form. A c

  • Logon prompt is coming

    Hi, In portal I need to access quality server. For a certain iView when I clicked it in Q server, another logon prompt is coming showing that it referring to Production backend. I this case it should not asked for another login i.e. the iview must ge