06-30-2010 7:39 AM
Dear forum,
can the below if statement
if p_waers = 'EUR' or p_waers = 'AUD' or p_waers = 'NZD' or p_waers = 'GBP'.
change to
if p_waers IN ( 'EUR' , 'AUD' , 'NZD' ) ?
i tried but not possible. why?
thanks
06-30-2010 7:52 AM
In ABAP it is not possible this way. What I usually do instead is
case p_wears.
when 'EUR' or 'AUD' or 'NZD' or 'GBP'.
...
when others.
..
endcase.
Regards
Marcin
06-30-2010 7:48 AM
Hello
It is because you do not read help for Logical Expressions - Comparison with a Selection Criterion
You need to create ranges for waers, fill it with your waers and in IF statement compare with ranges.
06-30-2010 7:49 AM
Hi,
You can populate all the values in to a range variable and then you can use IN. Answer for Why is, it is the way ABAP language syntax was created by SAP
r_waers-sign = 'I'.
r_waers-option = 'EQ'.
r_waers-low = 'EUR'.
APPEND r_waers.
r_waers-low = 'AUD'.
APPEND r_waers.
r_waers-low = 'NZD'.
APPEND r_waers.
IF p_waers IN r_waers.
Thanks,
Vinod.
06-30-2010 7:52 AM
In ABAP it is not possible this way. What I usually do instead is
case p_wears.
when 'EUR' or 'AUD' or 'NZD' or 'GBP'.
...
when others.
..
endcase.
Regards
Marcin
06-30-2010 7:53 AM
the IN logical operator requires a comparision against a select-option type structure, so would require something like
data: l_waers type waers.
select-options s_waers for l_waers no-display.
s_waers-sign = 'I'.
s_waers-option = 'EQ'.
s_waers-low = 'EUR'.
APPEND s_waers TO s_waers.
s_waers-sign = 'I'.
s_waers-option = 'EQ'.
s_waers-low = 'AUD'.
APPEND s_waers TO s_waers.
s_waers-sign = 'I'.
s_waers-option = 'EQ'.
s_waers-low = 'NZD
APPEND s_waers TO s_waers.
if p_waers in s_waers.
endif.
However a quicker alternative may be
if 'EUR AUD NZD' CS p_waers then.
endif.
06-30-2010 8:45 AM
replace
if p_waers IN ( 'EUR' , 'AUD' , 'NZD' )
with
if p_waers IN ('EUR','AUD','NZD')
(same code without spaces inside the brackets)
05-14-2013 2:32 AM
Hi Henri,
I was surprised at this solution but I thought I would give it a go.
I find that this code does not compile:
if p_waers IN ('EUR','AUD','NZD').
with or without spaces.
The best solution here is to use a ranges object as Vinod Vemuru correctly describes.
Unfortunately Manish Kumar you can use in with an if and Suraj Nair it is not always recommended to use a case statement in this situation.
05-14-2013 4:46 AM
Depends on the intended usage of IN keyword.
IN keyword can be used with values like IN ('EUR','AUD','NZD') or selection table.
Within an IF, IN can be used if you are using selection table, and not if you are using values list.
Within SELECT..WHERE, IN ('EUR','AUD','NZD') will work.
Creating a range table for matching a fixed list of values in IF statement isn't worth the effort.
05-14-2013 5:27 AM
Yes abap is a little inconsistent at the best of times.
Whether a range table is worth the effort is a case by case basis. I would say it is much better than a case statement given that there is no breaking from a case and fall through that you get in a c switch.
06-30-2010 9:35 AM
The reason why IN keyword does not work for you is that it can be used with WHERE keyword, but not with IF keyword.
06-30-2010 9:41 AM
hI,
Its always recommended to use CASE ... END CASE in this situation..
Thanks
Suraj