Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Milan Victor – SAP

MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

Function Module in SAP ABAP


Purpose of this document:
This document aims to offer a summary of the Function Module (FM) in SAP ABAP.

Function Module:
Function modules are like mini-programs with reusable code. They have specific tasks and can
take in information, send out results, and deal with errors. These modules are kept in a central
library, making them available to the whole system.

You can use function modules independently. If the code is only used in one program, it's better
to use a subroutine. SAP R/3 system has many built-in function modules that any ABAP program
can use.

Each function module is part of a function group, which holds modules that logically belong
together. Function modules are important for updating databases.

They also play a big role in remote function calls (RFC) between SAP R/3 systems or between an
SAP R/3 system and a non-SAP system. Function modules can handle errors while running
through exception handling.
Features:
 Function Group Association: They are part of a group known as a function group. This grouping
helps organize related function modules together.

 Defined Data Exchange Interface: Function modules have a fixed interface for exchanging data.
This simplifies the passing of input and output parameters, making it more straightforward to
send information to and receive results from the function module. It allows you to set default
values for input parameters and supports exception handling, enabling the capturing and
handling of errors.
 Callable by Name: To use a function module, you call it by its unique name in a CALL FUNCTION
statement. This allows for easy invocation of the specific functionality provided by the function
module.

Tcode – SE37
Types of Function Modules in SAP:
1) Normal Function Module
2) RFC Function Module
3) Update Function Module

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

Normal Function Module:


A normal or Regular Function Module is the default option. This kind of Function Module is
executed immediately and synchronously on your current SAP system.

CALL FUNCTION func { parameter_list | parameter_tables }.

RFC Function Module:


Remote Function Modules are like special tools that other systems, both SAP and non-SAP, can
use. They talk to each other using something called the RFC protocol.

For example, if you make a Remote Function Module in an EWM system, your ERP system can
use it to find out more details about stock levels or shipments.

When you say "CALL FUNCTION func DESTINATION dest parameter_list," you're asking another
system to do something, and it waits for the job to be done before continuing. The places these
tools can talk to are set up in SM59.

After this Remote Function Module is done doing its job, the program that asked for it keeps on
running. But sometimes, depending on how things connect, it might make things slower.

Update Function Module:


Update Function Modules don't run right away; they are scheduled to run later in a process
called an update work process. You start this update process by using the statement COMMIT
WORK. If you want to cancel all the update function modules you've scheduled, you can use the
statement ROLLBACK WORK.

By using CALL FUNCTION .. IN UPDATE TASK, you can group together changes to the database
into a single unit of work. This is helpful for performance because the updates occur in the
background, making things faster

CALL FUNCTION update_function IN UPDATE TASK


[EXPORTING p1 = a1 p2 = a2 ...]
[TABLES t1 = itab1 t2 = itab2 ...].

Parameters in FM:
1) Attributes
2) Import
3) Export
4) Changing
5) Tables
6) Exception
7) Source Code

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

ATTRIBUTES:
In the Attributes section, you'll find details such as the Function Group name, Function module
type, responsible person, change date, Program, and Include Name.

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

IMPORT PARAMETERS:
These parameters are used for passing values into the function module. The values are provided
by the calling program or function module.

EXPORT PARAMETERS:
These parameters are used for returning values from the function module to the calling program
or function module.

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

CHANGING PARAMETER:
These parameters are used for passing values into the function module, and the function
module can modify these values, which are then reflected in the calling program or function module.

TABLES PARAMETER:
These parameters allow you to pass internal tables into the function module, and the function
module can process the data within these tables.

EXCEPTION:
In SAP ABAP (Advanced Business Application Programming), exceptions in function modules are
used to handle errors or exceptional situations that may arise during the execution of the function
module. Exception handling is crucial for identifying and addressing unexpected issues in the program's
execution.

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

Defining Exception:
Within a function module, you can define exceptions using the EXCEPTIONS statement.
This statement is typically placed after the parameter declarations.

Raising Exceptions:
In your function module logic, you can raise an exception using the RAISE statement.
This indicates that a specific exceptional condition has occurred.
IF some_condition.
RAISE custom_exception1.
ENDIF.

Source Code:
In SAP ABAP, the source code of a function module contains the logic and processing
instructions that are executed when the function module is called.

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

How to Create FM:


Prerequisite:
Before Creating the Function module, we need to create the Function group.

How to Create the Function Group:


Go to TcodeSE80Select the Function group option give the FG name and press ‘ENTER’ like below,
STEP1:

STEP2:
A new Popup will come and there we need to press YES Button,

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

STE3:
Next, Give the Short text and press SAVE Button, then it will ask for the package and TR. Give the correct
package and TR and press OK Button.

Assign the package and TR for transport,

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

Create FM:
Go to SE37  Give function module name and press create button,

Then assign the Function group and give the Name and press Save,

https://www.linkedin.com/in/milan-victor-xavier-1713b3192
Milan Victor – SAP
MILLU138@GMAIL.COM
ABAP/Webdynpro/CDS/ODATA/SAP UI5/FIORI

Following the screenshot, you can add your import, export, changing, tables, and exception parameters.

I’m going to write the FM to get the data from the MARA table and export the retrieved value.
Import – Material Number
Export – Mara table structure

Under source code, you can add your logic,

https://www.linkedin.com/in/milan-victor-xavier-1713b3192

You might also like