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

compare value in ranges using IF

Former Member
0 Likes
10,016

Hi,

Need an advice how to compare single value with ranges. For below code it return error

Incorrect logical expression: Comparison / SELECT-OPTION can only be

followed by "AND", "OR" or ")".

For eg.


   s_hkont = '2410000'

  r6_hkont-low  = '0000889901'.
  r6_hkont-high = '0000889903'.
  r6_hkont-sign = 'I'.
  r6_hkont-option = 'BT'.
  append r6_hkont.

IF s_hkont IN r6_hkont.
 STOP.
ENDIF.

1 ACCEPTED SOLUTION
Read only

deepak_dhamat
Active Contributor
0 Likes
3,024

HI ,

s_hkont = '2410000'
 
  r6_hkont-low  = '0000889901'.
  r6_hkont-high = '0000889903'.
  r6_hkont-sign = 'I'.
  r6_hkont-option = 'BT'.
  append r6_hkont.
 
IF s_hkont IN r6_hkont.
 STOP.
ENDIF.

Always select data in query using either r6_hkont OR s_hkont and match that data with other

Regards

Deepak.

Hi,

Need an advice how to compare single value with ranges. For below code it return error

Incorrect logical expression: Comparison / SELECT-OPTION can only be

followed by "AND", "OR" or ")".

For eg.


   s_hkont = '2410000'

  r6_hkont-low  = '0000889901'.
  r6_hkont-high = '0000889903'.
  r6_hkont-sign = 'I'.
  r6_hkont-option = 'BT'.
  append r6_hkont.

IF s_hkont IN r6_hkont.
 STOP.
ENDIF.

9 REPLIES 9
Read only

deepak_dhamat
Active Contributor
0 Likes
3,025

HI ,

s_hkont = '2410000'
 
  r6_hkont-low  = '0000889901'.
  r6_hkont-high = '0000889903'.
  r6_hkont-sign = 'I'.
  r6_hkont-option = 'BT'.
  append r6_hkont.
 
IF s_hkont IN r6_hkont.
 STOP.
ENDIF.

Always select data in query using either r6_hkont OR s_hkont and match that data with other

Regards

Deepak.

Read only

Former Member
0 Likes
3,024

Hi

you can loop through the table r6_hknot and then write your if condition inside the loop.

I hope it will work.

thanks

lalit

Read only

former_member404244
Active Contributor
0 Likes
3,024

Hi,

Try this

s_hkont = '2410000'.

R6_HKONT-LOW = '0000889901'.

r6_hkont-high = '0000889903'.

r6_hkont-sign = 'I'.

r6_hkont-option = 'BT'.

APPEND r6_hkont.

IF s_hkont-low IN r6_hkont.

STOP.

ENDIF.

Regards,

Nagaraj

Read only

Former Member
0 Likes
3,024

Hi,

Since there will be multiple values in Select-option i think you have to loop on it and then compare it as below.

LOOP AT s_hkont.
IF s_hkont-low IN r6_hkont or s_hkont-high IN r6_hkont.
STOP.
ENDIF.
ENDLOOP.

Regards,

Pawan

Read only

Former Member
0 Likes
3,024

hi thanks for the quick reply,

how about if s_hkont is also ranges data type, how to compare two ranges

IF s_hkont IN r5_hkont ?

Read only

0 Likes
3,024

Hi

you can loop through the r6_hknot table and check the values of s_hknot against r6_hknot values. like:

loop at r6_hknot.

if s_hknot-low = r6_hknot-low or

if s_hknot-high = r6_hknot-high.

then your code.

endif.

endloop.

thanks

Lalit

Read only

0 Likes
3,024

Hi,

Use it like this IF for select options :

if s_matnr-low in r_matnr or s_matnr-high in r_matnr .

code

endif.

its the same for both.

there is not much of a difference between ranges and select options.

select-options are used on selection screen and ranges for internally in the code.

both have same structure and both create internal tables.

regards,

Sakshi

Read only

0 Likes
3,024

Hi,

try this:


TABLES: SKA1.
*
RANGES: R0_HKONT FOR SKA1-SAKNR.
RANGES: R1_HKONT FOR SKA1-SAKNR.
*
CLEAR: R0_HKONT.
R0_HKONT-LOW    = '0000241000'.
R0_HKONT-SIGN   = 'I'.
R0_HKONT-OPTION = 'EQ'.
APPEND R0_HKONT.
*
CLEAR: R1_HKONT.
R1_HKONT-LOW    = '0000889901'.
R1_HKONT-HIGH   = '0000889903'.
R1_HKONT-SIGN   = 'I'.
R1_HKONT-OPTION = 'BT'.
APPEND R1_HKONT.
*
SELECT * FROM SKA1 WHERE SAKNR IN R0_HKONT
                     AND SAKNR IN R1_HKONT.
*
  WRITE: / SKA1-SAKNR, 'is in R0 and R1'.
*
ENDSELECT.
*
* OR ->
* SELECT SINGLE  * FROM SKA1 WHERE SAKNR IN R0_HKONT
*                                 AND SAKNR IN R1_HKONT.
*
IF SY-SUBRC <> 0.
  WRITE: / 'R0 and R1 does not  match'.
ENDIF.

Regards, Dieter

Read only

Former Member
0 Likes
3,024

>

>

kont IN r6_hkont.
>  STOP.
> ENDIF.
> 
> 

Normally with single value you can use

CHECK kont IN r6_hkont.