Skip to content

Merge Nested IF Statements ​

WarningClean ABAP & Modern SyntaxQuickFix Ready#EC MERGE_IFSRemote Enabled

Overview ​

Merge consecutive nested IF blocks using boolean AND.

ATC Finding Messages:

  • Nested IF block can be merged with outer IF using AND
  • Nested IF in ELSE block can be changed to ELSEIF

Rationale ​

Nested IF statements without intermediate statements add indentation without adding meaning. Merging them with AND or converting a nested IF in an ELSE block into ELSEIF flattens the control flow and makes the combined condition explicit. Less nesting reduces cyclomatic complexity and makes the happy path easier to test.

Non-Compliant ​

abap
IF is_active( ).
  IF is_authorized( ).
    process_order( ).
  ENDIF.
ENDIF.

Compliant ​

abap
IF is_active( ) AND is_authorized( ).
  process_order( ).
ENDIF.

Automated QuickFix ​

This rule provides an automated QuickFix directly in Eclipse ABAP Development Tools (ADT):

  1. Position the cursor on the flagged statement.
  2. Press Ctrl + 1 (Quick Assist).
  3. Select the automated refactoring to apply the clean syntax immediately.

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.