From Relational Operator to Predicate Function
How about a new check to convert a relational operator to a predicate function?
| Relational Operator | Predicate Function |
|---|---|
| o1 CO o2 | NOT contains_any_not_of( val = o1 sub = o2 ) |
| o1 CN o2 | contains_any_not_of( val = o1 sub = o2 ) |
| o1 CA o2 | contains_any_of( val = o1 sub = o2 ) |
| o1 NA o2 | NOT contains_any_of( val = o1 sub = o2 ) |
| o1 CS o2 | contains( val = to_upper( o1 ) sub = to_upper( o2 ) ) |
| o1 NS o2 | NOT contains( val = to_upper( o1 ) sub = to_upper( o2 ) ) |
Source: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abencontains_functions.htm
Most of the non-ABAP developers do not understand the ABAP-specific relational operators.
The operators CP and NP can be replaced by the predicate function contains and a suitable regular expression. The differences in case handling must also be respected here. Generally, a simple mapping like in CS and NS is not possible, but is also not usually required.
Just my opinion, but I find the relational operators far shorter and readable, as is obvious from the list above. Yes, they're not common in other languages but are not hard to learn. Consider a real-world usage:
IF contains_any_of( val = sy-msgty sub = 'AEX' ).
vs.
IF sy-msgty CA 'AEX'.
String predicate functions are one of the few new ABAP features I have not fully embraced, I just find them awkward and only use them if a functional position is really required. If we want to compare to other languages, we can add JS to the example above:
IF sy-msgty CA 'AEX'.
if(msgty.match(/(A|E|X)/))
IF contains_any_of( val = sy-msgty sub = 'AEX' ).
I am not aware this is in the style guides either. As I said this is just my opinion though, perhaps some may find it useful but I would likely disable this check. I just can't see any benefit to limiting the use of relational operators.
Let's start a thread in the Clean ABAP.