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 Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
MAX_COGNITIVE | Integer | 15 | Maximum 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_COGNITIVERelated Rules
- Limit Cyclomatic Complexity (McCabe Complexity Metric) —
#EC MAX_CYCLO_COMP - Limit Control Flow Nesting Depth (Guard Clause Enforcement) —
#EC MAX_NESTING - Limit Boolean Expression Complexity in Conditional Statements —
#EC MAX_BOOL_EXPR
Technical Details
- Native ATC Class:
ZCL_SKYLINT_MAX_COGNITIVE - Implementation File: zcl_skylint_max_cognitive.clas.abap