GUIDELINE 5.6
Local Types for Global Classes
ABAP_BACKGROUND
Within class pools, like in virtually any other ABAP program, you can
define data types, local interfaces, and local classes 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.
You create local data types, interfaces, and classes within a class pool
using the Class-Local Types function of the Class Builder, which stores
such 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.
ABAP_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.
ABAP_DETAILS
From the perspective of a class pool, you can store all local type
definitions and the associated implementations of the local classes in
the Local Class Definitions/Types area. However, such an approach is
disadvantageous from the dependency management perspective. Only for
changes to the local type declarations of a class pool that are used in
the PRIVATE SECTION of the global class do you have to invalidate
dependent classes (subclasses and friends of the global class) and
regenerate them. But technically speaking, this invalidation occurs for
all changes in the Local Class Definitions/Types area. For this reason,
you are provided with the additional area, Local Class Implementations,
which is intended for local type declarations, which 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, which are based
on unwanted technical dependencies, after changes have been made to the
global class you must therefore define the class-local types in the
Class Builder at the appropriate positions:
Choose Goto _ Class-Local Types _ Local Class Implementations to
declare such types that are only used within the method implementations
of the global class. The local classes should be implemented here as
well.
If you choose Goto _ Class-Local Types _ Local Class
Definitions/Types , the system takes you to the types, which you can
also refer to 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.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved