Preface – This post is part of the Object Oriented ABAP series.
Table of Contents
From the reference of an article: SAP ABAP Classes we have discussed the flavors of ABAP Classes & we came to know that ABAP classes are available in two flavors, one of which is Global Class.
The visibility section of the global class is always public, meaning all the ABAP programs in an R/3 system can access the global class. However, instantiation of that class could be set as either public, protected or private.
A class which is defined in the class builder (Transaction Code – SE24) is known as Global Class.
While creating a class from Class Builder (T-code: SE24), we get many options that indicate which type of global class we want to create, for example, usual ABAP class, exception class, persistent class or a test class. It also gives an option of whether we want to make it final or not.
After selecting the type of class and properties ( description & instantiation ), a screen will come where we can see the components of a global class like:
- Interfaces – Independent structures which are used in a class to extend the functionality of a class.
- Friends – If there is any class, which you want to make a friend of your class, you can define it here.
- Attributes – variables or constant declared within the class and can be accessed by all the methods of that class.
- Methods – Determines the behavior of an object, it provides some functionality. A method is allowed to access all the attributes of their class.
- Events – A mechanism through which one method can raise method of another class.
- Types – Table Types can be defined here, that can further be used anywhere in the whole class.
- Alias – A concept of providing an alternate method name for an interface method in an implemented class.
While defining an attribute and method, there are two mandatory fields, which we need to provide:
- Level: We have 2 level options:
- Instance – Components declared as instance can only be addressed by the instance(object) of that class only.
- Static – Components declared as static can be used independently of a class instance.
- Visibility: We have 3 Visibility options:
- Public – Components with this visibility will be available to all.
- Protected – Components will be visible to that class, where they are defined and to the inherited class.
- Private – Components will be visible to that class only, where they are defined.
Provides reusability of code functionality & fast implementation time.