Before jumping to the difference between Class and Function Module, let’s have a short introduction.
An ABAP program consists of program blocks and is executed sequentially. This is a classical approach for programming known as procedural programming model. This model uses functions and subroutines.
Object Oriented programming paradigm is based on class and object and aims to implement real-world entities such as inheritance, abstraction, etc.
Function modules are procedures that have a set of re-usable statements with importing, exporting parameters, etc. These are created in ABAP workbench using the Function Module Builder. They are managed in the central function library. They play an important role in updating and in the interaction between different SAP systems, between SAP systems and remote systems through remote calls. Unlike Include, they can execute independently. Every function module needs to be assigned to a function pool called the function group. A Function group is a container that holds function modules that should be together logically. Function modules also support exception handling to catch any errors while they are running.
Classes are a blueprint for objects and represent a set of properties or methods common to all objects of the same type. The components of a class are called data members. The class provides the flexibility to assign visibility to all its data members. Every instance or objects have unique identity and has its own set of values for the attributes. A class can inherit another class and interfaces. You can read more about classes here.
Now, let’s have a look at their difference.
Difference between Class and Function Module
|It is procedural oriented.||It is object oriented.|
|It is created using Function Module Builder (T-code se37).||It is created using Class Builder (T-Code SE24).|
|It is always public.||A class can be Public, Private or Protected.|
|Variables are always Private.||Variables can be Public, Private or Protected.|
|Cannot create any instances.||Can create multiple instances.|
|Inheritance is not possible.||Inheritance is possible.|
|Screens can be created using it.||To create a screen, the class must call another program.|