In ABAP Objects, you can define classes and interfaces either globally or locally. You define global classes and interfaces with the Class Builder tool (transaction SE24) in the ABAP Workbench; they are then stored centrally in the Class Library in the R/3 Repository. All ABAP programs in the R/3 System can access these global classes and interfaces. Conversely, you can only use local classes and interfaces in the program that defines them. When an ABAP program uses a class, the system searches first for a local class, then for a global class of the same name. Otherwise, there is no difference in the use of local and global classes or interfaces.
Since local classes are only used by one program, it is generally sufficient to define the public interface - that is, the outwardly visible components appropriate for this program. Conversely, each global class is available throughout the system, which means that its public interface can only be typed with reference to data types that are themselves visible throughout the system.
The following sections describe the definition of local classes and interfaces in an ABAP program. For information on defining global classes and interfaces see also:Class Builder .
Local classes consist of ABAP source text enclosed between the CLASS - ENDCLASS statements. A complete class definition consists of a declaration part and, if necessary, an implementation part.
The declaration part of a class class consists of one statement block:
This declaration part contains the declaration of the Komponenten (attributes, methods, and events) of a class. All the components of a class must be assigned explicitly to a Sichtbarkeitsbereich (PUBLIC SECTION , PROTECTED SECTION, PRIVATE SECTION), which defines from where each component can be accessed. In global classes, the declaration part belongs to the global data declarations and should be at the start of the program.
If methods are declared in the declaration part of a class, the class needs an implementation part, which consists of one statement block:
The implementation part of a class contains the implementation of all the methods of this class. Methods are procedures - that is, processing blocks of an ABAP program. The position of the implementation part in the source texts is thus unimportant. For clarity, however, you should either put all the implementation parts of local classes at the end (like subroutines) or directly after the relevant definition part. If you do the latter, note that you must then assign subsequent non-declarative statements explicitly to a processing block, such as START-OF-SELECTION, so that they can be accessed.
You define the local interface intf using the
The definition contains all the components (attributes, methods, events) of the interface. In interfaces, you can define the same components as in classes. You cannot assign the components of a interface explicitly to a visibility area, because interface components always extend the public area of the class. There is no implementation part for interfaces, since the methods of an interface must be implemented in the same class that implements the interface.