Global Class in SAP ABAP

by | Mar 27, 2019 | OOABAP

Home » SAP » ABAP » OOABAP » Global Class in SAP ABAP

Preface – This post is part of the Object Oriented ABAP series.

Introduction

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.

Definition

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:

  1. Interfaces – Independent structures which are used in a class to extend the functionality of a class.
  2. Friends – If there is any class, which you want to make a friend of your class, you can define it here.
  3. Attributes – variables or constant declared within the class and can be accessed by all the methods of that class.
  4. Methods – Determines the behavior of an object, it provides some functionality. A method is allowed to access all the attributes of their class.
  5. Events – A mechanism through which one method can raise method of another class.
  6. Types – Table Types can be defined here, that can further be used anywhere in the whole class.
  7. 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:

  1. 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.
  1. 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.

 

Advantages:

Provides reusability of code functionality & fast implementation time.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author