Understanding the Function Module in SAP ABAP: A Comprehensive Overview

What Is Function Module In Sap Abap

Function Modules are Global ABAP programs created by SAP for reusable purpose . They have IMPORT, EXPORT and TABLE parameters, and EXCEPTIONS to through when error occurs. You can create them from TCode TCode Tcode stands for Transaction Code .It is an SAP Magic Word for calling the standard / Customer Programs. U can create the tcode in the transaction se93. Tcodes are stored in the table TSTC. https://community.sap.com › what-is-tcode › td-p What is TCODE – SAP Community SE37.

What Constitutes a Function Module in SAP ABAP?

Import Parameters: These are the inputs of the function module that are sent from the main program.

Export Parameters in SAP ABAP are the results or outputs of a Function Module (FM). These parameters are initially empty when they are sent from the main program to the FM. However, once processed within the FM, they return back to the main program with their respective output values.

Altering Parameters: These are input parameters that undergo modification during the process and subsequently become output parameters of the Function Module.

Exception parameters are parameters that trigger specific exceptions that our code anticipates.

Understanding SAP Functional Modules

Another important module is Production Planning (SAP PP), which helps companies plan and control their manufacturing processes. This module allows businesses to create production schedules, track inventory levels, and ensure efficient production workflows.

Material Management (SAP MM) is another functional module that focuses on managing the procurement process for materials needed by a company. It helps with tasks such as purchasing goods from suppliers, managing inventory levels, and ensuring timely delivery of materials.

Creating a Function Module in SAP ABAP: A Step-by-Step Guide

We will be developing a function module that performs calculations on two given numbers.

IV_OPERAND_1 and IV_OPERAND_2 are the two variables involved in this process.

The outcome of the computation is determined by the action specified in the IV_OPERATION parameter. There are two potential actions that can be performed.

The function module in SAP ABAP can perform mathematical operations such as addition (+) or subtraction (-).

The outcome of the computation is saved in the EV_RESULT parameter.

In case the IV_OPERATION is neither addition (+) nor subtraction (-), the function module will generate an exception known as OPERATION_NOT_SUPPORTED.

You might be interested:  Launching Fiori from SAP GUI: A Step-by-Step Guide

Distinguishing between function module and class in SAP ABAP

Function Modules in SAP ABAP are independent programs that receive input, perform certain operations or calculations, and provide output. They can be thought of as small units of code that can be reused in different parts of a larger program. For example, if you have a calculation that needs to be performed multiple times within your program, you can create a function module for it and call it whenever needed.

On the other hand, Object-Oriented Programming (OOP) is a programming approach that has revolutionized how real-life scenarios are represented in computer programs. OOP allows developers to model entities from the real world as objects with attributes (data) and behaviors (methods). These objects can interact with each other through messages, enabling more flexible and modular programming.

In simpler terms, think of function modules as individual tasks or functions that take some input data, process it using predefined logic or algorithms, and produce an output result. They are like building blocks that can be combined together to create complex programs. On the other hand, object-oriented programming is a way of organizing code by creating objects that represent real-world entities. These objects have their own characteristics (attributes) and actions they can perform (methods), making them more versatile for solving various problems efficiently.

Overall, both function modules and object-oriented programming play important roles in SAP ABAP development by providing reusable code components and allowing for better organization and modeling of software systems respectively

How to Create a Function Module in SAP ABAP

To access Function Builder in SAP, simply open transaction SE37 from the SAP easy access menu.

Please be aware that using /OSE37, /O will open a new session or window for the SE37 transaction.

Enter the new “Function Module” name. In my case I will name it: ZAS_LIB_HPL_CALCULATE_DEMO.

In SAP, Function Modules are named with either Z or Y, while my initials AS are also used. This naming convention is crucial to ensure easy understanding and management of the modules.

Enter the “Function group”. The function group must be defined before the creation of the function module.

Enter the “Short text” to describe the function module, e.g. “ABAP Academy Demo Calculate FM”

An informative pop-up appears on the screen, showing a message. To continue, simply click on the green button.

“Attributes” Tab

On this tab, we present all the input parameters for the function module.

Checkbox “Optional” means that the current parameter is optional and does not need to be filled.

There are three parameters that need to be imported for the calculate function module.

  • IV_OPERAND_1
  • IV_OPERATION
  • IV_OPERAND_2

– IV_OPERAND_1

– IV_OPERATION

– IV_OPERAND_2

Importing parameter starts with “IV”, which stands for “Importing Variable”. This naming convention is important for readability and maintainability. By doing this, we know that all parameters starting with “IV” are importing parameters.

You might be interested:  Sap S 4Hana Finance: Enhancing Cash Management

The content value of IV_OPERAND_1 and IV_OPERAND_2 is in the form of an Integer.

The IV_OPERATION variable is a one-character type that can hold either the plus (+) or minus (-) sign.

“Export” Tab

In this section, we offer all the exporting parameters for the function module. For this particular calculation function module, there is only one exporting parameter called EV_RESULT. It is an Integer type and it stores the outcome of the calculation.

The name of the parameter that is being exported begins with EV, which represents an Exporting Variable.

“Changing” Tab

In this section, we offer all the modified parameters for the function module. The calculation function module does not contain any altered parameters.

To illustrate the process of creating a changing parameter, an example called CV_DEMO has been created. The name of a changing parameter typically begins with “CV,” which is short for Changing Variable.

Please ensure that you remove this parameter as it will not be utilized in the given example.

“Exception” Tab

In this tab, we create an exception(s) to catch certain types of errors. As our calculation function module only will use addition (+) and subtraction (-), we need to create an error exception when the operation that is sent by the main program is not supported.

This is the real ABAP Editor where we execute the programming instructions for the Function Module.

ABAP includes pre-generated comments that include all the parameters: Import, Export, Changing parameters, and Exceptions.

Code implementation

This piece of code performs calculations on two variables: IV_OPERAND_1 and IV_OPERAND_2.

The value in IV_OPERATION can either be added (+) or subtracted (-).

Initially, I empty the exporting parameter EV_RESULT. The purpose of doing this is to demonstrate that this parameter is meant for exporting and it should not contain any value at the beginning of the logic execution.

Next, I search for the function in IV_OPERATION. If:

The value of IV_OPERATION is the addition symbol (+), which means that we need to add IV_OPERAND_1 and IV_OPERAND_2 together.

The value of IV_OPERATION is a subtraction symbol (-), which means that we need to subtract the value of IV_OPERAND_2 from IV_OPERAND_1.

If the value of IV_OPERATION is neither addition (+) nor subtraction (-), an exception will be raised.

Verify the coherence (CTRL+F2) and enable the function (CTRL+F3).

The function module ZAS_LIB_HPL_CALCULATE_DEMO is generated.

To check the function module, simply press (F8) to run it, and you will see the following screen displayed.

To carry out the calculation, input the values of IV_OPERAND_1, IV_OPERATION, and IV_OPERAND_2 and then click on Execute (F8).

You might be interested:  Training and job placement opportunities for SAP FICO in the United States

The value of EV_RESULT is populated with the outcome of the calculation, as illustrated in the following manner:

If the IV_OPERATION entered is multiplication (*), it raises an exception because the operation is not supported.

SAP: Understanding Function Module and Function Group

Function groups in SAP ABAP are like containers that hold function modules. However, you cannot directly execute a function group on its own. Instead, when you call a specific function module, the entire function group associated with it gets loaded into the internal session of the program making the call. This loading process occurs only if the function group has not already been loaded.

To simplify this concept further:

1. Function Groups: These are storage units or containers for holding multiple related function modules.

2. Function Modules: They are individual blocks of code within a function group that perform specific tasks or operations.

3. Execution: While you cannot directly execute a whole function group, you can call and execute individual functions/modules within it.

4. Loading Process: When calling a particular module, if its associated function group is not already loaded, it will be automatically loaded into memory before executing the requested module.

Definition of a function module in PLC

Function modules in SAP ABAP are utilized to streamline the coding process for intricate control logic. They play a crucial role in minimizing the time and effort needed to develop and test PLC programs. By encapsulating specific functionalities within function modules, developers can easily reuse code, enhance maintainability, and improve overall efficiency. These modules act as self-contained units that can be called from various parts of a program, making it easier to manage complex business processes. Additionally, function modules provide an abstraction layer that allows programmers to focus on specific tasks without worrying about the underlying implementation details. This modular approach promotes code reusability and simplifies debugging and troubleshooting processes.

Is SAP ABAP considered a functional module?

The SAP System is equipped with a range of pre-defined function modules that can be accessed from any ABAP program. These function modules serve various purposes, including facilitating updates and enabling communication between different SAP systems or between SAP systems and remote systems through remote communications. Function modules are essential components in the overall functionality of the SAP system.

Function modules play a crucial role in ensuring smooth data processing within the SAP environment. They provide standardized procedures for performing specific tasks, such as retrieving data from databases, executing complex calculations, or generating reports. By encapsulating these functionalities into reusable units, function modules promote code reusability and maintainability across multiple programs.