Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Jul 02, 2008 at 06:21 PM

    How about this

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

    CS is contain string

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Matthew Billingham

      >

      > >

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

  • avatar image
    Former Member
    Jul 02, 2008 at 06:12 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 02, 2008 at 06:19 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 29, 2015 at 11:32 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded