Prefer NEW #( ) over CREATE OBJECT
WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_NEW_OPERATORRemote Enabled
Overview
Prefer NEW operator over CREATE OBJECT and RAISE EXCEPTION.
ATC Finding Messages:
Prefer NEW #( ) expression over CREATE OBJECTPrefer RAISE EXCEPTION NEW cx_name( ) over RAISE EXCEPTION TYPE
Rationale
CREATE OBJECT is the procedural object-creation statement and requires a separate declaration and assignment. NEW #( ) infers the class from the target, can be used inside expressions, and keeps construction close to where the reference is needed. Use NEW for object creation in modern ABAP and reserve CREATE OBJECT for legacy downport code.
Non-Compliant
abap
DATA lo_customer TYPE REF TO cl_customer.
CREATE OBJECT lo_customer EXPORTING iv_name = lv_name.Compliant
abap
DATA lo_customer TYPE REF TO cl_customer.
lo_customer = NEW #( iv_name = lv_name ).Automated QuickFix
This rule provides an automated QuickFix directly in Eclipse ABAP Development Tools (ADT):
- Position the cursor on the flagged statement.
- Press Ctrl + 1 (Quick Assist).
- Select the automated refactoring to apply the clean syntax immediately.
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_CREATE_OBJECT | Boolean | true | Suggest NEW #( ... ) over CREATE OBJECT |
CHECK_RAISE_EXCEPTION | Boolean | true | Suggest RAISE EXCEPTION NEW over CREATE OBJECT followed by RAISE |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_NEW_OPERATOR
" SAP CI_ prefix format:
... "#EC CI_PREF_NEW_OPERATORRelated Rules
- Declare Constructor in PUBLIC SECTION —
#EC PREF_PUB_CTOR - Prefer CREATE_* Prefix for Factory Methods Returning Own Class —
#EC PREF_FACTORY_NAME - Design for Inheritance or Prohibit It (FINAL) —
#EC PREF_FINAL_CLASS
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_NEW_OP - Implementation File: zcl_skylint_pref_new_op.clas.abap