We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!
METHODS constructor $[FINAL$]
$[IMPORTING parameters $[PREFERRED PARAMETER p$]$]
$[${RAISING exc1$|RESUMABLE(exc1) exc2$|RESUMABLE(exc2) ...$}
$|${EXCEPTIONS exc1 exc2 ...$}$].
1. ... IMPORTING parameters
2. ... RAISING exc1$|RESUMABLE(exc1) exc2$|RESUMABLE(exc2) ...
3. ... EXCEPTIONS exc1 exc2 ...
4. ... FINAL
This statement declares the instance constructor constructor of a class. In a local class, it can be specified in all visibility sections that are more general than or equal to the instantiability specified in the CREATE addition of the statement CLASS DEFINITION:
CREATE PUBLIC | CREATE PROTECTED | CREATE PRIVATE | |
PUBLIC SECTION | X | X | X |
PROTECTED SECTION | - | X | X |
PRIVATE SECTION | - | - | X |
In a global class, the instance constructor must always be declared in the public visibility section, for technical reasons. In principle, the declaration can be made in the same visibility sections as in the table above, however the internal organization of a global class can cause incorrect syntax errors when the class is used.
Each class has a predefined method called constructor. By declaring this explicitly, the interface of the method constructor can be defined as class-specific, and its functions can be implemented. Without explicit declaration, the instance constructor assumes the parameter interface of the direct superclass and calls it implicitly.
If the instance constructor is implemented in a subclass, the instance constructor of the superclass must be called explicitly using super->constructor, even if the latter is not explicitly declared. The exception to this are direct subclasses of the root node object. The following restrictions apply before the superclass constructor is called:
After the superclass constructor has been called, the self-reference me-> can be used and instance components can be accessed.
For each instance of a class, the instance constructor is called only once using the statement CREATE OBJECT immediately after it has been created. Here, appropriate actual parameters must be assigned to all non-optional input parameters, return values can be assigned to non-class-based exceptions, and class-based exceptions can be declared. It is not possible to call the instance constructor explicitly, unless the superclass constructor is called using super->constructor in the redefined constructor of a subclass.
When an instance constructor is executed, the current instance is temporarily the type of the class in which the constructor is defined. This has the following effects:
Declare the instance constructor in the public visibility section.
Instance constructors are an exception to the rule that all non-private components on a path in the inheritance hierarchy are in the same namespace. The instance constructor of each class has its own interface and its own implementation. An instance constructor cannot be redefined.
... IMPORTING parameters
... RAISING exc1$|RESUMABLE(exc1) exc2$|RESUMABLE(exc2) ...
... EXCEPTIONS exc1 exc2 ...
The addition IMPORTING can be used to define input parameters according to the same rules as
for general methods. The additions RAISING and EXCEPTIONS for the declaration of class-based
exceptions or the definition of non-class-based exceptions also have the same meaning as for general methods.
When the instance constructor is executed, the same applies to
resumable
exceptions as to all other methods. If processing can be resumed successfully, the system continues to create the object.
... FINAL
Instance constructors are implicitly final. The addition FINAL can be specified, but it is not necessary.
The class c3 inherits from class c2, which inherits from class c1. The instance
constructor constructor is explicitly declared in all classes and must be implemented in all
classes, whereby the implementation in a subclass must contain the call of the superclass constructor.
The predicate expression IS INSTANCE
OF shows that every instance constructor for an instance of its own class is executed when an object of class c3 is instantiated.
Leave us your contact details and we will call you back. Fields marked with * are mandatory.
We offer holistic SAP solutions from a single source to shape digital change and develop new business areas.
Switzerland
Schaffhausen
Germany
Mannheim, Düsseldorf, Munich
USA
Haverhill
Greece
Thessaloniki