<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dynamic selection need from a table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053258#M89720</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not really sure what the problem is.  What is the table that you are entering in the selection screen.  I've used T001, it runs fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Dec 2005 20:13:06 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2005-12-14T20:13:06Z</dc:date>
    <item>
      <title>Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053255#M89717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a requirement to select the data from a table dynamically. Only during run time I will know the structure of that table &amp;amp; table name. In this case can anyone give any tips/sample code how it can be accomplished. Help appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Abhi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 19:17:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053255#M89717</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-14T19:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053256#M89718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure, check out this sample program.  It is a dynamic table read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0002.

type-pools: slis.

field-symbols: &amp;lt;dyn_table&amp;gt; type standard table,
               &amp;lt;dyn_wa&amp;gt;,
               &amp;lt;dyn_field&amp;gt;.

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=&amp;gt;describe_by_name( p_table ).
it_details[] = ref_descr-&amp;gt;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=&amp;gt;create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table.

assign new_table-&amp;gt;* to &amp;lt;dyn_table&amp;gt;.

* Create dynamic work area and assign to FS
create data new_line like line of &amp;lt;dyn_table&amp;gt;.
assign new_line-&amp;gt;* to &amp;lt;dyn_wa&amp;gt;.

* Select Data from table.
select * into table &amp;lt;dyn_table&amp;gt;
           from (p_table).

* Write out data from table.
loop at &amp;lt;dyn_table&amp;gt; into &amp;lt;dyn_wa&amp;gt;.
  do.
    assign component  sy-index  of structure &amp;lt;dyn_wa&amp;gt; to &amp;lt;dyn_field&amp;gt;.
    if sy-subrc &amp;lt;&amp;gt; 0.
      exit.
    endif.
    if sy-index = 1.
      write:/ &amp;lt;dyn_field&amp;gt;.
    else.
      write: &amp;lt;dyn_field&amp;gt;.
    endif.
  enddo.
endloop.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Welcome to SDN.  Please remember to award points for helpful answers and mark you post as solved when solved completely.  Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fixed Code&lt;/P&gt;&lt;P&gt;Message was edited by: Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 19:19:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053256#M89718</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-14T19:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053257#M89719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rich,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am thankful &amp;amp; really appreciate your help, However I am getting some errors, when I used your code I am getting dump at the select statement with the error 'SAPSQL_SELECT_TAB_TOO_SMALL' i.e With ABAP/4 Open SQL array select, the output table is too small.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will try to resolve this &amp;amp; keep you posted but in case if your are already aware of this problem, can you please suggest to get rid of it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help &amp;amp; time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards.Abhi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 20:07:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053257#M89719</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-14T20:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053258#M89720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not really sure what the problem is.  What is the table that you are entering in the selection screen.  I've used T001, it runs fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 20:13:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053258#M89720</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-14T20:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053259#M89721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As an example I used MARA table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards..Abhi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 20:20:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053259#M89721</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-14T20:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053260#M89722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am seeing the same.  I believe it has to do with the field types in the internal table.  They are all type C, which is not how it is in the table itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 20:34:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053260#M89722</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-14T20:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053261#M89723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is definitly because of the types of the fields.  Particularly the type P fields.  I'm looking at it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 21:02:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053261#M89723</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-14T21:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053262#M89724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Its weird, its like the client field is shifting everything to the left.  I don't understand it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, the fix for the types, is as follows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

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.
&amp;lt;b&amp;gt;  wa_it_fldcat-inttype = wa_details-type_kind.&amp;lt;/b&amp;gt;
  wa_it_fldcat-intlen = wa_details-length.
  wa_it_fldcat-decimals = wa_details-decimals.
  append wa_it_fldcat to it_fldcat .
endloop.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 21:28:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053262#M89724</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-14T21:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053263#M89725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Abhi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can try this program. This program approach is similar somewhat but it works for MARA too. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;report zsharad.
type-pools : abap.

data: w_line type ref to data.
data : it_details type abap_compdescr_tab,
       wa_details type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.


field-symbols  : &amp;lt;fs&amp;gt; type any,
                 &amp;lt;fval&amp;gt; type any,
                 &amp;lt;fnam&amp;gt; type any.

parameters: p_table(30) type c.

start-of-selection.
  ref_descr ?= cl_abap_typedescr=&amp;gt;describe_by_name( p_table ).
  it_details[] = ref_descr-&amp;gt;components[].


  create data w_line type (p_table).
  assign w_line-&amp;gt;* to &amp;lt;fs&amp;gt;.

  select *  from mara into &amp;lt;fs&amp;gt;
     where matkl = '01'.

    do.

      assign component sy-index of structure &amp;lt;fs&amp;gt; to &amp;lt;fval&amp;gt;.
      if sy-subrc &amp;lt;&amp;gt; 0.
        exit.
      endif.
      read table it_details into wa_details 
           index sy-index.

      write :/01 wa_details-name,
                 &amp;lt;fval&amp;gt;.
      free &amp;lt;fval&amp;gt;.

    enddo.

  endselect.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 22:06:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053263#M89725</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-14T22:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053264#M89726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm stumped, guess this code only works for most tables.  Mara is not one of them.  I'm on a 46c box, so I'm limited to the 46c technology.  Maybe there is something better in newer releases. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2005 23:14:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053264#M89726</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-14T23:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053265#M89727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks,  Rich/Sharad.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Abhi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2005 19:42:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053265#M89727</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-15T19:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic selection need from a table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053266#M89728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use this code instead of previouse:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
* Dynamic table and structure declaration
  DATA:
        lv_db_table_name TYPE string,
        dy_table TYPE REF TO data.

  FIELD-SYMBOLS:
                 &amp;lt;lt_data&amp;gt; TYPE STANDARD TABLE.


* Prepare
lv_db_table_name = 'RSZCALC'.
TRANSLATE lv_db_table_name TO UPPER CASE.


*---------------------------------------------------------------------
* Create dynamical table based on existing one
*---------------------------------------------------------------------
  CREATE DATA dy_table TYPE TABLE OF (lv_db_table_name).
  ASSIGN dy_table-&amp;gt;* TO &amp;lt;lt_data&amp;gt;.


*---------------------------------------------------------------------
* Select content of a table
*---------------------------------------------------------------------
  REFRESH &amp;lt;lt_data&amp;gt;.
  SELECT * FROM (lv_db_table_name) INTO TABLE &amp;lt;lt_data&amp;gt;.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards Pavel.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jan 2012 11:47:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-selection-need-from-a-table/m-p/1053266#M89728</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-28T11:47:26Z</dc:date>
    </item>
  </channel>
</rss>

