Limit Control Flow Nesting Depth (Guard Clause Enforcement)
WarningMetrics & Complexity Limits#EC MAX_NESTINGRemote Enabled
Overview
Nesting Depth Limit (excessive control block nesting).
ATC Finding Message:
Control block nesting depth exceeds
Rationale
Deeply nested control structures (IF, LOOP, CASE, DO, TRY) create the dreaded "Arrow Antipattern". Code drifts to the right edge of the editor, mental stack load increases exponentially, and error handling branches become difficult to trace.
Clean ABAP Guideline: Invert conditional checks and use Guard Clauses (RETURN, CONTINUE) at the top of methods and loops. Aim for a maximum nesting depth of 2 to 3 levels.
Non-Compliant
abap
" Anti-pattern: 4 levels deep nesting (Arrow Pattern)
METHOD process_item.
IF is_item-active = abap_true.
IF is_item-quantity > 0.
IF is_customer_eligible( is_item-customer_id ) = abap_true.
execute_booking( is_item ).
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.Compliant
abap
" Clean ABAP: Flat, linear flow using early return guard clauses
METHOD process_item.
IF is_item-active = abap_false.
RETURN.
ENDIF.
IF is_item-quantity <= 0.
RETURN.
ENDIF.
IF is_customer_eligible( is_item-customer_id ) = abap_false.
RETURN.
ENDIF.
execute_booking( is_item ).
ENDMETHOD.Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
MAX_DEPTH | Integer | 3 | Maximum allowable nesting depth of IF/CASE/LOOP/DO/WHILE/TRY control blocks |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC MAX_NESTING
" SAP CI_ prefix format:
... "#EC CI_MAX_NESTINGRelated Rules
- Limit Class Inheritance Depth (Favor Composition over Inheritance) —
#EC MAX_INHERIT - Limit Boolean Expression Complexity in Conditional Statements —
#EC MAX_BOOL_EXPR - Limit Cyclomatic Complexity (McCabe Complexity Metric) —
#EC MAX_CYCLO_COMP
Technical Details
- Native ATC Class:
ZCL_SKYLINT_MAX_NESTING - Implementation File: zcl_skylint_max_nesting.clas.abap