You are on page 1of 4

FUNCTION MODULES

Function modules are reusable section of codes. Functions modules generally used for global modularization. Functions modules contain functions that are used in the same form by many different programs. Functions modules must be defined in function group & called from any program. Function modules are similar to external subroutines. Function groups acts as container for function modules that logically belong together, we cannot execute function group. When we call a function module the system loads the whole of its function group into the internal session of the calling program. A single function group may contain one or more function modules which are logically related. The advantages of function modules are which helps code reusability. We can handle exceptions using functions modules. Each function group is known by a four character identifier called Function group id. If its user created function group than its begins with y or z. Function groups are stored in a group of tables with in the database called the function library or central library. To access the function library from the development workbench, press function library button on the application toolbar or use the transaction code SE 37. Syntax for detaining function module FUNCTION <name> ----------------------------------------------------------------------------------------------------END FUNCTION

Syntax for all function statement Call function FUNCTION MODULE NAME ---> function module name must be in upper case other wise it will not find and a short dump will result [Exporting P1 = V1] [Importing P2 = V2] [Changing P3 = V3] [Table P4 = IT] [Exception X2 = N [otherwise]} P1-P3 --> parameter name defined in function module V1-V3 -->are variables or field strings defined within the calling program IT --> internal table defined with in the calling program. X2 --> exception name

Function modules have the following interface parameters 1) Import parameter: A variables or filed string that contains values passed into the function module from the calling program. These values originate outside of the function module. They are imported into it. These must be supplied with data when you call the function module unless they are flagged as optional. 2) Export parameter: Are variables or field string that contains values returned from the function module. These values originate within the function module and they are exported out of it. These are also optional you may not have received in your program. 3) Changing parameter: These are variables or field string that contains values that are passed into the function module changed by code within the function module and then returned. These values originate outside the function module. They are passed into it, changed and passed back to the calling program. 4) Table parameter: These are internal tables that are passed to the function module changed within it and returned. The internal table must be defined in the calling program. 5) An exception: is a name for an error that occurs with in a function module. To pass parameters to a function module, we must define function module interface. The function module interface is the description of the parameters that are passed to and received form the function module. It is also called simply interface. Passing parameters: The methods for passing parameters to the function modules are very similar to those for passing parameters to external subroutines

By default 1) Import and Export parameter are passed by value 2) Changing parameters are passed by value and result 3) Internal tables are passed by reference. To come out of the function module at any time we use the statement called 1) RAISE ->which terminates the program and switches to debugging mode. 2) The message--->rising This statement display the specified message how the processing continues depends on the message type.

Types of functions modules There are two types of function module 1. Normal 2. Remote function call(RFC) 1. Normal: This function module is used for ABAP programming with in the system. It is normal function module. We can work within the system only. 2 .Remote function call (RFC): This function module can be called remotely by using RFC destination. Here remote means external system; it may be a SAP system or non SAP systems like java system. If it is RFC, we can work with in the system as well as across the system. Remote function modules are function modules that can be called from other SAP or non SAP systems. BAPIS are examples of RFC MODULES Types of RFCS 1. 2. 3. 4. 5. Synchronous RFC Asynchronous RFC Transaction RFC Queued RFC Parallel RFC

1) Synchronous RFC: It is the very common method used in real business scenarios. Both the client and server must be available in this type of RFC. The advantage is that you can get the result immediately. Which means the RFC function module gives result or output immediately. The syntax: CALL function<function-module name>destination<RFC destination name> 2. Asynchronous RFC: Asynchronous remote function call are similar to transactional RFCS in that the user does not have to wait for their completion before containing the calling dialog. There are three characters however that distinguish asynchronous RFCS from transaction RFCS 1) When the caller starts an asynchronous RFCS the called serve must be available to accept the request. The parameters of asynchronous RFCS are not logged to the database but sent directly to the server. 2) Asynchronous RFCs allow the user to carry on interactive dialog with remote system. 3) The calling program can receive results from the asynchronous RFC. You can use asynchronous remote function calls whenever you need to establish communication with remote system but do not want wait for the functions result before continuing processing. Asynchronous RFC can be also sent to the same System. In this case the

system opens a new session (or window) and allows you to switch back and forth between calling dialog and the called session.

Subroutine 1) Subroutines are for local modularization Maximum 2) Are not remote enabled 3) No support for exception handling 4) Not stored in SAP library stored in ABAP Memory 5) Not executed directly we have embedded in ABAP program before executing

Function modules 1) It is for global modularization 2) Are remote enabled. 3) It supports exception handling 4) Stored in SAP library i.e. Functional library 5) Directly executed.

You might also like