Function Module in SAP
Function Module in SAP
Q.What is a Function Module in SAP ABAP ? What is a Function Group in SAP ? Creating
Function modules in SAP ABAP, calling function modules in SAP ABAP programs?
Function Modules are sub-programs which contains set of re-usable statements with importing, exporting
parameters, exceptions. Unlike include programs Function Modules can be executed independently.
Function Group in SAP ABAP
Function group is a container of Function modules, every Function Module must be saved in a Function
group. T-codes for Function Modules and Function groups are SE37 OR SE80. We can save N number of
Function Modules in a Function Group.
Components of Function Module:
Import: These are input parameters of a Function Module.
Export: These are output parameters of a Function Module.
Changing: These are parameters which act as importing and exporting parameters to a Function Module.
Tables: These are internal tables which also acts as importing and exporting parameters.
Exceptions: Exceptions in Function Modules are used to catch certain type of errors.
In this lesson we are going to learn how to create Function Group and Function Module, in order to create a
Function Module we need a Function Group (We can save in existing one also), follow the below steps to
create a Function Group.
Go to SE80.
Select 'Function Group' from drop-down list.
Provide a Function Group name ex: ZTFUNCTIONGROUP and press enter.
A Popup will open Click on 'Yes' and provide short text, click on save.
A pop up will open, provide a Function Group name ZTEST_SAPNUTS and short text, Save .
An information message will come saying that Function Module name is reserved for SAP , just click on
continue icon
Source Code
Declare work area and an input field (parameter).
A pop up will open, select CALL FUNCTION radio, provide Function Module name and click on continue icon
(tick mark at the bottom).
The below code will be generated.
CALL FUNCTION 'ZSAPN_GET_MATERIAL'
EXPORTING
IM_MATNR =
IMPORTING
EX_MARA =
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
Now pass material no parameter and receive material data into a work area, full program code is below.
REPORT ZSAPN_GET_MATERIAL.
DATA : WA_MARA TYPE MARA .
START-OF-SELECTION.
CALL FUNCTION 'ZSAPN_GET_MATERIAL'
EXPORTING
IM_MATNR = P_MATNR
IMPORTING
EX_MARA = WA_MARA .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
Output