Limit Method and Constructor Statement Length
Overview
Method and Constructor Length Limits.
ATC Finding Messages:
Method length exceeds maximum allowed statement limitAvoid heavy business logic/loops in constructor; use injection only
Rationale
Methods that contain hundreds of statements violate the Single Responsibility Principle (SRP). They are difficult to comprehend, impossible to unit test thoroughly, and conceal copy-pasted business logic branches. Constructors are especially sensitive: heavy business logic or loops in constructors make dependency injection and mock testing impossible.
Clean ABAP Guideline: A clean method should do one thing, do it well, and do it only. Keep regular methods under 20-30 statements and keep constructors minimal (dependency assignment only).
Non-Compliant
" Anti-pattern: Overly long method combining validation, calculation, DB updates, and logging
METHOD process_sales_order.
" 150+ lines of mixed concerns...
" Validation logic
" Database reads
" Currency conversion
" Pricing calculations
" Direct database updates
" Email dispatch
ENDMETHOD.Compliant
" Clean ABAP: Short, focused methods delegating to dedicated domain services
METHOD process_sales_order.
validate_order_data( is_order ).
DATA(ls_pricing) = mo_pricing_service->calculate( is_order ).
mo_order_repository->save( is_order = is_order is_pricing = ls_pricing ).
mo_notifier->send_confirmation( is_order-order_id ).
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 |
|---|---|---|---|
MAX_STATEMENTS | Integer | 5 | Maximum executable ABAP statements allowed in regular method bodies |
MAX_CTOR_STATEMENTS | Integer | 10 | Maximum statements allowed in CONSTRUCTOR methods (guards against heavy setup logic) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
" Standard pseudo-comment:
... "#EC MAX_METHOD_LEN
" SAP CI_ prefix format:
... "#EC CI_MAX_METHOD_LENRelated Rules
- Limit Source Code Line Length (Avoid Horizontal Scrolling) —
#EC MAX_LINE_LEN - Limit Method Parameter Count and Require Multi-Line Signatures —
#EC MAX_PARAMS_COUNT - Limit Multiple Return Statements per Method Body —
#EC MAX_RETURNS
Technical Details
- Native ATC Class:
ZCL_SKYLINT_MAX_METHOD_LEN - Implementation File: zcl_skylint_max_method_len.clas.abap