<?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 select-statement with ranges in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228017#M1380145</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Hymavathi:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error is the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;An exception occurred that is explained in detail below.&lt;/P&gt;&lt;P&gt;The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was&lt;/P&gt;&lt;P&gt; not caught and&lt;/P&gt;&lt;P&gt;therefore caused a runtime error.&lt;/P&gt;&lt;P&gt;The reason for the exception is:&lt;/P&gt;&lt;P&gt;The current ABAP program has tried to execute an Open SQL statement&lt;/P&gt;&lt;P&gt;which contains a WHERE, ON or HAVING condition with a dynamic part.&lt;/P&gt;&lt;P&gt;The part of the WHERE, ON or HAVING condition specified at runtime in&lt;/P&gt;&lt;P&gt;a field or an internal table, contains the invalid value&lt;/P&gt;&lt;P&gt; "GT_CONDITIONS[1]-RANGES".&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Hymavathi, second time:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the whole code for the select:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT gt_conditions INTO gs_conditions.
  l_index = sy-tabix.
  CONCATENATE 'gt_conditions[' l_index ']-ranges' INTO l_condition.
  CONDENSE l_condition NO-GAPS.

  CONCATENATE gs_conditions-fieldname 'IN' l_condition INTO lt_condition SEPARATED BY space.
  IF sy-tabix &amp;gt; 1.
    CONCATENATE 'AND' lt_condition INTO lt_condition SEPARATED BY space.
  ENDIF.
  APPEND lt_condition.
ENDLOOP.

SELECT * FROM (p_tab)
   INTO TABLE &amp;lt;gt_table&amp;gt;
        WHERE (lt_condition).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see, the select is after the loop. So gs_conditions-ranges wouldn't be right, then the where statement would only use the last range-tab from my table gt_conditions. (loop at...endloop =&amp;gt; gs-conditions-range = last gt_conditions-range).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Sep 2009 07:38:19 GMT</pubDate>
    <dc:creator>michael_fallenbchel</dc:creator>
    <dc:date>2009-09-30T07:38:19Z</dc:date>
    <item>
      <title>Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228009#M1380137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good morning experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just wanted to know if this is possible:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a report with a selection-screen where I can enter a table-name and one ore more filed-names (separated by ;).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After that, I create a table like my entered (for example MARA) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CREATE DATA gt_table TYPE TABLE OF (p_tab).
ASSIGN gt_table-&amp;gt;* TO &amp;lt;gt_table&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I split my entered fields (at &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt; and for each filed I made a selection (with function COMPLEX_SELECTIONS_DIALOG).&lt;/P&gt;&lt;P&gt;Result of this is for each field a range-tab which I write in a new table - first column is the name of the field, second column is a range-tab:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF t_ranges,
          sign TYPE tkeppllevs-sign,
          opt  TYPE tkeppllevs-opt,
          low  TYPE rsdslow,
          high TYPE rsdslow,
        END OF t_ranges.

DATA: BEGIN OF gs_conditions,
        fieldname TYPE string,
        ranges    TYPE TABLE OF t_ranges.
DATA: END OF gs_conditions.
DATA: gt_conditions LIKE TABLE OF gs_conditions.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I want to make a select on the entered table (MARA).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I make a loop on my gt_conditions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT gt_conditions INTO gs_conditions.
  l_index = sy-tabix.
 CONCATENATE 'gt_conditions[' l_index ']-ranges' INTO l_condition.
  CONDENSE l_condition NO-GAPS.
  CONCATENATE gs_conditions-fieldname 'IN' l_condition INTO lt_condition SEPARATED BY space.
  IF sy-tabix &amp;gt; 1.
    CONCATENATE 'AND' lt_condition INTO lt_condition SEPARATED BY space.
  ENDIF.
  APPEND lt_condition.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I look at it after the loop, it looks correct:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MATNR IN gt_conditions[1]-ranges&lt;/P&gt;&lt;P&gt;AND ERSDA IN gt_conditions[2]-ranges&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this wont work because of "gt_conditions[1]-ranges". I know, i can work with the "table in table", because gs_conditions-ranges works (I already tested this).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anybody any idea how to make my idea work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 06:01:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228009#M1380137</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-09-30T06:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228010#M1380138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you try to use FM like CONVERT_SELECT_INTO_WHERE, ADSPC_CREATE_WHERE_CLAUSE, DYNSQL_GENERATE_WHERE_CLAUSE or FREE_SELECTIONS_RANGE_2_WHERE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Raymond&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 06:42:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228010#M1380138</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2009-09-30T06:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228011#M1380139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN __default_attr="blue" __jive_macro_name="color"&gt;Hi Michael,
Your definition to range table is wrong i believe. To use IN operator for MATNR, you need to do the following way your declarations.
&lt;PRE&gt;&lt;CODE&gt;
TYPES: BEGIN OF t_ranges,
          sign TYPE tkeppllevs-sign,
          opt  TYPE tkeppllevs-opt,
          low  TYPE rsdslow,
          high TYPE rsdslow,
        END OF t_ranges.
 
DATA: BEGIN OF gs_conditions,
        fieldname TYPE string,
        ranges    TYPE TABLE OF t_ranges.
DATA: END OF gs_conditions.
DATA: gt_conditions LIKE TABLE OF gs_conditions.
&lt;/CODE&gt;&lt;/PRE&gt;
Change above code to below code
&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF gs_conditions,
        fieldname TYPE string,
        ranges    TYPE RANGE OF mara-matnr. "This is like defining SELECT-OPTIONS
DATA: END OF gs_conditions.
DATA: gt_conditions LIKE TABLE OF gs_conditions.&lt;/CODE&gt;&lt;/PRE&gt;

Thanks
Venkat.O&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 06:58:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228011#M1380139</guid>
      <dc:creator>venkat_o</dc:creator>
      <dc:date>2009-09-30T06:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228012#M1380140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Raymond: Thanks for your input, I will check those FMs, maybe the right is there...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Venkat: No, you''re not right. I I will made my definition like you say, there only can be entered a range of MATNR. I want to save there a table of any range I enter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: I enter fields MATNR and ERSDA in my selections screen:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have to ranges, one for MATNR (maybe from 1 to 200 and 500 - 1000), and one for ERSDA (maybe 01.01.2000 to 31.12.2000 and NOT 01.06.2000), so my table with the conditions would look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MATNR_____RANGE&lt;/P&gt;&lt;P&gt;ERSDA_____RANGE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you open the ranges, the table would look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MATNR____BT_001_200&lt;/P&gt;&lt;P&gt;__________BT_500_1000&lt;/P&gt;&lt;P&gt;ERSDA____BT_01012000_31122000&lt;/P&gt;&lt;P&gt;__________NT_01062000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you know what I mean? I I make al oop on the conditions-table into gs_conditions, the first row would look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gs_conditions-fieldname = MATNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gs_conditions-range:&lt;/P&gt;&lt;P&gt;BT_001_200&lt;/P&gt;&lt;P&gt;BT_500_1000&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 07:09:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228012#M1380140</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-09-30T07:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228013#M1380141</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 not understand as why are you declaring ranges like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF t_ranges,&lt;/P&gt;&lt;P&gt;          sign TYPE tkeppllevs-sign,&lt;/P&gt;&lt;P&gt;          opt  TYPE tkeppllevs-opt,&lt;/P&gt;&lt;P&gt;          low  TYPE rsdslow,&lt;/P&gt;&lt;P&gt;          high TYPE rsdslow,&lt;/P&gt;&lt;P&gt;        END OF t_ranges.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;why cant you use ranges stamenet directly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ranges: t_ranges for  MARA-MATNR (Example)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now t_ranges behaves like select-options.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in your internal table, you can declare like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF gs_conditions,&lt;/P&gt;&lt;P&gt;        fieldname TYPE string,&lt;/P&gt;&lt;P&gt;        ranges    TYPE TABLE OF t_ranges.&lt;/P&gt;&lt;P&gt;DATA: END OF gs_conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now you can use gs_conditions-low and gs_conditions-high in your slect queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from &amp;lt;dbtab&amp;gt; into &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;where &amp;lt;fieldvalue&amp;gt; in gs_conditions-ranges.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from &amp;lt;dbtab&amp;gt; into &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;where &amp;lt;fieldvalue&amp;gt; = gs_conditions-low.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 07:12:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228013#M1380141</guid>
      <dc:creator>hymavathi_oruganti</dc:creator>
      <dc:date>2009-09-30T07:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228014#M1380142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I try to explain:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't want to use the ranges for a specific field - I want to use it for every field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The user enters a table and the fields, I don't know what he enters...so I cant make the ranges like t_ranges for MARA-MATNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also I can't make the select statement "static" with a specific field, I have to "build" the where-statement completely:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM (p_tab)
   INTO TABLE &amp;lt;gt_table&amp;gt;
        WHERE (lt_condition).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it clearer now?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 07:18:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228014#M1380142</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-09-30T07:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228015#M1380143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;can you tell me whats the error you are getting when you are using the logic given by you?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 07:25:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228015#M1380143</guid>
      <dc:creator>hymavathi_oruganti</dc:creator>
      <dc:date>2009-09-30T07:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228016#M1380144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;tell me one thing,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT gt_conditions INTO gs_conditions.&lt;/P&gt;&lt;P&gt;  l_index = sy-tabix.&lt;/P&gt;&lt;P&gt; CONCATENATE 'gt_conditions[' l_index ']-ranges' INTO l_condition.&lt;/P&gt;&lt;P&gt;  CONDENSE l_condition NO-GAPS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are inside the loop and you are sure that you are accessing first record of gt_conditions, then y to use index again?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;why cant the below code work? try using wok area "gs_conditions" instead of gt_conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT gt_conditions INTO gs_conditions.&lt;/P&gt;&lt;P&gt;  l_index = sy-tabix.&lt;/P&gt;&lt;P&gt; CONCATENATE  &lt;STRONG&gt;'gs_conditions-ranges'&lt;/STRONG&gt;  INTO l_condition.&lt;/P&gt;&lt;P&gt;  CONDENSE l_condition NO-GAPS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 07:29:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228016#M1380144</guid>
      <dc:creator>hymavathi_oruganti</dc:creator>
      <dc:date>2009-09-30T07:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228017#M1380145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Hymavathi:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error is the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;An exception occurred that is explained in detail below.&lt;/P&gt;&lt;P&gt;The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was&lt;/P&gt;&lt;P&gt; not caught and&lt;/P&gt;&lt;P&gt;therefore caused a runtime error.&lt;/P&gt;&lt;P&gt;The reason for the exception is:&lt;/P&gt;&lt;P&gt;The current ABAP program has tried to execute an Open SQL statement&lt;/P&gt;&lt;P&gt;which contains a WHERE, ON or HAVING condition with a dynamic part.&lt;/P&gt;&lt;P&gt;The part of the WHERE, ON or HAVING condition specified at runtime in&lt;/P&gt;&lt;P&gt;a field or an internal table, contains the invalid value&lt;/P&gt;&lt;P&gt; "GT_CONDITIONS[1]-RANGES".&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Hymavathi, second time:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the whole code for the select:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT gt_conditions INTO gs_conditions.
  l_index = sy-tabix.
  CONCATENATE 'gt_conditions[' l_index ']-ranges' INTO l_condition.
  CONDENSE l_condition NO-GAPS.

  CONCATENATE gs_conditions-fieldname 'IN' l_condition INTO lt_condition SEPARATED BY space.
  IF sy-tabix &amp;gt; 1.
    CONCATENATE 'AND' lt_condition INTO lt_condition SEPARATED BY space.
  ENDIF.
  APPEND lt_condition.
ENDLOOP.

SELECT * FROM (p_tab)
   INTO TABLE &amp;lt;gt_table&amp;gt;
        WHERE (lt_condition).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see, the select is after the loop. So gs_conditions-ranges wouldn't be right, then the where statement would only use the last range-tab from my table gt_conditions. (loop at...endloop =&amp;gt; gs-conditions-range = last gt_conditions-range).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 07:38:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228017#M1380145</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-09-30T07:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228018#M1380146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got it!! Thanks all for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For whom is interested - this is it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: lt_field_ranges  TYPE rsds_trange.
DATA: ls_field_ranges  TYPE rsds_range.
DATA: ls_rsds_trange   TYPE rsds_frange.
DATA: lt_where_clauses TYPE rsds_twhere.
DATA: ls_where_clauses TYPE rsds_where.

(...)

ls_field_ranges-tablename = p_tab.

LOOP AT gt_conditions INTO gs_conditions.
  ls_rsds_trange-fieldname = gs_conditions-fieldname.
  ls_rsds_trange-selopt_t[] = gs_conditions-ranges[].
  APPEND ls_rsds_trange TO ls_field_ranges-frange_t.
ENDLOOP.
APPEND ls_field_ranges TO lt_field_ranges.

CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'
  EXPORTING
    field_ranges  = lt_field_ranges
  IMPORTING
    where_clauses = lt_where_clauses.


LOOP AT lt_where_clauses INTO ls_where_clauses.
  SELECT * FROM (p_tab)
     INTO TABLE &amp;lt;gt_table&amp;gt;
          WHERE (ls_where_clauses-where_tab).
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you all for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 08:12:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228018#M1380146</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-09-30T08:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic select-statement with ranges</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228019#M1380147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field symbols: &amp;lt;fs&amp;gt; type any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT gt_conditions INTO gs_conditions.&lt;/P&gt;&lt;P&gt;  l_index = sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assign component ranges of structure gs_conditions to &amp;lt;fs&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  CONCATENATE gs_conditions-fieldname 'IN' &amp;lt;fs&amp;gt; INTO lt_condition SEPARATED BY space.&lt;/P&gt;&lt;P&gt;  IF sy-tabix &amp;gt; 1.&lt;/P&gt;&lt;P&gt;    CONCATENATE 'AND' lt_condition INTO lt_condition SEPARATED BY space.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;  APPEND lt_condition.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 08:32:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-select-statement-with-ranges/m-p/6228019#M1380147</guid>
      <dc:creator>hymavathi_oruganti</dc:creator>
      <dc:date>2009-09-30T08:32:00Z</dc:date>
    </item>
  </channel>
</rss>

