Skip to content

Limit Cognitive Complexity per Method ​

WarningMetrics & Complexity Limits#EC MAX_COGNITIVERemote Enabled

Overview ​

Limit cognitive complexity per procedure.

ATC Finding Message: Procedure cognitive complexity exceeds threshold

Rationale ​

Cognitive complexity measures how hard a procedure is to understand: every branch adds one point plus the current nesting depth, so deeply nested IFs and loops escalate quickly even when the raw branch count looks acceptable. Unlike cyclomatic complexity it rewards flat guard clauses and early exits. Keep procedures below the configured threshold and extract nested logic into well-named helper methods.

Non-Compliant ​

abap
LOOP AT lt_items INTO ls_item.
  IF ls_item-active = abap_true.
    IF ls_item-amount > 0.
      IF ls_item-currency = lv_currency.
        process( ls_item ).
      ENDIF.
    ENDIF.
  ENDIF.
ENDLOOP.

Compliant ​

abap
LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<ls_item>).
  IF is_relevant( <ls_item> ) = abap_false.
    CONTINUE.
  ENDIF.
  process( <ls_item> ).
ENDLOOP.

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_COGNITIVEInteger15Maximum allowed cognitive complexity score per procedure (default: 15)

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.