Application Development 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: 

Using IN in IF statements

Wil_Wilstroth
Active Participant
0 Kudos
115

Hi all,

I have a problem using the IN syntax in IF statements. Below is an example:

data : v_hkont like bseg-hkont.

selection-options : s_variable for bseg-hkont default '0010000' to '0020000',

s_variable2 for bseg-hkont default '0020001' to '0030000'.

v_hkont = '0025000'.

if v_hkont IN s_variable or v_hkont IN s_variable2.

"do something.

endif.

Do you think is this the right way to use the syntax IN in IF statement for this situation?

Because i need to do such scenario and i find the IF statement with IN syntax is not working correctly.

Regards

William Wilstroth

William Wilstroth
1 ACCEPTED SOLUTION

Former Member
0 Kudos
91

Hi William,

Guess the code seems to be fine and you can use IN statement in IF statement. I have used it that way and it has worked for me in the past.

Cheers

VJ

6 REPLIES 6

Former Member
0 Kudos
92

Hi William,

Guess the code seems to be fine and you can use IN statement in IF statement. I have used it that way and it has worked for me in the past.

Cheers

VJ

Former Member
0 Kudos
91

Hi William :

This could solve your problem .

select-options cannt have variable names more than 8 characters .

data : v_hkont like bseg-hkont.

select-options :

s_var for v_hkont default '0010000' to '0020000',

s_var2 for v_hkont default '0020001' to '0030000'.

v_hkont = '0025000'.

if v_hkont IN s_var or v_hkont IN s_var2.

write 'hi' .

else.

write 'bye'.

endif.

Former Member
0 Kudos
91
Yes thats the correct way ,  

tr this..

s_variable-sign = 'I'.
s_variable-option = 'BT'.
s_variable-low = '0000200001'.
s_variable-high = '0000300000'.
append s_variable

and use this in IF

Former Member
0 Kudos
91

Your declaration is wrong.

you have to select-options not selection-options.

and the select options variable should not be more than 8 characters.

i have modified your code. see below it is working fine.

tables: bseg.

data : v_hkont like bseg-hkont.

select-options : s_var for bseg-hkont default '0010000' to '0020000',

s_var1 for bseg-hkont default '0020001' to '0030000'.

v_hkont = '0025000'.

if v_hkont IN s_var or v_hkont IN s_var1.

"do something.

endif.

Former Member
0 Kudos
91

<b>EXAMPLE</b>

IF ( v_reqdate BETWEEN s_rdate-low AND s_rdate-high )

OR v_reqdate EQ s_rdate-low OR s_rdate IS INITIAL.

ENDIF.

Change u r code like this,

data : v_hkont like bseg-hkont.

<b>select-options : s_var for bseg-hkont default '0010000' to '0020000',

s_var2 for bseg-hkont default '0020001' to '0030000'.

</b>

v_hkont = '0025000'.

<b>if ( ( v_hkont BETWEEN s_var-low AND s_var-high ) or ( v_hkont BETWEEN s_var2-low AND s_var2-high ) ).

"do something.

endif.</b>

Wil_Wilstroth
Active Participant
0 Kudos
91

HI all,

First of all, i make a mistake in my question.

I have got it mix up. I am supposed to ask why i can't use IN with range using NO INTERVAL.

I am very happy that everyone contributed to my problem. Of course all your answer will work.

I just got confused with the range using NO INTERVAL.

I have figured this out.

IF i declared

select-options : s_v1 for bseg-hkont default '0000100000' NO INTERVAL.

I cannot use IN in IF statement but i should use EQ.

One more thing, you guys are particular with my declaration. Everyone is sharp!

Thanks to all.

Appreciated

William Wilstroth

William Wilstroth