PROTECTED SECTION
Syntax
PROTECTED SECTION.
Effect
This statement is only possible in the declaration section of a class and defines the protected
visibility section in the class
class. All the components of the class that are declared
in the section after the PROTECTED SECTION statement can be addressed in the subclasses of the class, as well as in the class itself.
Note
-
The smallest encapsulation unit in ABAP objects is the class. This is the reason why a method cannot
only use the protected components of the own class but also all instances of the same class. In subclasses,
it is not possible to access the protected components of the superior classes using reference variables
of the type of the superior class, because otherwise an attribute of an object of the dynamic type of
the superior class or another subclass could be changed. In the last case, a warning is triggered by the extended syntax check.
-
The declaration of attributes in the protected section does not prevent methods in subclasses or in the class itself from transferring
references to these attributes in the form of
reference variables or
field symbols, so that the attributes become visible and changeable outside the protected section.
Example
See Visibility Areas.