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: 

Analog to "IN" operator for ABAP?

Former Member

If I have a parameter into a function module (or subroutine, for that matter), that's a string and I need to process based upon certain groups of the possible values is there a way I can check using something like an "IN" operator?

For example:


IF p_code_in EQ 'A100' OR p_code_in EQ 'A200' OR p_code_in EQ 'A300'.
    PERFORM subroutine1.
ELSE...

would become


IF p_code IN ('A100','A200','A300')
ELSE...

1 ACCEPTED SOLUTION

former_member156446
Active Contributor
0 Kudos

How about this

IF p_code CS ('A100','A200','A300') .

CS is contain string

7 REPLIES 7

Former Member
0 Kudos

The only commands I know are search and find, but neither one will do what you want to do.

Maybe write up a function module that can take as input parameter a string like:

A100]A200]A300

Additionaly, p_code_in as input.

Inside the function, cycle through this string reading each value seperated by "]" and do a find on p_code_in?

This way, you just have to append to the input parameter for the function call to add additional AXXX values.

FYI: I haven't ABAP'ed in a while, maybe there is a command that will do "IN". In that case, just ignore what I wrote above.

Former Member
0 Kudos

Hello

You can use a RANGE table do the following:


DATA:
  lt_range TYPE RANGE OF p_data,
  ls_range LIKE LINE OF lt_range.

 ls_range-sign = 'I'.
 ls_range-option = 'EQ'.
 ls_range-low = 'A100'.
 APPEND ls_range to lt_range.

 ls_range-low = 'A200'.
 APPEND ls_range to lt_range.

 ls_range-low = 'A300'.
 APPEND ls_range to lt_range.

IF p_code IN lt_range....
...

Regards.

former_member156446
Active Contributor
0 Kudos

How about this

IF p_code CS ('A100','A200','A300') .

CS is contain string

0 Kudos

>

> How about this

> IF p_code CS ('A100','A200','A300') .

>

> CS is contain string

Shouldn't that be:

IF p_code CS 'A100' OR p_code CS 'A200' OR p_code CS 'A300'.

0 Kudos

opps.. ur right.. I was just looking to replace IN.. thanks Mat

0 Kudos

>

> >

> > How about this

> > IF p_code CS ('A100','A200','A300') .

> >

> > CS is contain string

>

> Shouldn't that be:

>

> IF p_code CS 'A100' OR p_code CS 'A200' OR p_code CS 'A300'.

I think this really depends on what the original poster wanted. I think the point of him wanting to replicate the IN functionality (e.g. SQL query), is for reusability. I think that what he's looking for is not having to append to the IF statement for every new "AXXX" value.

Example:

Today it is = IF p_code CS 'A100' OR p_code CS 'A200' OR p_code CS 'A300'.

Tomorrow it may be Today it is = IF p_code CS 'A100' OR p_code CS 'A200' OR p_code CS 'A300' OR p_code CS 'A400'.

Then = IF p_code CS 'A100' OR p_code CS 'A200' OR p_code CS 'A300' OR p_code CS 'A400' OR p_code CS 'A500'.

You get the idea.

I think that to truely replicate a "IN" functionality, a function module is needed. This way, you can simply append the new AXXX value into the input parameter and be done with it.

E.g.

Today it is = call new_function @conditionstring="A100;A200;A300"

Tomorrow = call new_function @conditionstring="A100;A200;A300;A400"

More time pass = call new_function @conditionstring="A100;A200;A300;A400;A500"

A lot more reusable.

Former Member
0 Kudos

Hi Friends, not worked for me:

if lv_type CS ('KR', 'AA', 'KA', 'ZP', 'ZS', 'SA', 'KG').

endif.

in the first "," is displayed in RED

why? any advice?

Thanks.