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_ORRelated Rules
- Limit Boolean Expression Complexity in Conditional Statements —
#EC MAX_BOOL_EXPR - Avoid Duplicate Branch Conditions —
#EC NO_DUP_COND - Avoid Comparing to abap_true / abap_false —
#EC NO_BOOL_COMPARE
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_PAREN_AND_OR - Implementation File: zcl_skylint_pref_paren_and_or.clas.abap