0% found this document useful (0 votes)
60 views

Function Module

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
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Function Module

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
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

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.

You might also like