<?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: Need Help in Constructing where clause Dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963734#M68031</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use the AT NEW or AT END statement if you are in a loop,  or maybe the ON CHANGE OF.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, when the first number in the table changes from 1 to 2,  code for the "OR" otherwise code for "AND".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at where_clause_tab.

  on change of where_clause_tab-knumv.
* code "OR"
  else.
* code "AND"
  endon.


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;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Aug 2005 15:16:38 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2005-08-11T15:16:38Z</dc:date>
    <item>
      <title>Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963733#M68030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear ABAP Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a Database Table which is used for configuring Where clauses like below &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SIGN|FIELDS |OPERAND|MIN |MAX&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------" /&gt;&lt;P&gt;1   |FIELD1 |EQ     |ABC |	&lt;/P&gt;&lt;P&gt;1   |FIELD2 |EQ     |123 |	&lt;/P&gt;&lt;P&gt;2   |FIELD1 |EQ     |DEF |	&lt;/P&gt;&lt;P&gt;2   |FIELD2 |EQ     |456 |	&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Database table will have the data like the one showed above. I Have to construct the "where clause" based on the availabe data as shown above dynamically. 							&lt;/P&gt;&lt;P&gt;TO understand how to decode AND and OR operation&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------" /&gt;&lt;P&gt;						&lt;/P&gt;&lt;P&gt;If the SIGN field 2 rows subsequently  1 and 1 - &amp;gt; its AND&lt;/P&gt;&lt;P&gt;If the SIGN field 2 rows subsequently  1 and 2 - &amp;gt; its OR							&lt;/P&gt;&lt;P&gt;For the ABOVE data the Where clause can be decoded in this way &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;( field1 = 'ABC' AND field2 = '123' ) OR ( field1 = DEF' AND field2 = '456' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know how can this be done.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in Advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 15:13:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963733#M68030</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T15:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963734#M68031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use the AT NEW or AT END statement if you are in a loop,  or maybe the ON CHANGE OF.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, when the first number in the table changes from 1 to 2,  code for the "OR" otherwise code for "AND".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at where_clause_tab.

  on change of where_clause_tab-knumv.
* code "OR"
  else.
* code "AND"
  endon.


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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 15:16:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963734#M68031</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-08-11T15:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963735#M68032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this FM RSAN_FILL_DYNAMICAL_SELECT.&lt;/P&gt;&lt;P&gt;It takes selection options and converts them to where clause.&lt;/P&gt;&lt;P&gt;It does not cover all the possible operators like NOT and other. You may create custom FM and make it more intelligent.&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;venu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 15:24:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963735#M68032</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T15:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963736#M68033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, assume all the entries have been selected into ITAB&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: str_where  type string,
      str_temp   type string,
      conca_flag type char1.

sort itab.
loop at itab into lc_itab.
  at new sign.
    conca_flag = 'x'.
  endat.
  if conca_flag = 'x'.
    if str_temp is intial.
      concatenate FIELDS '=' MIN into str_temp. 
    else
      concatenate 'and' FIELDS '=' MIN into str_temp.
    endif.
  endif.
  at end of sign.
    if str_where is initial.
      concatenate '(' str_temp ')' into str_where. 
    else.
      concatenate 'or' '(' str_temp ')' into str_where. 
    endif.
    clear conca_flag.
    clear str_temp .
  endat.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code above is for reference, can't be compiled successfully. Just for reflect an idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it will be helpful. Thanks a lot&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: zhenglin gu&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 15:32:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963736#M68033</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T15:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963737#M68034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  Check this document for reference:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://webphl07.phl.sap.corp/~sapidb/011000358700002805272003E" target="test_blank"&gt;https://webphl07.phl.sap.corp/~sapidb/011000358700002805272003E&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aveek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 15:52:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963737#M68034</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T15:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963738#M68035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Aveek Ghose ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was not able to get this link on? Any help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 16:19:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963738#M68035</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T16:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963739#M68036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;  it is in FAQ in abap.&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;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aveek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2005 18:37:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963739#M68036</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-08-11T18:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Constructing where clause Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963740#M68037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all of you for the resoponses.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Mar 2008 10:53:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-constructing-where-clause-dynamically/m-p/963740#M68037</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-03T10:53:58Z</dc:date>
    </item>
  </channel>
</rss>

