Ansicht
Dokumentation

ABENNEW_CONSTRUCTOR_PARAMS_CLASS - NEW CONSTRUCTOR PARAMS CLASS

ABENNEW_CONSTRUCTOR_PARAMS_CLASS - NEW CONSTRUCTOR PARAMS CLASS

TXBHW - Original Tax Base Amount in Local Currency   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

NEW, Classes

... NEW class$|#( $[let_exp$] p1 = a1 p2 = a2 ... ) ...

Effect

If a class class is specified or # stands for a class like this, the non-optional input parameters p1 p2 ... of the instance constructor of the instantiated class must be filled with the type-compliant actual parameters a1 a2 ... The optional input parameters do not need to but can be filled. The description of the statement CREATE OBJECT specifies how parameters are passed and which classes can be used. No parameters are passed for a class without an explicit instance constructor. An optional LET expression let_exp can be specified in front of the parameter to define local helper fields.

Like an object reference variable of the type class, a constructor expression NEW class( ... ) can be specified in front of the object component selector -> and in chained attribute accesses and chained method calls. A chained method call of this type can be specified as a standalone statement. The result is then preserved for the duration of the statement. Even a single expression without a subsequent object component selector can be executed as a standalone statement. In this case, only the constructor that has a reference to the created object elsewhere is executed if this object needs to be preserved.

In the special case of an attribute access NEW class( ... )->attr, the following applies:

Method chainings cannot be specified between the constructor expression and the attribute here.

Notes

  • When the instance constructor is called, the return code sy-subrc is set to 0. Values other than 0 are not possible, since non-class-based exceptions cannot be handled.

Example

Construction of an instance of the class c1 when the method m2 of the class c2 is called, which requires an input parameter of this type.

Example

Use of a constructor expression with NEW in various positions. The temporary reference variable created using NEW is persisted during each statement.

Example

Display of a time stamp created in a constructor that only exists while the statement is being executed.

Example

Constructor expression with NEW on the left side of an expression. Although the reference variable only exists during the statement, the reference to the object is assigned to the reference variable oref in the constructor of the class class, thus preserving the object.






Addresses (Business Address Services)   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.

Length: 4606 Date: 20240416 Time: 102151     sap01-206 ( 83 ms )