Skip to Content
0

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

Nov 07, 2016 at 11:23 AM

219

avatar image

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

10 |10000 characters needed characters left characters exceeded

You can use both AND and OR in SELECT statement, so what exactly is the issue? I'm confused...

1
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Raghu Govindarajan Nov 07, 2016 at 10:23 PM
1

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.

Share
10 |10000 characters needed characters left characters exceeded
Sandra Rossi Nov 10, 2016 at 08:01 AM
1

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_*

Share
10 |10000 characters needed characters left characters exceeded
Nikhil Jacob Nov 10, 2016 at 05:42 AM
0

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'

Share
10 |10000 characters needed characters left characters exceeded