Routine Declaration Hygiene (Top Placement & Order)
WarningClean ABAP & Modern Syntax#EC DEF_TOPRemote Enabled
Overview
Routine Declaration Hygiene (top placement & order).
ATC Finding Messages:
Reorder definitions to beginning of routine; avoid scattered declarationsDeclare local TYPES before CONSTANTS before DATA before FIELD-SYMBOLS
Rationale
Declarations placed in the middle of executable code interrupt reading flow and conceal variable scope. Moreover, arbitrary ordering can place a DATA declaration before the TYPE it references. Maintain clean routine hygiene by placing all local declarations at the beginning of the routine in strict hierarchical order: TYPES before CONSTANTS before DATA before FIELD-SYMBOLS.
Non-Compliant
abap
METHOD process_order.
lv_total = 100.
DATA lv_tax TYPE i.
FIELD-SYMBOLS <fs> TYPE i.
TYPES ty_status TYPE c LENGTH 1.
ENDMETHOD.Compliant
abap
METHOD process_order.
TYPES ty_status TYPE c LENGTH 1.
CONSTANTS lc_rate TYPE i VALUE 18.
DATA lv_tax TYPE i.
FIELD-SYMBOLS <fs> TYPE i.
lv_total = 100.
ENDMETHOD.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 |
|---|---|---|---|
CHECK_DEF_TOP | Boolean | true | Enforce all local declarations (DATA, TYPES, CONSTANTS) at top of method body |
CHECK_DECL_ORDER | Boolean | true | Enforce declaration order: TYPES first, then CONSTANTS, then DATA |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC DEF_TOP
" SAP CI_ prefix format:
... "#EC CI_DEF_TOPRelated Rules
- Prefer Modern Inline Declarations in ABAP 7.40+ —
#EC PREF_INLINE - Prefer FINAL( ) over DATA( ) when the variable is never written again —
#EC PREF_FINAL_DATA - Avoid Hungarian Notation and Type Prefixes —
#EC NO_HUNGARIAN
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_DECLARATIONS - Implementation File: zcl_skylint_pref_declarations.clas.abap