Skip to content

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 NameData TypeDefault ValueDescription & Guidance
MAX_DEPTHInteger3Maximum 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_NESTING

Technical Details ​

Released under the MIT License.