Skip to content

Limit Local Variable Count per Method ​

WarningMetrics & Complexity Limits#EC MAX_LOCALSRemote Enabled

Overview ​

Limit local variable count per procedure.

ATC Finding Message: Procedure declares too many local symbols

Rationale ​

A method with many local variables usually does several unrelated things at once and is hard to unit test. The count includes DATA, FIELD-SYMBOLS, STATICS and CONSTANTS declarations as well as inline DATA(...) and FIELD-SYMBOL(...) definitions, because each declared symbol is another piece of state a reader must track. Extract cohesive blocks into helper methods or introduce a dedicated result structure.

Non-Compliant ​

abap
METHOD process.
  DATA lv_a TYPE i.
  DATA lv_b TYPE i.
  DATA lv_c TYPE i.
  DATA lv_d TYPE i.
  DATA lv_e TYPE i.
ENDMETHOD.

Compliant ​

abap
METHOD process.
  DATA ls_totals TYPE ty_totals.
  ls_totals = calculate_totals( ).
  persist_totals( ls_totals ).
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_LOCALSInteger15Maximum allowed number of local declarations per procedure (default: 15)

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.