<?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 SQl Query Select in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876782#M1477951</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;Pass the name of the Table to the Field symbol.&lt;/P&gt;&lt;P&gt;ASSIGN (ls_key) TO &amp;lt;fs_tab&amp;gt;.&lt;/P&gt;&lt;P&gt;and then use this FS to get the data in SELECT statement&lt;/P&gt;&lt;P&gt;ags.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 May 2010 10:53:35 GMT</pubDate>
    <dc:creator>agnihotro_sinha2</dc:creator>
    <dc:date>2010-05-06T10:53:35Z</dc:date>
    <item>
      <title>Dynamic SQl Query Select</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876781#M1477950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Colleague,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table that contains multiple entries of TABLE NAME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to query the databse table and check if certain entry exist in that table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I Loop over the table containing the tablenames and try a select :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at lt_key into ls_key.&lt;/P&gt;&lt;P&gt;  SELECT * FROM (ls_key) WHERE field = 'ABC' .&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It gives me a error and asks to store the result using INTO. Now i am confused with the type of result because the tablename is provided dynamically. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Piyush&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 May 2010 10:49:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876781#M1477950</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-06T10:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQl Query Select</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876782#M1477951</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;Pass the name of the Table to the Field symbol.&lt;/P&gt;&lt;P&gt;ASSIGN (ls_key) TO &amp;lt;fs_tab&amp;gt;.&lt;/P&gt;&lt;P&gt;and then use this FS to get the data in SELECT statement&lt;/P&gt;&lt;P&gt;ags.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 May 2010 10:53:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876782#M1477951</guid>
      <dc:creator>agnihotro_sinha2</dc:creator>
      <dc:date>2010-05-06T10:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQl Query Select</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876783#M1477952</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 did something similar to it, the following program accepts table&lt;/P&gt;&lt;P&gt;name and fields from user and sort dynamically.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  zreport_SORT.

parameters:
  p_f1(15) obligatory,
  p_f2(15) obligatory,
  p_f3(15) obligatory,
  p_table(15).

data:
  w_tab type ref to data,
  fs_tab type ref to data,
  w_flag,
  w_count type i.


create data w_tab type table of  (p_table) .
create data fs_tab type (p_table).

data:
  t_tab type table of spfli,
  fs_tab1 like line of t_tab.

field-symbols:
  &amp;lt;fs&amp;gt; type any table,
  &amp;lt;fs1&amp;gt; type any,
  &amp;lt;fs2&amp;gt; type any,
  &amp;lt;fs3&amp;gt; type any,
  &amp;lt;fs4&amp;gt; type any.

at selection-screen.

select count(*)
  from dd03l
  into w_count
 where tabname eq p_table
   and fieldname eq p_f1.
if w_count eq 0.
  w_flag = 'Y'.
 endif.
select count(*)
  from dd03l
  into w_count
 where tabname eq p_table
   and fieldname eq p_f2.

if w_count eq 0.
  w_flag = 'Y'.
 endif.

select count(*)
  from dd03l
  into w_count
 where tabname eq p_table
   and fieldname eq p_f3.

if w_count eq 0.
  w_flag = 'Y'.
 endif.
if w_flag eq 'Y'.
 clear w_flag.
 Message 'Incorrect field name' type 'E'.
endif.

start-of-selection.
assign w_tab-&amp;gt;* to &amp;lt;fs&amp;gt;.
assign fs_tab-&amp;gt;* to &amp;lt;fs1&amp;gt;.

  select *
    from (p_table)
    into corresponding fields of
   table &amp;lt;fs&amp;gt; up to 10 rows.
   sort &amp;lt;fs&amp;gt; by (p_f1) ascending (p_f2) ascending (p_f3) ascending.

assign component p_f1 of structure &amp;lt;fs1&amp;gt; to &amp;lt;fs2&amp;gt;.
assign component p_f2 of structure &amp;lt;fs1&amp;gt; to &amp;lt;fs3&amp;gt;.
assign component p_f3 of structure &amp;lt;fs1&amp;gt; to &amp;lt;fs4&amp;gt;.


  loop at &amp;lt;fs&amp;gt; into &amp;lt;fs1&amp;gt;.
  write:/ &amp;lt;fs2&amp;gt;,
          &amp;lt;fs3&amp;gt;,
          &amp;lt;fs4&amp;gt;.
  endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards and Best wishes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 May 2010 10:54:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876783#M1477952</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-06T10:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQl Query Select</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876784#M1477953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why do you need this SELECT stmt ? Do you want to use the data selected from the table or just want to check if there are any entries in the table with &lt;STRONG&gt;field = 'ABC'&lt;/STRONG&gt; ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to use the data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA:
DREF TYPE REF TO DATA.

FIELD-SYMBOLS:
&amp;lt;ITAB&amp;gt; TYPE STANDARD TABLE.


LOOP AT ITAB INTO LS_KEY.

CREATE DATA DREF TYPE STANDARD TABLE OF (ls_key).
ASSIGN DREF-&amp;gt;* TO &amp;lt;ITAB&amp;gt;.

SELECT * FROM (ls_key) WHERE field = 'ABC' INTO TABLE &amp;lt;ITAB&amp;gt;.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 May 2010 10:55:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query-select/m-p/6876784#M1477953</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2010-05-06T10:55:55Z</dc:date>
    </item>
  </channel>
</rss>

