‎2005 Aug 11 4:13 PM
Dear ABAP Experts,
I have a Database Table which is used for configuring Where clauses like below
SIGN|FIELDS |OPERAND|MIN |MAX
-
1 |FIELD1 |EQ |ABC |
1 |FIELD2 |EQ |123 |
2 |FIELD1 |EQ |DEF |
2 |FIELD2 |EQ |456 |
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.
TO understand how to decode AND and OR operation
-
If the SIGN field 2 rows subsequently 1 and 1 - > its AND
If the SIGN field 2 rows subsequently 1 and 2 - > its OR
For the ABOVE data the Where clause can be decoded in this way
( field1 = 'ABC' AND field2 = '123' ) OR ( field1 = DEF' AND field2 = '456' ).
Please let me know how can this be done.
Thanks in Advance.
‎2005 Aug 11 4:16 PM
You could use the AT NEW or AT END statement if you are in a loop, or maybe the ON CHANGE OF.
For example, when the first number in the table changes from 1 to 2, code for the "OR" otherwise code for "AND".
loop at where_clause_tab.
on change of where_clause_tab-knumv.
* code "OR"
else.
* code "AND"
endon.
endloop.Regards,
Rich Heilman
‎2005 Aug 11 4:16 PM
You could use the AT NEW or AT END statement if you are in a loop, or maybe the ON CHANGE OF.
For example, when the first number in the table changes from 1 to 2, code for the "OR" otherwise code for "AND".
loop at where_clause_tab.
on change of where_clause_tab-knumv.
* code "OR"
else.
* code "AND"
endon.
endloop.Regards,
Rich Heilman
‎2005 Aug 11 4:24 PM
Check this FM RSAN_FILL_DYNAMICAL_SELECT.
It takes selection options and converts them to where clause.
It does not cover all the possible operators like NOT and other. You may create custom FM and make it more intelligent.
thanks,
venu
‎2005 Aug 11 4:32 PM
Hi, assume all the entries have been selected into ITAB
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.The code above is for reference, can't be compiled successfully. Just for reflect an idea.
Hope it will be helpful. Thanks a lot
Message was edited by: zhenglin gu
‎2005 Aug 11 4:52 PM
Hi,
Check this document for reference:
https://webphl07.phl.sap.corp/~sapidb/011000358700002805272003E
regards
Aveek
‎2005 Aug 11 5:19 PM
Hello Aveek Ghose ,
I was not able to get this link on? Any help
‎2005 Aug 11 7:37 PM
‎2008 Mar 03 10:53 AM