Skip to content

Avoid Static State (CLASS-DATA and STATICS) ​

WarningAnti-Patterns & Bad Practices#EC NO_STATIC_STATERemote Enabled

Overview ​

Avoid CLASS-DATA and STATICS state.

ATC Finding Message: Static state hides dependencies and survives between calls; inject state instead

Rationale ​

Static state survives between calls and is shared by every caller in the internal session, which makes behavior order-dependent and lets unit tests interfere with each other. CLASS-DATA and STATICS also hide dependencies: a method looks self-contained while it silently reads or mutates global memory. Keep state in instances that are injected, or pass it explicitly, so lifecycles stay visible and tests stay isolated.

Non-Compliant ​

abap
CLASS-DATA gv_counter TYPE i.

METHOD increment.
  STATICS sv_calls TYPE i.
  sv_calls = sv_calls + 1.
ENDMETHOD.

Compliant ​

abap
METHOD increment
  IMPORTING io_counter TYPE REF TO zcl_counter.
  io_counter->increment( ).
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
CHECK_CLASS_DATABooleantrueDetect CLASS-DATA attributes declared in class definitions
CHECK_STATICSBooleantrueDetect STATICS variables declared inside methods, forms, and function modules

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.