Get Example source ABAP code based on a different SAP table
ID PROTECTED • PROTECTED SECTION ABAP Statement
PROTECTED SECTION> Short Reference >
ABAP_SYNTAX PROTECTED SECTION.>
What does it do? This statement can only be used in the declaration part> of a class and defines the protected visibility section> of the class class>. All components of the class that are declared in the area behind the statement PROTECTED SECTION> can be addressed directly only in the subclasses of the class and in the class itself, as well as its friends>, if allowed by the package concept>. In particular, protected methods in subclasses can be redefined.
Latest notes:
The class is the smallest encapsulation unit in ABAP Objects. Therefore a method can use all protected components of all instances of its class besides the protected components of its own class.
In subclasses, it is not possible to access the protected components of superclasses using reference variables of the type of the superclass, because otherwise an attribute of an object of the dynamic type of the superclass or another subclass could be changed. However, the latter only produces a warning from the extended syntax check.
A subclass cannot access the protected components of a subclass of a different branch of the inheritance hierarchy inherited from a shared superclass.
The declaration of attributes in the protected section does not prevent methods in subclasses or in the class itself from passing references> to these attributes in the form of reference variables> or field symbols>, so that the attributes become visible and modifiable outside the protected section. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Declaration of a protected constant const> in a superclass cls1> and its use as a start value of a public attribute of a subclass cls2>. ABEXA 00501 ABAP_EXAMPLE_END