‎2009 Aug 06 11:04 AM
Hi folks,
Is it possible to change a comparison operator dynamically? For example:
IF A = B.
then w_operator = '>' .
else.
w_operator = '<'.
.
.
.
Select * From ZTABLE where DATE w_operator SY-DATUM.
.
.
.
.
Your help is greatly appreciated.
‎2009 Aug 06 11:47 AM
Use a RANGE and an IN operator, like
DATA r_date TYPE RANGE OF syst-datum WITH HEADER LINE.
REFRESH r_date.
CLEAR r_date.
r_date-sign = 'I'.
IF A = B.
r_date-option = 'GT'.
ELSE.
r_date-option = 'LT'.
ENDIF.
r_date-low = sy-datum.
APPEND r_date.
SELECT * FROM ztable WHERE date IN r_date.Regards,
Raymond
‎2009 Aug 06 11:17 AM
Hi,
Well am not sure if that is possible , anyway u can use the normal method as i dont see any harm in using it performance wise.
if A = B.
Select * From ZTABLE where DATE > SY-DATUM.
else.
Select * From ZTABLE where DATE < SY-DATUM.
endif.
Regards,
Vik
‎2009 Aug 06 11:20 AM
Hi,
Insted you can write your query directly like this:
IF A = B.
Select *
From ZTABLE
where DATE GT SY-DATUM.
ELSE.
Select *
From ZTABLE
where DATE LT SY-DATUM.
ENDIF.Thanks,
Sri.
‎2009 Aug 06 11:28 AM
Hello friends,
Thanks for your replies, However, there is far more involved than I have written in my example. I tried to give a very simplified pseudo code. My objective is exactly the opposite of the suggested solutions so far. That is to say, I'd like to avoid repeating the same SELECT statement twice lest a minor difference.
Thanks for your input. Am still listening.
‎2009 Aug 06 11:34 AM
TABLES:mara.
DATA:w_operator TYPE c.
DATA:a TYPE i,b TYPE i.
DATA:LT TYPE C VALUE '<',GT TYPE C VALUE '>'.
TYPES:BEGIN OF ty_where,
where_clause TYPE char255,
END OF ty_where.
DATA:it_where TYPE TABLE OF ty_where,
wa_where TYPE ty_where.
a = b = 1.
IF a = b.
w_operator = GT .
ELSE.
w_operator = LT.
ENDIF.
CONCATENATE 'DATE' w_operator sy-datum INTO wa_where-where_clause SEPARATED BY space..
APPEND wa_where TO it_where.
SELECT SINGLE * FROM mara WHERE (it_where).
Edited by: Keshu Thekkillam on Aug 6, 2009 4:14 PM
‎2009 Aug 06 11:47 AM
Use a RANGE and an IN operator, like
DATA r_date TYPE RANGE OF syst-datum WITH HEADER LINE.
REFRESH r_date.
CLEAR r_date.
r_date-sign = 'I'.
IF A = B.
r_date-option = 'GT'.
ELSE.
r_date-option = 'LT'.
ENDIF.
r_date-low = sy-datum.
APPEND r_date.
SELECT * FROM ztable WHERE date IN r_date.Regards,
Raymond