<?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: Loop Range table to Build SQL Statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173172#M123665</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Eswar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You seem to be the closest to what I want, but would that not create multiple select statements for each field?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Feb 2006 13:02:28 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-02-28T13:02:28Z</dc:date>
    <item>
      <title>Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173163#M123656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to loop Through a RANGES type table to build a SQL Statement something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data: SQLSTR type C.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at LS_Select into WA_LS_select.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SQLSTR = SQLSTR + WA_LS_select-Fieldname in WA_LS_select.&lt;/P&gt;&lt;P&gt;endloop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select * from TABLEX where ( SQLSTR )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this possible if so could someone please give me a little sample code. Additionally it is possible that in my ranges table I could have multiple items for the same field name..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2006 23:13:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173163#M123656</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-27T23:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173164#M123657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Hubert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try changing the loop as follows..&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
assuming ls_select is your RANGES
Loop at LS_Select.
concatenate SQLSTR LS_select-low
 into SQLSTR.
endloop
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suresh Datti&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2006 23:18:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173164#M123657</guid>
      <dc:creator>suresh_datti</dc:creator>
      <dc:date>2006-02-27T23:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173165#M123658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did not understand your requirement but here is one suggestion - my assumption is you do not want to use select option directly in code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suppose I have S_MATNR as select optopn.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First get all the Materials for this S_MATNR from MARA table into another internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can loop at this table and select your code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT I_MARA.&lt;/P&gt;&lt;P&gt;  SELECT DATA FROM TABLE WHERE MATNR = I_MARA-MATNR.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Else you can also use FOR ALL ENTRIES option.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2006 23:45:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173165#M123658</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-27T23:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173166#M123659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;aSSUMING THE TABLE AND FIELDNAME IS CONSTANT:&lt;/P&gt;&lt;P&gt;  DATA l_sql TYPE string.&lt;/P&gt;&lt;P&gt;loop at r_range.&lt;/P&gt;&lt;P&gt;  if sy-tabix = 1.&lt;/P&gt;&lt;P&gt;    concatenate 'table-fieldname = ' r_range-low&lt;/P&gt;&lt;P&gt;     into l_sql separated by space.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;    concatenate l_sql 'or table-fieldname = ' r_range-low&lt;/P&gt;&lt;P&gt;     into l_sql separated by space.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select * from TABLEX where (l_sql).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.........&lt;/P&gt;&lt;P&gt;If you want to use the HIGH and LOW of the range you could modify it slightly to use&lt;/P&gt;&lt;P&gt;    concatenate 'table-fieldname between ' r_range-low&lt;/P&gt;&lt;P&gt;     'and' r_range-high into l_sql separated by space.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 01:25:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173166#M123659</guid>
      <dc:creator>former_member186741</dc:creator>
      <dc:date>2006-02-28T01:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173167#M123660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This would be pretty difficult. You will have to handle things like NE, CP, EXCLUDE. Why not just use the range table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 03:53:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173167#M123660</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T03:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173168#M123661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rob,&lt;/P&gt;&lt;P&gt;This is exactly what I would like to do is use the Range table. My table contains data like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fieldname&lt;DEL&gt;-sign&lt;/DEL&gt;-option&lt;DEL&gt;-low&lt;/DEL&gt;-high&lt;/P&gt;&lt;P&gt;zip&lt;DEL&gt;-I&lt;/DEL&gt;-eq---30152&lt;/P&gt;&lt;P&gt;zip&lt;DEL&gt;-I&lt;/DEL&gt;-bt&lt;DEL&gt;-30111&lt;/DEL&gt;-30113&lt;/P&gt;&lt;P&gt;year&lt;DEL&gt;e&lt;/DEL&gt;-lt---2005&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;etc etc....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to do is loop through this table to build a sql statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this possible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 12:40:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173168#M123661</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T12:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173169#M123662</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;  U can write a select like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  select &amp;lt;your fields&amp;gt; from &amp;lt;table&amp;gt; into table &amp;lt;IT&amp;gt;&lt;/P&gt;&lt;P&gt;       where &lt;/P&gt;&lt;P&gt;       zip_field in zip (This is the range in your table)&lt;/P&gt;&lt;P&gt;    and year in year(year in your range table)   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;GSR.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 12:51:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173169#M123662</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T12:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173170#M123663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Pls.look into the below code..may it useful for u&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop &amp;lt;rangestable&amp;gt; into &amp;lt;wa_range&amp;gt;&lt;/P&gt;&lt;P&gt;select &amp;lt;f1&amp;gt; &amp;lt;f2&amp;gt; from &amp;lt;db&amp;gt; into table &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;             where &amp;lt;field&amp;gt; in &amp;lt;wa_range&amp;gt;.&lt;/P&gt;&lt;P&gt;clear &amp;lt;wa_range&amp;gt;.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 12:53:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173170#M123663</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T12:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173171#M123664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Hubert&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yes you can loop through this table then build the select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab_range.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;use conditional statements then hard code the required select statement  for ex.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if itab_range-fieldname eq 'zip' and itab_range-option eq 'eq'.&lt;/P&gt;&lt;P&gt;select * from zemp where zip bt itab_range-low and itab_range-high.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;kishore&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 12:55:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173171#M123664</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T12:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173172#M123665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Eswar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You seem to be the closest to what I want, but would that not create multiple select statements for each field?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 13:02:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173172#M123665</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T13:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173173#M123666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hope in this case it will create multiple statements bcoz we will get only one row at a time to check in select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or else u can create separate range for each field to check in a single select statement (Performance)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 13:07:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173173#M123666</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T13:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173174#M123667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was considering making a range table for each possible entry, but this could endup being a little over 80.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I would have to also include every on in the select statement. I was really hoping to avoid this since, most of the time I expect the user to only select 10 to 20 variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to convert a range table into a string, maybe a function module or something? what does it do at run time?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 13:12:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173174#M123667</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T13:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173175#M123668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I was suggesting that you just use all of the range tables as is. I'm sure you can build the logic to do what you want, but it will be difficult and time consuming. In the end it probably will be just as long and no more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2006 15:10:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173175#M123668</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-28T15:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173176#M123669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have coded this and it works, but I have to wonder why you would ever want to do it this way given that the sql can just refer directly to the ranges (or select-options in this example). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a program which had a few select options within it's sql, I changed it to dynamically generate references to the select options instead of hard-coding the 'in' clauses in the sql:&lt;/P&gt;&lt;P&gt;DATA l_sql TYPE string.&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS S_bLART for bSID-bLART.&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS s_BRAN1 for KNA1-BRAN1.&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS s_REGIO for KNA1-REGIO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;define append_sql.&lt;/P&gt;&lt;P&gt;if l_sql is initial.&lt;/P&gt;&lt;P&gt; concatenate &amp;amp;1 'in' &amp;amp;2 into l_sql separated by space.&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt; concatenate L_SQL 'AND' &amp;amp;1 'IN' &amp;amp;2 into l_sql separated by space.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND_SQL 'BSID~BLART' 'S_BLART'.&lt;/P&gt;&lt;P&gt;APPEND_SQL 'KNA1~BRAN1' 'S_BRAN1'.&lt;/P&gt;&lt;P&gt;APPEND_SQL 'KNA1~REGIO' 'S_REGIO'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT bsid&lt;SUB&gt;bukrs bsid&lt;/SUB&gt;kunnr bsid~belnr&lt;/P&gt;&lt;P&gt;         kna1&lt;SUB&gt;regio kna1&lt;/SUB&gt;bran1 kna1~name1&lt;/P&gt;&lt;P&gt;  FROM bsid&lt;/P&gt;&lt;P&gt;  JOIN vbrk ON vbrk&lt;SUB&gt;vbeln = bsid&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;  JOIN knvv ON knvv&lt;SUB&gt;kunnr = vbrk&lt;/SUB&gt;kunag&lt;/P&gt;&lt;P&gt;           AND knvv&lt;SUB&gt;vkorg = vbrk&lt;/SUB&gt;vkorg&lt;/P&gt;&lt;P&gt;           AND knvv&lt;SUB&gt;vtweg = vbrk&lt;/SUB&gt;vtweg&lt;/P&gt;&lt;P&gt;           AND knvv&lt;SUB&gt;spart = vbrk&lt;/SUB&gt;spart&lt;/P&gt;&lt;P&gt;  JOIN kna1 ON kna1&lt;SUB&gt;kunnr = knvv&lt;/SUB&gt;kunnr&lt;/P&gt;&lt;P&gt;    INTO CORRESPONDING  FIELDS OF TABLE T_BSID&lt;/P&gt;&lt;P&gt;    WHERE bsid~bukrs = p_bukrs&lt;/P&gt;&lt;P&gt;      AND bsid~kunnr IN s_kunnr&lt;/P&gt;&lt;P&gt;      AND bsid~budat &amp;lt;= w_key_date&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     AND bsid~blart IN s_blart "now in l_sql&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     AND kna1~bran1 IN s_bran1 "&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     AND kna1~regio IN s_regio "&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      AND (l_sql)&lt;/P&gt;&lt;P&gt;      .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 02:42:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173176#M123669</guid>
      <dc:creator>former_member186741</dc:creator>
      <dc:date>2006-03-06T02:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173177#M123670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Hubert,&lt;/P&gt;&lt;P&gt;You must build your SQL statement dynamically like this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;b&amp;gt;DATA sqlstr(100).&amp;lt;/b&amp;gt;

LOOP AT ls_select INTO wa_ls_select.
 IF sqlstr IS INITIAL.
   IF wa_ls_select-option EQ 'eq' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'EQ' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
  IF wa_ls_select-option EQ 'eq' AND wa_ls_select-sign EQ 'e'.
     CONCATENATE wa_ls_select-fieldname 'NE' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
  IF wa_ls_select-option EQ 'bt' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'BETWEEN' wa_ls_select-low
    'AND' wa_ls_select-high
     INTO sqlstr
     SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'lt' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'LE' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'lt' AND wa_ls_select-sign EQ 'e'.
     CONCATENATE wa_ls_select-fieldname 'LT' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'gt' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'GE' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'gt' AND wa_ls_select-sign EQ 'e'.
     CONCATENATE wa_ls_select-fieldname 'GT' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
ELSE.
   CONCATENATE sqlstr 'AND' INTO sqlstr SEPARATED BY space.
   IF wa_ls_select-option EQ 'eq' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'EQ' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
  IF wa_ls_select-option EQ 'eq' AND wa_ls_select-sign EQ 'e'.
     CONCATENATE wa_ls_select-fieldname 'NE' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
  IF wa_ls_select-option EQ 'bt' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'BETWEEN' wa_ls_select-low
    'AND' wa_ls_select-high
     INTO sqlstr
     SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'lt' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'LE' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'lt' AND wa_ls_select-sign EQ 'e'.
     CONCATENATE wa_ls_select-fieldname 'LT' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'gt' AND wa_ls_select-sign EQ 'I'.
     CONCATENATE wa_ls_select-fieldname 'GE' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
   IF wa_ls_select-option EQ 'gt' AND wa_ls_select-sign EQ 'e'.
     CONCATENATE wa_ls_select-fieldname 'GT' wa_ls_select-low
        INTO sqlstr
        SEPARATED BY space.
   ENDIF.
 ENDIF.
ENDLOOP.


Select * from TABLEX where ( SQLSTR ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 03:20:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173177#M123670</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T03:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173178#M123671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Wenceslaus, what do you mean by "MUST" build the sql like this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 03:36:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173178#M123671</guid>
      <dc:creator>former_member186741</dc:creator>
      <dc:date>2006-03-06T03:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173179#M123672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Neil,&lt;/P&gt;&lt;P&gt;Since the requirement was to build sql from a table where he had not used RANGES:&lt;/P&gt;&lt;P&gt;fieldname&lt;DEL&gt;-sign&lt;/DEL&gt;-option&lt;DEL&gt;-low&lt;/DEL&gt;-high&lt;/P&gt;&lt;P&gt;zip&lt;DEL&gt;-I&lt;/DEL&gt;-eq---30152&lt;/P&gt;&lt;P&gt;zip&lt;DEL&gt;-I&lt;/DEL&gt;-bt&lt;DEL&gt;-30111&lt;/DEL&gt;-30113&lt;/P&gt;&lt;P&gt;year&lt;DEL&gt;e&lt;/DEL&gt;-lt---2005&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I think the possible way for this is that he could parse the contents of the table and build SQL query. Still there could be alternative ways of doing this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Wenceslaus.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 03:42:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173179#M123672</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T03:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173180#M123673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;maybe I've misunderstood, but Hubert specifically said he wants to use a RANGES type table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 04:27:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173180#M123673</guid>
      <dc:creator>former_member186741</dc:creator>
      <dc:date>2006-03-06T04:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173181#M123674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Here is the code if it for ranges table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  ZEN_COV.

TABLES: mara.

SELECT-OPTIONS: ls_sel FOR mara-matnr.

DATA: t TYPE i.

DATA datstr(2000).
DATA tmpstr(2000).

LOOP AT ls_sel.
  IF datstr IS NOT INITIAL.
    CONCATENATE datstr 'AND' INTO datstr SEPARATED BY space.
    tmpstr = datstr.
  ENDIF.

  IF ls_sel-option EQ 'EQ' AND ls_sel-sign EQ 'I'.
    CONCATENATE tmpstr 'mara~matnr' 'EQ' ls_sel-low
    INTO datstr SEPARATED BY space.
  ENDIF.
  IF ls_sel-option EQ 'BT' AND ls_sel-sign EQ 'I'.
    CONCATENATE tmpstr 'mara~matnr' 'BETWEEN' ls_sel-low
    'AND' ls_sel-high INTO datstr SEPARATED BY space.
  ENDIF.
  IF ls_sel-option EQ 'EQ' AND ls_sel-sign EQ 'E'.
    CONCATENATE tmpstr 'mara~matnr' 'NE' ls_sel-low
    INTO datstr SEPARATED BY space.
  ENDIF.
  IF ls_sel-option EQ 'LT' AND ls_sel-sign EQ 'I'.
    CONCATENATE 'mara~matnr' 'LE' ls_sel-low
    INTO datstr SEPARATED BY space.
  ENDIF.
  IF ls_sel-option EQ 'LT' AND ls_sel-sign EQ 'E'.
    CONCATENATE tmpstr 'mara~matnr' 'LT' ls_sel-low
    INTO datstr SEPARATED BY space.
  ENDIF.
  IF ls_sel-option EQ 'GT' AND ls_sel-sign EQ 'I'.
    CONCATENATE tmpstr 'mara~matnr' 'GE' ls_sel-low
    INTO datstr SEPARATED BY space.
  ENDIF.
  IF ls_sel-option EQ 'GT' AND ls_sel-sign EQ 'E'.
    CONCATENATE tmpstr 'mara~matnr' 'GT' ls_sel-low
    INTO datstr SEPARATED BY space.
  ENDIF.

ENDLOOP.

SELECT * FROM mara WHERE (datstr).
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;austin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 05:32:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173181#M123674</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T05:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Range table to Build SQL Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173182#M123675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok. I finaly solved it myself. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All the ideas above were great but, I was really looking for something that was a litte more standard SAP, rather than custom built from scratch.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAP has a function module that you can pass a range table too, and it basically gves you back the where statement really cool. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- Take a look at FREE_SELECTIONS_RANGE_2_WHERE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for all your help...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 14:54:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-range-table-to-build-sql-statement/m-p/1173182#M123675</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T14:54:46Z</dc:date>
    </item>
  </channel>
</rss>

