code pal for ABAP > Documentation > Prefer New to Create Object
This check searches for CREATE OBJECT
statements and reports a finding if the type of the instance being created is known statically. Static instance creation with the functional NEW
constructor allows for inline declarations and more concise code.
Use NEW
to create instances of objects when the type is known statically.
In exceptional cases, you can suppress this finding by using the pseudo comment "#EC PREF_NEW
:
DATA prefer_new_to_crt_obj TYPE REF TO y_check_prefer_new_to_crt_obj.
CREATE OBJECT prefer_new_to_crt_obj. "#EC PREF_NEW
Before the check:
DATA prefer_new_to_create_object TYPE REF TO y_check_prefer_new_to_crt_obj.
CREATE OBJECT prefer_new_to_create_object.
After the check:
DATA(prefer_new_to_create_object) = NEW y_check_prefer_new_to_crt_obj( ).
DATA prefer_new_to_create_object TYPE REF TO y_check_prefer_new_to_crt_obj.
prefer_new_to_create_object = NEW #( ).