Skip to content

ABAP Keyword Documentation →  ABAP Programming Guidelines →  Architecture →  Object-Oriented Programming 

Local Types for Global Classes

Other versions: 7.31 | 7.40 | 7.54

Background

Within class pools, as in virtually any other ABAP program, data types, local interfaces, and local classes can be defined to ensure a better structure of the implementation of the global class. From a technical point of view, these optional declaration parts, together with the declaration part of the global class, form the global declaration part of the class pool.

These local declarations of a class pool are invisible outside the class pool and can therefore only be used in the private visibility section (PRIVATE SECTION) of the declarations of the global class or within their method implementations. These two usage types have different technical visibility requirements because friends of a global class have access to its private visibility section. Local type declarations that are used in the PRIVATE SECTION must therefore be accessible for any possible friends of the class, whereas those type declarations that are only used within the method implementations are completely meaningless for other classes.

In general, local classes consist of the declaration part and the associated method implementations. These are invisible to the friends of the global class and have thus technically the same visibility requirements as local type declarations that are only used within the implementation.

Local data types, interfaces, and classes are created within a class pool using the "Class-Local Types" function in Class Builder, which stores these declaration and implementation parts in the include programs provided for this purpose. There is a distinction between the two areas, Local Class Definitions/Types and Local Class Implementations, to meet the different technical visibility requirements mentioned above.

Rule

Position local declarations appropriately

Position the local declarations of a class pool at appropriate positions depending on the requirements. Types that are only used within the implementation of the global class need to be in a different position than types that are also addressed in the PRIVATE SECTION of the global class.

Details

From the perspective of a class pool, all local type definitions and the associated implementations of the local classes can be saved in the "Local Class Definitions/Types" area. However, such an approach is disadvantageous from the dependency management perspective. Dependent classes (subclasses and friends of the global class) only have to be invalidated for changes to the local type declarations of a class pool that are used in the PRIVATE SECTION of the global class. But technically speaking, this invalidation occurs for all changes in the Local Class Definitions/Types area. For this reason, the additional area "Local Class Implementations" which is intended for local type declarations that are only used within the class implementation of the global class, and for the implementation part of local classes. If this area is changed, dependent classes are not invalidated.

To prevent unnecessary new generations of other classes that are based on unwanted technical dependencies, the class-local types must be defined in Class Builder at the appropriate positions after changes have been made to the global class:

  • Choose Goto > Class-Local Types > Local Class Implementations to declare types like this that are only used within the method implementations of the global class. The local classes should be implemented here as well.
  • Choose Goto > Class-Local Types > Local Class Definitions/Types to display the types that can also be referenced in the PRIVATE SECTION. Declaration and implementation of a local class are only supposed to be distributed across the areas Local Class Definitions/Types and Local Class Implementations if they are to be referred to in the PRIVATE SECTION. However, if the local class is only used within the implementation of the global class, both the declaration and the implementation are to be carried out in the Local Class Implementations area.


Note

The rule specified here specializes the general rule implement global declarations centrally with regard to class pools. They are especially oriented toward the external call of methods of their respective global class and are therefore particularly integrated within a dependency network. For this reason, the rule just mentioned cannot apply to its full extent.