Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  Classes and Interfaces →  CLASS →  CLASS - DEFINITION 

PRIVATE SECTION

Other versions: 7.31 | 7.40 | 7.54

Syntax


PRIVATE SECTION. 

Effect

This statement can only be used in the declaration part of a class. It defines the private visibility section of the class class. All components of the class defined in the area after the statement PRIVATE SECTION can only be addressed in the class itself, and in its friends.


Notes

  • The class is the smallest encapsulation unit in ABAP Objects. This means that a method can use all private components of all instances of the same class, apart from the private components of its own class. An exception to this rule are subclasses that cannot access the private components of superclasses if they are not their friends.
  • The declaration of attributes in the private section does not stop methods of the references class from exposing these attributes in the form of reference variables or field symbol, which makes the attributes visible and modifiable outside the private section.
  • Private components declared in a class but not used statically there produce a warning in the extended program check.

Example

Declares a private constant const in a class cls1 and uses it as a start value of a public attribute of a friend cls2.

CLASS cls2 DEFINITION DEFERRED. 

CLASS cls1 DEFINITION FRIENDS cls2. 
  PRIVATE SECTION. 
    CONSTANTS const TYPE string VALUE `I'm private`. 
ENDCLASS. 

CLASS cls2 DEFINITION. 
  PUBLIC SECTION. 
    CLASS-DATA attr TYPE string VALUE cls1=>const. 
ENDCLASS. 

START-OF-SELECTION. 
  cl_demo_output=>display( cls2=>attr ).