The Procedural Programming Model
Global variables for a program contain data, while subroutines contain functions.Every subroutine can access all global variables.
Components of a Procedural ABAP Program
A typical procedural ABAP program consists of type definitions and data declarations. The data declarations describe the data structure the program uses when being executed.
It is possible to encapsulate logic in modularization units (for example, subroutines or function modules). However, at the main program level, there is no special protection for global data objects. It is possible to read and change global variables from anywhere in the program.
Encapsulation of Data Using Function Groups
When a function module is called in the main program, its function group is loaded into the internal session. The function group remains active until the main program finishes executing. The system stores the main program and the called function groups in separate memory areas. Even if the data objects of the function groups have the same data object names as they do in the calling program, they do not share the same memory space.
Nothing is shared, even if the data objects of the function groups have the same name. It is not possible to access the global data of a function group directly from the main program. You can only call the function modules of the function groups from the main program. In turn, the function modules can access other components, particularly the global data of their own function group.
Encapsulation also uses the idea that the implementation of a service can be hidden from other components of the system. The reason for this is that the other components cannot and do not need to make assumptions about the internal status of the modularization unit. In this way, the design of these other components is not dependent on the other modularization units being implemented in a specific way.
A function group brings together data and functions. which manages the data. Encapsulated access to data and services is one of the many concepts of the object-oriented programming model. Therefore, this programming model and the procedural part of ABAP Objects support this encapsulation. When implementing the Business Application Programming Interface (BAPI), BAPIs are implemented as function modules and Business Objects are implemented as function groups.
Function Groups
The function group S_VEHICLE provides a user or client with the services Inc_speed, dec_speed, and get_speed. These services are the interface of the function group. They all have access to the global data object speed, which belongs to the function group.
The main program cannot access the data object speed of the function group directly.
Multiple Instantiation
In order for the main program to work with several vehicles, there must be additional programming and administrative effort. A function group can only refer to one vehicle at a time.
Multiple Instantiation in Object-Oriented Programming
The possibility to create several runtime instances using the same program context is one of the key characteristics of object-oriented programming.
In this example, you will develop a program to create four vehicles, all of which have different characteristics.
However, all the vehicles share the same data structure and the same set of functions. They all have the ability to protect their data from outside access.
ABAP Main Memory and Encapsulation
The features of encapsulation using function groups and subroutines are as follows:
The features of encapsulation using objects are as follows: