
Function Modules
A Function Module is a function created and stored in SAP that can be used by any ABAP program. These functions are accessible through the SE37 transaction, where you can create, modify, and visualize functions. They have a defined interface, facilitating the passing of parameters in and out.
CALL FUNCTION '<function_name>'
EXPORTING
<input_parameters>
IMPORTING
<output_parameters>
TABLES
<tables>
EXCEPTIONS
<exceptions>.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = 'Bank Application'
TEXT_QUESTION = 'Do you want to delete the record?'
TEXT_BUTTON_1 = 'Yes'
TEXT_BUTTON_2 = 'No'
DISPLAY_CANCEL_BUTTON = ''
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2.
In this example, we call the function 'POPUP_TO_CONFIRM' to request user confirmation before performing a specific action. If an exception occurs, a message is displayed.
Creating a function module
When creating a new function through the SE37 transaction, associate it with a function group. If the group doesn't exist, create one. A function group is a repository that groups functions, primarily used for sharing subroutines and variable declarations.
- Navigate to "Go to" > "Function Group" > "Create Group" Enter the group name and create it.
- For declaring global variables that can be used in all functions inside the function group "Go to" > "Global Data"
- To create subroutines for the entire group, go to "Go to" > "Master Program" Uncomment the first include, change its name starting with 'Z', and create subroutines inside.
After creating the group, return to the SE37 transaction, enter module name, group, description, and press create. This leads to a page with tabs:
- Attributes: Specify function description and processing type (Regular, Remote-RFC, or Update module).
- Import: Specify function input parameters.
- Export: Specify function output parameters.
- Changing: Specify output parameters that change during function execution.
- Tables: Specify tables used in the function.
- Exceptions: Specify function exceptions, predefined errors for quick error identification.
- Source Code: Enter the ABAP code for the function.