Function Modules are like Functions which can be called in any ABAP Program and can also be called external to SAP System. These are sub-programs and contain a set of statements with exporting, importing parameters and exceptions. It is a must for function module to save it in a Function Group.
Although, Sub-Routines also act like functions but both Function Module and Sub-Routine are different from each other. Now, we will see following what are differences between Function Module and Sub-Routine.
Difference between Function Module and Sub-Routine:
Function Module | Sub – Routine |
Create external to ABAP Program | Create internal to ABAP Program |
Can call from any ABAP Program and also Outside the SAP System | Can call from any ABAP Program in which it is created and can’t be called outside the SAP System. |
Set of statements provide re-usability in the SAP System and outside SAP System i.e. globally. | Set of statements provide re-usability in the SAP System i.e. locally in ABAP Program. |
T-Code to create a function module is SE37. | No T-Code provided to create a Sub-Routine as it is created in ABAP Program. |
Steps to create a Function Module: –
Step 1: – Type the T-Code SE37 and then Press Enter Key.
Step 2: – Type the name of Function Module and Click on the create button.
Step 3: – Type the name of Function Group in which you want to create your function module and short text, and then click on the Save button.
Step 4: – Open Attributes tab, choose Processing Type as we are seeing in following fig. there are two Processing Types Normal Function Module and Remote Function Module.
Normal Function Module: On choosing this option, you can call function module in any ABAP Program anywhere in SAP system.
Remote Function Module: On choosing this option, you can call function module in any ABAP Program anywhere in SAP system and also call external to system like in ASP.Net Web application you can call SAP Function Module. Calling a Function Module outside the SAP System is known as Remote Function Call or RFC.
Step 5: – Open the Import tab and Import Parameters.
Step 6: – Open the Export tab and Export Parameters.
Step 7: – Open the Tables tab and Internal Tables Parameters.
Step 8: – Open the Exceptions tab and Exception Parameters.
Step 9: – Open the source code tab, and write your code.
Now, Save and Activate it by pressing Ctrl + F3 key and Execute your Function Module to check it give the desired result or not.