Key OOP Concepts Explained: ABAP Terminologies

OBJECT ORIENTED PROGRAMMING TERMINOLOGIES in ABAP

Below are some of the important concepts of OOP:-

Global Class
Global Class is an ABAP object which can be accessible via SAP Class Builder, T-code for SAP Class Builder is SE24.

Local Class
Local classes are classes which are available in ABAP programs, we can access them via ABAP editor SE38.

What is a Class ? A class is a user defined data type with attributes, methods, events, user-defined types, interfaces etc. for a particular entity or business application

What are Objects ? Objects are nothing but instances of classes, each object has a unique identity that is memory and it`s own attributes.

Static attributes define a common state of a class that is shared by all the instances of the class. That is, if you change a static attribute in one object of a class, the change is visible to all other objects of the class as well. A static attribute is declared by using the CLASS-DATA statement.

Events: Event is a mechanism through which one method of a class can raise method of other class, without hazard of instantiating that class.

In ABAP Objects, the whole class definition is separated into three visibility sections:

  • PUBLIC .
  • PROTECTED .
  • PRIVATE.

Public section: Data declared in public section can be accessed by the class itself, by its subclasses as well as by other users outside the class.

Protected section: Data declared in the protected section can be accessed by the class itself, and also by its subclasses but not by external users outside the class.

Private Section: Data declared in the private section can be accessed by the class only, but not by its subclasses and by external users outside the class.

Instance components : These components exist separately in each instance (object) of the class and are referred using instance component selector using ->

Static components : These components exists globally for a class and are referred to using static component selector => .

Events: Contains events declared and implemented in that class.

Types: The types tab contains user defined type deceleration.

Aliases: Contains alias names for interface methods ( will discuss in later lessons).

The methods can be called using key word CALL METHOD in SAP ABAP programs.

EDIT:

In new ABAP syntax you can directly call methods using objects and CALL METHOD keyword explicitly is not required anymore.

.In SAP classes we don`t have options to directly specify tables, for this one we need to create table type in SE11(Data Dictionary).

A table type describes the structure and functional attributes of an internal table in ABAP.

In ABAP programs you can reference a table type TTYP defined in the ABAP Dictionary with the command DATA is created in the program with the attributes defined for TTYP in the ABAP Dictionary.

CLASS CONSTRUCTOR (Also called as STATIC CONSTRUCTOR).

It is a type of constructor, this method will be executed automatically whenever a first call to the class is made, the first call may be through instance or through class.

These CLASS CONSTRUCTORS are mainly used to set the default values globally i:e irrespective of instances, these methods will not have any importing and exporting parameters. These methods will be executed only once.

Name of the CLASS CONSTRUCTOR must be CLASS_CONSTRUCTOR.

What is Inheritance in SAP OOABAP ?
Inheritance is the concept of passing the behavior of one class to another class.

This means we can add additional features to an existing class without modifying it.

SUPER is the keyword used to represent the super class in oops, you can access the methods and attributes the super class using this word super.

REDIFINATION is the keyword which is used to overwrite the parent class methods with new definition.

Association –   Relating two classes or relation between two classes is called as Association.

Aggregation – One class using the instances on other class is know as Aggregation.

Composition – when one class data is related or will affect  other class data is known as composition. Eg: when one class data is deleted the data pertaining to that in another class will be deleted.

Abstraction – Extracting the essential details or data while ignoring the unwanted data.

Encapsulation( known as information hiding)-

Polymorphism

• Identical methods behave differently in different classes.

• With the help of an interface it enables to address methods with same name to different objects.

• The signature or the definition of the method is always the same but the implementation is different for different classes.

Inheritance

• Deriving a new class from the existing class

• Can inherit the data and methods of the super class

• Can overwrite the existing methods and can also add new ones.

Overriding– Overriding allows to change the functionality of the inherited methods. This is also known as the redefinition. Overriding is not possible for STATIC methods

Overloading

Overloading allows to change the signature of the inherited methods in the subclasses. ABAP doesn’t support Overloading.

Friends-.

Sometimes, it would be advantageous to give the access to these protected and private attributes to other classes. This can be achieved using the FRIENDS addition.

Narrowing Cast (Up Casting)– When we assign the instance of the Subclass back to the instance of the Superclass, than it is called the “Narrow Casting”, because we are switching from a “More Specific view of an object” to “less specific view”.

Widening Cast (Down Casting)– When we assign the instance of the Superclass to the Subclass, than it is called the Widening Cast, because we are moving to the “More Specific View” from the “Less specific view”. Due to this reason it is also called the “Down Casting”.

Define an event .
Define a method.
Link event and method and convert the method into event-handler method.
Create a triggering method which will raise the event.
Use set handler and register event handler method to a particular instance in the program.

Leave a comment