Skip to Content
avatar image
Former Member

Search using Logical operators like AND/OR/NOT in ABAP

Hello,

My requirement is to search the table say HRP1000->MC_STEXT using logical operators.

The user would just enter "Management AND Engineering OR Research" and I get the desired results. We wont be able to use TREX as the ECC system doesn't have it installed.

Could you please let me know if this is possible with any other way.

Thank you.

Regards,

Nikhil

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Nov 07, 2016 at 10:23 PM

    If you are trying this on a single field, you will have to build your own routine to parse the users request and then use something like a selection range or a dynamic where clause. No built-in way, but it is achievable.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 10, 2016 at 08:01 AM

    It's just an algorithm.

    You just need to add the field name at first position and after AND NOT, OR NOT, AND (?!NOT), OR (?!NOT) (expressed in regular expression), and you need to add quotes where they do not exist (still with regular expressions).

    But it depends of the valid syntax (are parentheses allowed, priority of operators, wild cards, etc.) which is not clear for us:

    Things not clear like for instance, in CUST OR MANAGEMENT OR DEGREE NOT ENGG AND "DIPLOMA LVL1", what does mean "OR DEGREE NOT ENGG"???

    Anyway, that should be converted into something like:

    field = 'CUST' OR field = 'MANAGEMENT' OR field = 'DEGREE' AND NOT field = 'ENGG' AND field = 'DIPLOMA LVL1'

    There is still the priority of operators to define in the expression. Next, I suggest that you have a look at function modules FREE_SELECTIONS_*

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 10, 2016 at 05:42 AM

    Thank you for your replies,

    Yes i have build the logic to translate the user text into variables which can be used using the 'IN' operator using range table for the selected table.

    Search examples ->

    1) CUST AND "MANGEMENT DEGREE"

    2) CUST OR MANAGEMENT OR DEGREE NOT ENGG AND "DIPLOMA LVL1"

    This might be helpful to people in the future. This works fine for now but still would need to do some regression testing.

    For OR condition

    r-sign = 'I'

    r-option = 'CP'

    For AND condition

    r-sign = 'E'

    r-option = 'NP'

    For NOT condition

    r-sign = 'E'

    r-option = 'CP'

    Add comment
    10|10000 characters needed characters exceeded