Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Analog to "IN" operator for ABAP?

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...

Tags:
Former Member
Former Member replied

>

> >

> > 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.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question