<?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: How to dynamic create Select SQL statements. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamic-create-select-sql-statements/m-p/966323#M68611</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a sample program....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will get you started in programming a dynamic internal table as well as dynamic select.&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-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 corresponding fields of 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;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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>Thu, 11 Aug 2005 20:16:57 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2005-08-11T20:16:57Z</dc:date>
    <item>
      <title>How to dynamic create Select SQL statements.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamic-create-select-sql-statements/m-p/966322#M68610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi frnds,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to make a SELECT statement in which all values I will get dynamically. Like i have two fields on selection screen, one for table name and one for field name. Now I need to make my ITAB according to the table selected and field name selected. So finally my ITAB will be having the field which I chosen from selection screen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now how can I make a dynamic ITAB and how to create a dynamic SELECT statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It wud be great if you can help me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Arpit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 20:13:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamic-create-select-sql-statements/m-p/966322#M68610</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T20:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamic create Select SQL statements.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamic-create-select-sql-statements/m-p/966323#M68611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a sample program....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will get you started in programming a dynamic internal table as well as dynamic select.&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-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 corresponding fields of 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;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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>Thu, 11 Aug 2005 20:16:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamic-create-select-sql-statements/m-p/966323#M68611</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-08-11T20:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamic create Select SQL statements.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamic-create-select-sql-statements/m-p/966324#M68612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arpit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check 'Using dynamic SELECT statement' in the following link.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.sdn.sap.com/sdn/developerareas/abap.sdn?contenttype=url&amp;amp;content=/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/abap" target="test_blank"&gt;https://www.sdn.sap.com/sdn/developerareas/abap.sdn?contenttype=url&amp;amp;content=/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/abap&lt;/A&gt; faqs.faq&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found it very interesting. Hope it will help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ashish Jain&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 20:27:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamic-create-select-sql-statements/m-p/966324#M68612</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T20:27:39Z</dc:date>
    </item>
  </channel>
</rss>

