100% found this document useful (1 vote)
46 views4 pages

Types of Function Modules in SAP ABAP

Function modules are modular units that can be called both within and across systems. They have uniquely defined interfaces and parameters that can be imported, exported, or changing. Function modules return values and exceptions unlike subroutines. Subroutines can be internal, called within a program, or external, called across programs. Parameters for subroutines can be passed by reference, value, or value-result. Macros are code abbreviations expanded at compile time within the program, while subroutines and functions can be called externally.

Uploaded by

pal singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
46 views4 pages

Types of Function Modules in SAP ABAP

Function modules are modular units that can be called both within and across systems. They have uniquely defined interfaces and parameters that can be imported, exported, or changing. Function modules return values and exceptions unlike subroutines. Subroutines can be internal, called within a program, or external, called across programs. Parameters for subroutines can be passed by reference, value, or value-result. Macros are code abbreviations expanded at compile time within the program, while subroutines and functions can be called externally.

Uploaded by

pal singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Function Module (SE37) & Subroutine & Macros.

Function module

 A function module is one of main modularization unit. It is very similar to external


subroutines like,
Both exist within external program,
Both enables to passed and return the parameters,
Parameters can be passed by value, passed by result and passed by reference.

 ATTRIBUTES (FUNCTION MODULE)


Three processing type or three types of function module,
Normal: that can be executed within system only.
RFC: that can be executed with cross sytems.
Update module: There are four types

1. Start update immediately

The function module is processed immediately in the update task.

2. Update is started immediately, no restart possible

The function module will be edited in the update task. It cannot be updated
subsequently

3. Start of update delayed

The function module is processed in the update task as a low priority item. You
use delayed update primarily for database changes that are not time-critical (e.g.
statistical updates).

4. Update triggered by collector (for internal use only)

A number of similar function modules that previously used to run individually in


the V2 update process can be grouped together and run collectively.

Global check box in attributes

If we want to make our parameters interface then we need to check this check
box.

If you select this field, the system declares the interface parameters in the function
group globally. This means that, within the function group, you can access the
function parameters in subroutines, as well as PBO and PAI modules.
 A major difference between Function module and normal subroutine are,

 In contrast to normal subroutines function modules have uniquely defined


interface.
 Sub routines do not return values.
 Sub routines do not return exceptions.
 Sub routines cannot be tested independently.
 Declaring data as common parts is not possible for function modules.
Function modules are stored in a central library.

 A major difference between Function module and external subroutine are,


 Function modules have a special screen used for defining parameters-parameters
are not defined via ABAP/4 statements.
 tables work areas are not shared between the function module and the calling
program.
 Different syntax is used to call a function module than to call a subroutine.
 Leaving a function module is accomplished via the raise statement instead of
check, exit, or stop.

 Function module parameters:


 Import parameters
 Export parameters
 Changing parameters
 Table Parameters
 Exceptions

Import parameters are variable that contains values passed into the function module
from the calling program.

Export parameters are variables that contains values returned from the function
module.

Changing parameters are variable that contains values that are passed to the
function module, then changed by the code within the function module, then returned.
In short, this values passed by calling program, change into function module and then
returned back.

Table parameters are internal tables that are passed to the function module and
change within it and returned. Internal table must be defined in the calling program.

Exception is used for the raising (handling) the errors.

 PASSING PARAMETERS

By default:
 Import and export parameters are passed by value.
 Changing parameters are passed by value and result.
 Internal tables are passed by reference.
 What are the different methods of passing data?

A. Calling by reference: During a subroutine call, only the address of the actual
parameter is transferred to the formal parameters. The formal parameter has no
memory of its own, and we work with the field of the calling program within the
subroutine. If we change the formal parameter, the field contents in the calling
program also change.
B. Calling by value: During a subroutine call, the formal parameters are created as
copies of the actual parameters. The formal parameters have memory of their
own. Changes to the formal parameters have no effect on the actual parameters.
C. Calling by value and result: During a subroutine call, the formal parameters are
created as copies of the actual parameters. The formal parameters have their
own memory space. Changes to the formal parameters are copied to the actual
parameters at the end of the subroutine.

Subroutine

 The following are differences between external and internal subroutines:

 A global variable defined by using data is known only within the program that
defines it.
 A global variable that has the same name in both programs and is defined using
the tables statement in both programs is common to both programs. A change to
this variable in one program affects the other.
 What are subroutines?

Subroutines are program modules which can be called from other ABAP/4 programs or
within the same program.

 What are the types of Subroutines?

A. Internal Subroutines: The source code of the internal subroutines will be in the
same ABAP/4 program as the calling procedure (internal call).
B. External Subroutines: The source code of the external subroutines will be in an
ABAP/4 program other than the calling procedure.

 What are the different types of parameters?

Formal parameters: Parameters which are defined during the definition of subroutine
with the FORM statement.

Actual parameters: Parameters which are specified during the call of a subroutine with
the PERFORM statement.

Macros
 What is the difference between macro and subroutine?-

Macros can only be used in the program they are defined in and only after the definition
are expanded at compilation / generation.
Subroutines (FORM) can be called from both the program they are defined in and other
programs.

A MACRO is more or less an abbreviation for some lines of code that are used more than
once or twice.
A FORM is a local subroutine (which can be called external).

A FUNCTION is (more or less) a subroutine that is called external.


Since debugging a MACRO is not really possible, prevent the use of them (I’ve never
used them, but seen them in action).
If the subroutine is used only local (called internal) use a FORM. If the subroutine is
called external (used by more than one program) use a FUNCTION.

Common questions

Powered by AI

Function modules support comprehensive code modularization by providing a well-defined interface, error handling through exceptions, and independent testing capability, unlike macros which expand code only internally and have limited debugging capabilities . Additionally, function modules support complex data types through structured parameter passing mechanisms and are centrally stored, which enhances reusability and maintainability .

Function modules have uniquely defined interfaces, return exceptions, and are stored in a central library, whereas subroutines do not return values or exceptions, cannot be independently tested, and do not have defined interfaces . Function modules utilize a special screen for defining parameters, while subroutines define parameters via ABAP/4 statements. Additionally, parameters in function modules are not shared with the calling program and use different syntax for calling .

Formal parameters are defined during the subroutine's definition with the FORM statement and serve as placeholders for the values to be used within the subroutine. Actual parameters are specified during the subroutine call using the PERFORM statement and provide the concrete values or references that populate the formal parameters during execution . This separation helps ensure that subroutine logic is sufficiently abstracted from specific data values.

The 'raisin' statement in function modules is used for handling exceptions, allowing for robust error management by defining and responding to specific error conditions during module execution . This mechanism helps isolate and manage errors more predictably, preventing unforeseen failures and maintaining system stability. It facilitates clearer communication about potential errors between the module and the calling environment, aiding in troubleshooting and debugging processes.

Update modules in SAP can significantly optimize system performance by managing how data updates are processed. Immediate updates engage quickly but can increase system load. Conversely, delayed updates lower immediate system demands by handling less time-sensitive data operations later, thereby balancing system resource utilization . This strategy reduces performance bottlenecks during peak operational times and upgrades the transaction throughput efficiency at the cost of temporary data inconsistency.

Delayed updates in function modules are primarily considered for non-time-critical database changes, such as statistical updates, where the operation is processed at a low priority. This allows for more efficient system performance management because it minimizes immediate processing load, deferring non-essential tasks for less busy times . However, this can cause a delay in data consistency across the system, which needs to be accounted for during system optimization.

Macros are suitable for simple abbreviation of code used multiple times within the same program but are limited by their lack of debugging capabilities . Subroutines, on the other hand, can be called from both the defining program and other programs, making them suitable for more complex and reusable code structures. They provide better flexibility and debugging options compared to macros .

In function modules, import and export parameters are passed by value, changing parameters by value and result, and table parameters by reference . In contrast, subroutines can utilize calling by reference or by value, where calling by reference passes the address of the actual parameter, and calling by value creates a copy with independent memory .

Internal subroutines are contained within the same program, so global variables are managed within that singular program context. External subroutines, however, can affect global variables if both the calling and the subroutine-defining programs declare a global variable with the same name using the tables statement. Changes to such common variables in one program can impact the behavior in the other .

Using 'calling by value and result' allows a function module to create an independent copy of the parameters initially, thus changes within the module do not immediately affect the original parameters in the calling program. However, once the function module execution completes, any changes made are then applied back to the actual parameters in the calling program . This approach provides a balance between data integrity and transformation flexibility during the execution process.

You might also like