SAP CONSTRUCTOR EXPRESSION NEW



Get Example source ABAP code based on a different SAP table
  


• NEW ABAP_CONSTRUCTOR
• # NEW

NEW, Instance Operator

ABAP_SYNTAX
... NEW type( ... ) ...

What does it do?
A constructor expression with the instance operator NEW creates an anonymous data object or an instance of a class and assigns values to the new object. The result is a reference variable that points to the created object. The following can be specified for type:
A non-generic data type dtype. The operator NEW creates an anonymous data object of data type dtype. The result of NEW is a data reference variable of static type dref that points to the anonymous data object. The operator NEW works in the same way as the statement CREATE DATA dref TYPE dtype where dref corresponds to the result of the expression. A constructor expression of this type cannot be extended using a component selector.
A class class. The operator NEW creates an object of the class class. The result of NEW is a object reference variable of static type class that points to the object. The operator NEW works in the same way as the statement CREATE OBJECT oref TYPE class where oref corresponds to the result of the expression.
In general expression positions , functional positions and result positions an object component selector -> can be placed behind NEW( ... ) and point to an attribute of the class:
... NEW class( ... )->attr$|('attr_name') ... The attribute can be specified statically as attr or dynamically as content of a character-like data object attr_name in parentheses. A single expression that points to an attribute of the class using exactly one subsequent object component selector can also be used as the target field of assignments.
Standalone and functional method calls, including chained method calls , can be introduced:
... NEW class( ... )->meth( ... ) ...
The method must be specified statically.
The # character.