ABAP

ABAP (Advanced Business Application Programming or Generic Processor for Report Preparation). It is a fourth generation programming language. It is used to program the Resource Planning Systems of a company.

It is a programming language specialized in the management of companies’ resource planning systems. It uses statements from another programming language, Open SQL to connect databases . It is a language for managing files, databases, dates, etc. It allows RFC (Remote Function Calls) connections to connect SAP systems with any other system or programming language.

Summary

[ hide ]

  • 1 Story
  • 2 ABAP objects
    • 1 From functions to objects
    • 2 Local and global classes
    • 3 Definition of local classes
    • 4 Components of classes
    • 5 Use of objects
      • 5.1 Objects
      • 5.2 Object references
    • 6 Inheritance
    • 7 Classes and abstract methods
    • 8 Interfaces
      • 8.1 Definition of interfaces
      • 8.2 Interface implementation
    • 9 Trigger and handle events
  • 3 ABAP OO
  • 4 Sources
  • 5 See also

History

ABAP was invented in the 80s, with this language we wanted to achieve a kind of platform that would allow large companies to create applications to improve the management of their businesses.

ABAP was very similar to Cobol in its origins, it was created so that end users could use it without problems, but over time it became increasingly complex for normal users, and currently only expert programmers can use it.

ABAP remained the development language for the next client-server version of SAP R / 3, which was released in 1992, in which almost the entire system, except for basic system calls, was written in ABAP. In 1999, with the release of version 4.6 of R / 3, SAP released an object-oriented extension called ABAP Objects . The latest SAP development platform , NetWeaver , supports ABAP and Java as programming languages.

ABAP objects

ABAP Object Oriented Extension, ABAP Objects is a set of object-oriented statements that have been introduced into the ABAP language. This extension is cemented in the existing language, being compatible with it. Objects can be used in existing programs, just as conventional ABAP statements can be used in object-oriented ABAP programs. The rest of the ABAP language is created from the beginning oriented to a structured programming, in which the data is stored in a structured way in tables in the database and the programs through functions access them.

From functions to objects

ABAP Objects allows you to define data and functions in classes rather than in groups of functions. Using classes, an ABAP program can work with any number of instances (objects) based on the same template. Rather than implicitly loading a single instance of a group from a group of functions when calling the function module, the ABAP program can now explicitly generate the instances of the class using the new ABAP CREATE OBJECT statement. Each instance represents a single object, and each instance can be accessed by its reference. The object reference is what allows an ABAP program to access the interfaces of the instance.

Local and global classes

Classes in ABAP Objects can be declared either globally or locally. Global classes are defined in the class generator (transaction SE24) in the ABAP Workbench . These classes are stored in class pools in the class library in the R / 3 Repository. All ABAP programs in an R / 3 system can access global classes. Local classes are defined in an ABAP program. Local classes and their interfaces can only be invoked from the program in which they are defined.

When using a class in an ABAP program the system first searches for a local class with the specified name. If it doesn’t find any then it looks for a global class. Other than the visibility issue, there is no difference between using a global class or a local class. What does change significantly is the way in which a local class and a global class are created. If you define a class to be used in a single program, it is usually sufficient to apparently define the visible components so that the class fits the program. On the other hand, global classes must be prepared to be used anywhere. This means that certain restrictions have to be applied when defining the interface of a global class,

Defining local classes

The local classes are the set of statements that are between the CLASS … and ENDCLASS statements.

A complete definition of a class will consist of a declarative part in which the components are defined, and if necessary an implementation part in which these components are implemented. The declarative part of a class is included between the sentences:

CLASS <class> DEFINITION. … ENDCLASS.

Components of classes

In ABAP Obejcts, classes can define the following components (since all components that can be declared in classes can also be declared on interfaces, the following descriptions apply in the same way to interfaces:

Attributes

Attributes are the internal data fields of a class and can have any ABAP data type. The state of an object is determined by the content of its attributes. One type of attributes are the referenced variables. These variables allow you to create and access objects, so if they are defined in a class, they allow you to access other objects from within the class.

  • Instance dependent attributes:The content of these attributes is specific to each object. They are declared using the DATA statement.
  • Static attributes:The content of the static attributes defines the status of the class and is valid for all instances of the class. Static attributes exist only once for the class. They are declared using the CLASS-DATA statement. They are accessible from the entire class execution environment. All objects in a class can access its static attributes. If a static attribute is changed on an object, the change is visible on all other objects in the class.

Methods

Methods are internal procedures of a class that define the behavior of an object. Methods can access all the attributes of a class. This allows them to change the content of the attributes of an object. The methods also have a parameterized interface that allows them to receive values ​​when called and return values ​​after the call. The private attributes of a class can only be changed by methods of the same class.

The definition and interface of a method are similar to those of function modules. A method is defined in the declarative part of the class and is implemented in the implementation part using the statements:

METHOD <meth>. ……. ENDMETHOD.

Events

Objects or classes can use events to trigger a type of method on other objects or classes. These methods are called event handler methods.

In a normal method call, the method can be called by any number of users. When an event is triggered, any number of these methods can be called. The union between the trigger of the event (trigger) and the handler of the event (handler) is not established beforehand, if not in the execution environment. In normal method calls, the calling program determines the methods it wants to call. These methods have to exist. The event handler determines the events to which it has to react. There does not have to be a registered event handler method for each event. Events of a class can be triggered on methods of the same class using the RAISE EVENT statement.

A method of the same or a different class is declared as an event handler method using the FOR EVENT <evt> OF <class> addition. Events have a parameter interface similar to that of methods, but only have output parameters. The parameters are passed by the trigger (RAISE EVENT statement) to the event handler method which receives them as input parameters.

The link between the trigger and the handle (trigger and handler) is dynamically established in the program using the SET HANDLER statement. The trigger and handler can be objects or classes, depending on whether we have instance dependent events or static events and event handler methods. When an event is fired, the corresponding event handler method is executed on all classes registered for that handler.

There are two types of events:

  • Instance dependent events:Declared with the EVENTS statement. They can only be triggered in an instance dependent method.
  • Static or instance independent events:Declared with the CLASS-EVENTS statement.

All methods (instance dependent and static) can trigger static events. Static events are the only type of events that can be triggered by a static method.

Types

ABAP data types can be defined within a class with the TYPES statement. Data types are not instance-specific and exist only once for all objects in the class.

  • Constants

Constants are a special type of static attribute. Their value is fixed when they are declared and cannot be changed. They are declared using the CONSTANTS statement. Constants exist only once for all objects in the class.

  • Encapsulation

The three areas of visibility are the basis of one of the most important characteristics of object orientation, encapsulation. When defining a class, great care must be taken in the design of public components, trying to declare as few as possible. The public components of global classes cannot be changed once the class has been released.

For example, public attributes are externally visible, and are part of the interface between an object and its users. If you want to encapsulate the state of an object completely, you don’t have to declare any public attribute. In addition to defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.

Use of objects

Objects

Objects are instances of classes. Each object has its own identity and has its own attributes. All transient objects reside in the context of an internal session (memory area of ​​an ABAP program). A class can have an indefinite number of objects (instances).

Object references

Object references are used to access an object from an ABAP program. Object references are pointers to objects. In ABAP objects are always contained in referenced variables.

The referenced variables either contain the value ‘initial’ or contain the reference to an existing object. The identity of an object depends on its reference. A referenced variable that points to an object is the one that knows the identity of the object. Users cannot access the identity of the object directly. Variables referenced in ABAP are treated like any other elementary data object. This means that a referenced variable can contain an internal table or a structure.

ABAP contains a predefined data type for references, comparable to data types for structures or for internal tables. The complete data type is not defined until the declaration in the ABAP program. The data type of the referenced variable determines how the program acts with its value, that is, with the reference to the object. There are two main types of references, the class reference and the interface reference (see below).

Class references are defined using the following addition: TYPE REF TO <class>. : This addition is used in TYPES or DATA statements. Such a referenced variable is called a class-referenced variable or simply a class reference. A reference to class <cref> allows the user to create an instance, or an object, of the class and access a visible component as follows: cref-> comp

Heritage

Inheritance allows you to create a new class from an existing class by inheriting the properties from the new class. This is done by adding the INHERITING FROM addition to the class definition statement:

CLASS <subclass> DEFINITION INHERITING FROM <superclass>.

The new <subclass> class inherits all the components of the existing <superclass> class.

The new class is known as the subclass of the class it came from. The original class is known as the superclass of the new class. If no statement is added to the subclass, it contains the same components as the superclass. Either way, only the public and private components of the superclass are visible in the subclass. Although the private components of the superclass exist in the subclass, they are not visible.

Private components can be declared in a subclass that have the same names as private components of the superclass. Each class works with its own private components. The methods that a subclass inherits from a superclass use the private attributes of the superclass and not any private components of the subclass with the same name.

If the superclass does not have a private section, the subclass is an exact replica of the superclass. Anyway, you can add new components to the subclass. This allows the subclass to be converted into a specialized version of the superclass. If a subclass is itself a superclass of other classes, a new level of specialization is being introduced.

A class can have more than one subclass of which it is superclass, but it can only have one superclass of which it is subclass. This is known as simple inheritance, as opposed to multiple inheritance where a class inherits from multiple superclasses. When a subclass inherits from a superclass which itself inherits from another superclass of which it is a subclass, a tree structure is formed in which the degree of specialization increases with each hierarchical level added. Conversely, classes become more general until the root node of the inheritance tree is reached. The root node of all inheritance trees in ABAP Objects is the empty predefined class OBJECT.

This is the most general of all possible classes since it contains neither attributes nor methods. When defining a new class you do not have to explicitly specify this class as a superclass, this relationship is implicitly defined. Within an inheritance tree, two adjacent nodes are the superclass and the subclass directly from each other. Component declarations in a subclass are distributed across all higher levels in the inheritance tree.

Abstract classes and methods

The ABSTRACT and FINAL additions in the METHODS and CLASS statements allow you to define abstract and final methods or classes. An abstract method is defined in an abstract class and cannot be implemented in that class, it has to be implemented in a subclass of the class. Abstract classes cannot be instantiated. A final method cannot be redefined in a subclass. The final classes cannot have subclasses, they are the ones that end the inheritance tree.

Interfaces

Classes, their instances (objects), and accessing objects using referenced variables are the foundation of object-oriented programming in ABAP. Furthermore, there are times when it is necessary for similar classes to provide similar functionalities but which are coded differently in each class, which give a common point of contact with the user.

In ABAP Objects interfaces are independent structures that can be implemented in a class to extend the scope of that class. The specific scope of a class is defined by its components and its visibility sections. For example, the public components of a class define its public scope, since all its attributes and method parameters can be used by all users. The protected components of a class define its scope in terms of its subclasses.

Interfaces extend the scope of a class by adding its own components to the public section. This allows users to access different classes through a common point of contact. Interfaces together with inheritance provide one of the basic pillars of polymorphism, as they allow a single method with an interface to behave differently in different classes.

Defining interfaces

Like classes, interfaces can be defined either globally in the R / 3 Repository or locally in an ABAP program. The definition of a local interface is the code between the statements:

INTERFACE <intf> ……. ENDINTERFACE.

The definition contains the declaration of all the components (attributes, methods, events) of the interface. The same components can be defined in an interface as in a class. The components of the interfaces do not have to be assigned to any visibility section since they automatically belong to the public section of the class in which the interface is implemented. Interfaces do not have an implementation part since their methods are implemented in the class that implements the interface.

Implementation of interfaces

Unlike classes, interfaces have no instances, instead, interfaces are implemented by classes. To implement an interface in a class the INTERFACES <intf> statement is used. in the declarative part of the class. This statement can only appear in the public section of the class.

When an interface is implemented in a class, the components of the interface are added to the other components of the public section. A <icomp> component of an <intf> interface can be addressed as if it were a member of the class under the name <intf ~ icomp>. The class has to implement the methods of all the interfaces implemented in it. The implementation part of the class must contain the implementation of each method of the <imeth> interface:

METHOD <intf ~ imeth>. ………. ENDMETHOD.

Interfaces can be implemented by different classes. Each of the classes is extended with the same set of components, although the interface methods can be implemented differently in each class. Interfaces allow different classes to be used in a uniform way by taking advantage of references to interfaces (polymorphism). For example, interfaces implemented in different classes extend the public scope of each class in the same set of components. If the class does not have any public components specific to itself then the interface fully describes the public scope of the class.

Trigger and handle events

In ABAP Objects there are certain methods that are known as triggers and others that are known as handlers . The triggers are methods that trigger an event, while handlers are methods that are executed when an event occurs.

  • Triggering events

To trigger an event, a class must: – declare the event in the declarative part. – trigger the event in one of its methods.

  • Declaration of events

Events are declared in the declarative part of a class or in an interface. To declare instance dependent events use the statement: EVENTS <evt> EXPORTING … VALUE (<ei>) TYPE type [OPTIONAL] .. To declare static events use the statement: CLASS-EVENTS <evt> …

Both statements have the same syntax.

When an event is declared you can use the EXPORTING addition to specify parameters that are passed to the event handler. The parameters are always passed by value. Instance dependent events always contain the implicit parameter SENDER, which has the type of a reference to the type or interface on which the event is declared.

ABAP OO

The latest version, ABAP OO, is Object Oriented programming. SAP runs scheduled applications in both ABAP and ABAP OO.

The SAP R / 3 business model was developed before the concept of object-oriented programming was extended. The transition to the object-oriented model reflects an increase in customer demand for this model. ABAP OO uses a unique inheritance model and full support for object features like encapsulation , polymorphism, and persistence.

 

by Abdullah Sam
I’m a teacher, researcher and writer. I write about study subjects to improve the learning of college and university students. I write top Quality study notes Mostly, Tech, Games, Education, And Solutions/Tips and Tricks. I am a person who helps students to acquire knowledge, competence or virtue.

Leave a Comment