Function Module
Function Module
Function module
The function module will be edited in the update task. It cannot be updated
subsequently
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).
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,
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.
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
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.
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.
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).