<?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 Tables &amp; SQL Statements in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261620#M779324</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Leslie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thought the code can give you a lead to handle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyhow check below example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

types: begin of ty_code,
         text type char255,
       end of ty_code.
data: it_code type table of ty_code,
      wa_code type ty_code.

select * from &amp;lt;tabA&amp;gt; into &amp;lt;itabA&amp;gt;.

loop at &amp;lt;itabA&amp;gt; into &amp;lt;waA&amp;gt;.
     move &amp;lt;waA&amp;gt;-cfield to wa_code-text.
     append wa_code to it_code.
endloop.

* Now the conditions exists in table it_code, Use the same for next select

select * from &amp;lt;tabB&amp;gt; into &amp;lt;itabB&amp;gt;
       where (it_code).

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Jan 2008 06:09:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-01-16T06:09:13Z</dc:date>
    <item>
      <title>Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261617#M779321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Example: &lt;/P&gt;&lt;P&gt;A user types in a SQL statement, " Country = 'US' ", into a input field. i read it and copy into table A. how am i supposed to use the statement found in the table to do a comparison of data from table B? i've found a example in the abap documentation but i'm not sure how to retrieve the statement from table A. please provide sample codes so i know how it works. i'll reward handsomely if the answer's close (((((((:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks (:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT demo_special_tech_subroutine_1.&lt;/P&gt;&lt;P&gt;DATA: code TYPE TABLE OF rssource-line,&lt;/P&gt;&lt;P&gt;      prog(8) TYPE c, msg(120) TYPE c, lin(3) TYPE c,&lt;/P&gt;&lt;P&gt;      wrd(10) TYPE c, off(3) TYPE c.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND 'PROGRAM SUBPOOL.'&lt;/P&gt;&lt;P&gt;        TO code.&lt;/P&gt;&lt;P&gt;APPEND 'FORM DYN1.'&lt;/P&gt;&lt;P&gt;        TO code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND&lt;/P&gt;&lt;P&gt;   'WRITE / ''Hello, I am the temporary subroutine DYN1!''.' "#EC NOTEXT&lt;/P&gt;&lt;P&gt;        TO code.&lt;/P&gt;&lt;P&gt;APPEND 'ENDFORM.'&lt;/P&gt;&lt;P&gt;        TO code.&lt;/P&gt;&lt;P&gt;APPEND 'FORM DYN2.'&lt;/P&gt;&lt;P&gt;        TO code.&lt;/P&gt;&lt;P&gt;APPEND&lt;/P&gt;&lt;P&gt;   'WRIT / ''Hello, I am the temporary subroutine DYN2!''.'  "#EC NOTEXT&lt;/P&gt;&lt;P&gt;        TO code.&lt;/P&gt;&lt;P&gt;APPEND 'ENDFORM.'&lt;/P&gt;&lt;P&gt;        TO code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GENERATE SUBROUTINE POOL code NAME prog&lt;/P&gt;&lt;P&gt;                         MESSAGE msg&lt;/P&gt;&lt;P&gt;                         LINE    lin&lt;/P&gt;&lt;P&gt;                         WORD    wrd&lt;/P&gt;&lt;P&gt;                         OFFSET  off.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;  WRITE: / 'Error during generation in line', lin,           "#EC NOTEXT&lt;/P&gt;&lt;P&gt;         / msg,&lt;/P&gt;&lt;P&gt;         / 'Word:', wrd, 'at offset', off.                   "#EC NOTEXT&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;  WRITE: / 'The name of the subroutine pool is', prog.       "#EC NOTEXT&lt;/P&gt;&lt;P&gt;  SKIP 2.&lt;/P&gt;&lt;P&gt;  PERFORM dyn1 IN PROGRAM (prog).&lt;/P&gt;&lt;P&gt;  SKIP 2.&lt;/P&gt;&lt;P&gt;  PERFORM dyn2 IN PROGRAM (prog).&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Leslie Koh on Jan 16, 2008 6:31 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 05:22:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261617#M779321</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T05:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261618#M779322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Leslie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If my understanding is right your requirement is to pass 'Country = 'US'' to the select condition for another table, below example can help you understand in handling the scenario.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: l_land1 type land1.

data: code(20) type c.

move 'LAND1 = ''US''' TO code.
select single land1 into l_land1 from t005
       where (code)
       and   spras = sy-langu.

write:/ l_land1.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 05:47:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261618#M779322</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T05:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261619#M779323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi Eswar Rao Boddeti,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for your fast response but i'm trying to do it dynamic, meaning you will not know what the user key in for the SQL statement. i need to run a program to retrieve data from table A, using a loop case, and based on the SQL statement found at table A to compare the data from table B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what you're doing is hard-coding the 'us' into code. but thanks again for your help (: i've rewarded you (: please continue your help &lt;SPAN __jive_emoticon_name="silly"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 06:00:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261619#M779323</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T06:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261620#M779324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Leslie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thought the code can give you a lead to handle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyhow check below example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

types: begin of ty_code,
         text type char255,
       end of ty_code.
data: it_code type table of ty_code,
      wa_code type ty_code.

select * from &amp;lt;tabA&amp;gt; into &amp;lt;itabA&amp;gt;.

loop at &amp;lt;itabA&amp;gt; into &amp;lt;waA&amp;gt;.
     move &amp;lt;waA&amp;gt;-cfield to wa_code-text.
     append wa_code to it_code.
endloop.

* Now the conditions exists in table it_code, Use the same for next select

select * from &amp;lt;tabB&amp;gt; into &amp;lt;itabB&amp;gt;
       where (it_code).

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 06:09:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261620#M779324</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T06:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261621#M779325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Eswar, &lt;/P&gt;&lt;P&gt;the codes you provide is very helpful. but the thing is that i'm not sure abt what's ty_code, it_code and &amp;lt;waA&amp;gt;-cfield.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks (:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 06:23:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261621#M779325</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T06:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261622#M779326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Leslie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check below comments:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

types: begin of ty_code,   " Type declaration
         text type char255,
       end of ty_code.

data: it_code type table of ty_code, " Internal table to hold the dynamic WHERE condition
      wa_code type ty_code. " Work Area
 
select * from &amp;lt;tabA&amp;gt; into &amp;lt;itabA&amp;gt;. " tabA is the first table which holds the SQL conditions
 
loop at &amp;lt;itabA&amp;gt; into &amp;lt;waA&amp;gt;. 
     move &amp;lt;waA&amp;gt;-cfield to wa_code-text. " In this example as presuming CFIELD has the SQL condition
     append wa_code to it_code. " Am preparing an internal table with all the conditions
endloop.

* Note that if you have more than one condition you may need to add AND to starting 2nd line
 
* Now the conditions exists in table it_code, Use the same for next select
 
select * from &amp;lt;tabB&amp;gt; into &amp;lt;itabB&amp;gt;
       where (it_code). " Retreiving data from table tabB with the SQL conditions from tabA
 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you understand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try using the above code in a temporary program, replace &amp;lt;tabA&amp;gt; with your first table that holds SQL conditions, &amp;lt;tabB&amp;gt; with the second table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 06:33:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261622#M779326</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T06:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261623#M779327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;loop at &amp;lt;itabA&amp;gt; into &amp;lt;waA&amp;gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where does the &amp;lt;waA&amp;gt; come from?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks ((:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 06:56:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261623#M779327</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T06:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261624#M779328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;lt;itabA&amp;gt; and &amp;lt;waA&amp;gt; are the internal table and work area for the first table, Similiar is the case for table 2 with &amp;lt;itabB&amp;gt; and &amp;lt;waB&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 07:02:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261624#M779328</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T07:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Tables &amp; SQL Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261625#M779329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks eswar (: you've solved my problem!!! (((:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2008 07:19:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-tables-sql-statements/m-p/3261625#M779329</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-16T07:19:06Z</dc:date>
    </item>
  </channel>
</rss>

