SAP INHERITANCE STATICAL SAP Info
ARTICLE ( Version: 0003)
Inheritance and Static Attributes
Like all components, static attributes exist only once per inheritance
tree. A subclass can access the content of the public and protected static attributes of all superclasses. Vice versa, a superclass shares its public and protected static attributes with all subclasses. Thus static attributes are not assigned to one single class but to a section of the inheritance tree. Changes can be made from outside using the class component selector with all class names involved or from inside in all associated classes and are visible in all classes involved.
When a static attribute is addressed that belongs to a section of an inheritance tree, the class where the attribute is declared is always addressed irrespective of the class name used in the class component selector. This is important for calling the
ARTICLE ( Version: 0011)
Inheritance and Static Attributes
Like all components,
> exist only once per inheritance tree. A subclass can access the content of the public and protected static attributes of all superclasses. Vice versa, a superclass shares its public and protected static attributes with all subclasses. Thus static attributes are not assigned to one single class but to a path of the inheritance tree. Accesses from outside are possible using the class component selector with all class names involved or from inside in all associated classes. Changes of the values are visible in all classes involved.
When a static attribute is addressed that belongs to a path of an
inheritance tree, the class where the attribute is declared is always addressed irrespective of the class name used in the class component selector. This is important for calling the
ARTICLE ( Version: 0033)
Inheritance and Static Components
components, exist only once in each inheritance tree, and can be used as of the declaring class:
A subclass can access all non-private static components of its superclasses. The class in which the static component is declared is always the class that is addressed.
From outside, the class component selector can be used to access all visible static components. Each class can be specified in which the component exists (that is, the declaring class and each subclass). Regardless of the class name used in the class component selector, however, the class in which the component is declared is addressed.
The class in which the component is declared is addressed, whether the
static component is used internally or externally. This is important for:
Calling the
Static constructors are called the first time you address a class. If you address a static component declared in a superclass using the class name of a subclass, only the static constructor of the superclass is called.
Access to the
A subclass has access to the content of all non-private static attributes of all superclasses. Conversely, a superclass shares its p ublic and protected static attributes with all of its subclasses. When inherited, therefore, static attributes are not assigned to a single class; instead they are assigned to the subtree of the inheritance tree that consists of all subclasses of the defining class. Changes to the values are visible in all involved classes, regardless of the class used to address an attribute.
The registration of
If an event handler is declared for a static event of a subclass inherited from a superclass, it can react to this event only if it is triggered by a method of the subclass or one of its subclasses. If the event is triggered in a static method of a superclass, it is not handled, even if the method is called in a subclass or if the name of the subclass is specified.
Example
Calls a static method of a superclass using the name of a subclass.
Before the method is executed, the static constructor of the superclass is executed, but not the static constructor of the subclass. The method returns the value set in the superclass.
PUBLIC SECTION.
CLASS-DATA a1 TYPE string.
CLASS-METHODS: class_constructor,
m1 RETURNING value(r1) LIKE a1.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD class_constructor.
a1 = 'c1'.
ENDMETHOD.
METHOD m1.
r1 = a1.
ENDMETHOD.
ENDCLASS.
CLASS c2 DEFINITION INHERITING FROM c1.
PUBLIC SECTION.
CLASS-METHODS class_constructor.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD class_constructor.
a1 = 'c2'.
ENDMETHOD.
ENDCLASS.
DATA v1 TYPE string.
START-OF-SELECTION.
v1 = c2=>m1( ).>
Example
This example shows how a subclass is used to change a static attribute
of a superclass, and how the change is visible in a subclass of a different path in the inheritance tree.
PUBLIC SECTION.
CLASS-DATA a1 TYPE string.
ENDCLASS.
CLASS c11 DEFINITION INHERITING FROM c1.
...
ENDCLASS.
CLASS c12 DEFINITION INHERITING FROM c1.
...
ENDCLASS.
c11=>a1 = 'Hello Sister'.
MESSAGE c12=>a1 TYPE 'I'.>
Example
For an example of static events, see
Inheritance Events>.
ARTICLE ( Version: 0034)
Inheritance and Static Components
components, exist only once in each inheritance tree, and can be used as of the declaring class:
A subclass can access all non-private static components of its superclasses. The class in which the static component is declared is always the class that is addressed.
From outside, the class component selector can be used to access all visible static components. Each class can be specified in which the component exists (that is, the declaring class and each subclass). Regardless of the class name used in the class component selector, however, the class in which the component is declared is addressed.
The class in which the component is declared is addressed, whether the
static component is used internally or externally. This is important for:
Calling the
Static constructors are called the first time you address a class. If you address a static component declared in a superclass using the class name of a subclass, only the static constructor of the superclass is called.
Access to the
A subclass has access to the content of all non-private static attributes of all superclasses. Conversely, a superclass shares its p ublic and protected static attributes with all of its subclasses. When inherited, therefore, static attributes are not assigned to a single class; instead they are assigned to the subtree of the inheritance tree that consists of all subclasses of the defining class. Changes to the values are visible in all involved classes, regardless of the class used to address an attribute.
The registration of
If an event handler is declared for a static event of a subclass inherited from a superclass, it can react to this event only if it is triggered by a method of the subclass or one of its subclasses. If the event is triggered in a static method of a superclass, it is not handled, even if the method is called in a subclass or if the name of the subclass is specified.
Example
Calls a static method of a superclass using the name of a subclass.
Before the method is executed, the static constructor of the superclass is executed, but not the static constructor of the subclass. The method returns the value set in the superclass. CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-DATA a1 TYPE string.
CLASS-METHODS: class_constructor,
m1 RETURNING value(r1) LIKE a1.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD class_constructor.
a1 = 'c1'.
ENDMETHOD.
METHOD m1.
r1 = a1.
ENDMETHOD.
ENDCLASS.
CLASS c2 DEFINITION INHERITING FROM c1.
PUBLIC SECTION.
CLASS-METHODS class_constructor.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD class_constructor.
a1 = 'c2'.
ENDMETHOD.
ENDCLASS.
DATA v1 TYPE string.
START-OF-SELECTION.
v1 = c2=>m1( ).
Example
This example shows how a subclass is used to change a static attribute
of a superclass, and how the change is visible in a subclass of a different path in the inheritance tree. CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-DATA a1 TYPE string.
ENDCLASS.
CLASS c11 DEFINITION INHERITING FROM c1.
...
ENDCLASS.
CLASS c12 DEFINITION INHERITING FROM c1.
...
ENDCLASS.
c11=>a1 = 'Hello Sister'.
MESSAGE c12=>a1 TYPE 'I'.
Example
For an example of static events, see
Inheritance Events>.
Message text extract from SAP system. Copyright SAP SE.
Search for further information about these or an SAP related objects