SAP ABAP Function Modules - SAP ABAP

What are the function modules?How do they define?

Function modules play a very important role in SAP system. Because SAP contains several function modules that can be called from any ABAP programs. These can perform independently. They also play a vital role in updating databases.
Function modules are the procedures defined in the function groups and can be called from any ABAP programs. These are the sub-programs that have a set of reusable statements with appropriate function group acts as import and export parameters. Number of function modules are kept in a function group which acts as a container and it can be put together. For example, the function modules for an HR payroll system would be put together into a function group which acts as a container.
To create function modules, go to the transaction code will find the function builder as shown below. Type the name of the function module with the wild card character to find out how the function modules can be searched. Type *amount* and then press the F4 key.
You can see the results of the search that are displayed in a new window. Here back ground is highlighted with blue where the function modules are displayed in the lines. And the function groups are displayed with effective pink lines. You can also see a list of function modules and other objects using Object Navigator Screen placed in the function group. Let's assume the function module as SPELL_AMOUNT. This function module converts numeric figures into words.

Creating a New Program

Step 1 – enter transaction code SE38 and create a new program called Z_SPELLAMOUNT.
Step 2 − Enter any code so that a parameter can declares where a value could be entered and passed on to the function module. Here The text element text-001 reads as ‘Enter a Value’.
Step 3 – Press CTRL+F6 to write the code. A window appears as shown below where you can see the ‘CALL FUNCTION’ is the first option in a list. Update 'spell amount' in the text box and click the continue button.
Step 4 − Code is generated automatically. First the code need to be included by IF statement. Then Activate the message button and write a message to the screen as “The function module returned a value of: sy-subrc”. Then include the ELSE statement so that correct result will be displayed when the module is successful. Here, include a new variable to hold the value that is returned from the function module. The new variable is ‘result’.
Following is the code –
Step 5 − The variable which the function module returns is called IN_WORDS. Enter the corresponding variable in the program called ‘result’. IN_WORDS defined by using the LIKE statement to refer to a structure called SPELL.
Step 6 − Save, activate and execute the program. Enter a value as shown in the following and press F8.
The above code produces the following output −
The code is successfully entered.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status