Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Is it possible to dynamically replace a comparison operator?

Former Member
0 Likes
670

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.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
622

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

5 REPLIES 5
Read only

Former Member
0 Likes
622

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

Read only

sridhar_meesala
Active Contributor
0 Likes
622

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.

Read only

0 Likes
622

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.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
622

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
623

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