Skip to content

Parenthesize Combinations of AND and OR ​

WarningClean ABAP & Modern Syntax#EC PREF_PAREN_AND_ORRemote Enabled

Overview ​

Parenthesize Combinations of AND and OR.

ATC Finding Message: Parenthesize combinations of AND and OR to eliminate ambiguity

Rationale ​

Different programming languages and databases have varying operator precedences for logical operators. Unparenthesized conditions mixing AND and OR (such as a AND b OR c) are ambiguous to human readers and easily hide critical branching bugs. Explicitly parenthesize combinations as ( a AND b ) OR c to make evaluation precedence unmistakable.

Non-Compliant ​

abap
IF cond_a AND cond_b OR cond_c.
  step( ).
ENDIF.

Compliant ​

abap
IF ( cond_a AND cond_b ) OR cond_c.
  step( ).
ENDIF.

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC PREF_PAREN_AND_OR

" SAP CI_ prefix format:
... "#EC CI_PREF_PAREN_AND_OR

Technical Details ​

Released under the MIT License.