Wednesday, January 7, 2009

Function Modules


Repeatedly done piece of codes doing specific tasks can be put into global place.
Stored in R/3 repository.

Creating Function Module:
Requirement: Pass A, B values, get results.

For function modules, we must have function groups.

Creating Function groups
Goto SE 80

Function group contains function module(s) as wel as global data which is used by the function modules.
Global data is stored in TOP INCLUDE of function group.

Goto SE80
Open function group – double clock on it
Click on main program.
Double click on TOP INCLUDE.
Declare variables.
Goto SE37. Enter module name, click on create.
Enter function group name and short description.

Click on Attributes
NOTE: There are 3 types of function modules:
1. Normal – Used for modularization purpose.
2. Remote Enabled – Used to call function module from another server.
3. Update modules. Used to update the database by using the update work processes.
We should use update more often.

Click on IMPORT.
Enter the cariables which are used by the function modules and for which values will come from main program.
NOTE: We can not change input parameter value.

Click on EXPORT
Enter variables which will be passed to main program.

Click on changing
Changing parameters’ value can be changed.

Click on Tables
Here we pass the internal tables.
If more than one table is updating internal table, we can create a structure and define internal table of type structure.
Structure can be defined in source code or TOP INCLUDE.

Click on Source Code
Write the logic.

Callin function modules in the main program.

Create an executable program.

To call the function module: Place cursor where we want to call the function module, click on Pattern ( ctrl + F6)
Enter function module name.

Exception handling in function modules
Open function module in change mode, click on exceptions tab.
Enter exception name. ( eg – RAISE_EX 0)
Goto source code
IF b =0.

Whenever we call the function module for the first time, the total function group will be loaded into the runtime environment along with the global variables.
Function module called twice will be loaded once and used again.
Above is the major difference between function modules and object oriented programming.
Otherwise, function module , like OOPs, also do encapsulation.

Analyzing Short Dump
GOTO tcode: ST22
Click on today or whatever time the error occurred.

Double click on source code extract and system will take us to the line where error has occurred.

No comments: