SAP ABAP - Modularization PDF
SAP ABAP - Modularization PDF
MODULARIZATION TECHNIQUES:
1. SUBROUTINE
● Subroutines are procedures that can be defined in any program and called
from any ABAP program.
● Subroutines normally contain sections of code or algorithms.
● Subroutines can be defined anywhere in the program
● Subroutines can be defined using FORM and ENDFORM statements.
● PERFORM statement is used to call the subroutine
Syntax:
PERFORM PERFORM_NAME.
FORM FORM_NAME.
CODING.
ENDFORM.
SAP ABAP DOCUMENT
External subroutines
CODING.
ENDFORM.
2. INCLUDE
● If the same set of statements (source code) is used in more than one program,
those statements can add to the include program.
● Include programs are only used to modularise the source code but have no
parameter interface.
● Include programs are not standalone programs and cannot be executed
independently.
● Include programs available globally and can be used in any ABAP program.
● Include programs contain small pieces of source code that can be included in a
program with an INCLUDE statement.
● INCLUDE programs can’t call themselves. The INCLUDE program must be
syntax error free and contain complete statements.
CONVENTION—> INCLUDE name should always start with either ‘y’ or ‘z’.
SYNTAX
INCLUDE ZINCLUDE_NAME.
3. FUNCTION MODULE—>
● Function modules are subprograms that contain a set of reusable source code
statements with importing, exporting parameters and exceptions.
● Function modules are stored in the central library.Function modules available to
the entire system. Function modules can execute independently.
● If the source code is only used within the same program, then use a Subroutine.
Otherwise a function module is preferred.
● Every function module is a part of the function group. The function group acts as
a container for function modules that would logically belong together.
● Function modules plays significant role in updating the databases.
After executing the program click on the circled button to get the following output
screen.
2. Select CALL FUNCTION radio button and type the FUNCTION MODULE as per
requirement.
3. Remove commenting by selecting the statements and pressing ctrl + > .
4. Write code to display data.
Actual Parameter : these are the actual values passed to the subroutine
while calling the subroutine..
Formal Parameter : The formal parameters are the parameters that you
define in the subroutine declaration..
EX:
v_y type i.
( or)
(or)
Endform.
v_y type i.
V_x = 40.
V_y = 30.
M1 = k1 + k2.
M2 =k1-k2. endform.
SAP ABAP DOCUMENT
● Macros
● Include
● Subroutines
● Function Modules
● Methods & Classes
● Include programs are used to split ABAP source code into individual repository objects.
An ABAP program can be created in the program attributes using the program type
include program.
● Subroutines are used to modularize the program. Generally Subroutines are called by
using the PERFORM keyword and defined within the FORM and ENDFORM block.
● Actual Parameter : these are the actual values passed to the subroutine while
calling the subroutine..
CHANGING XXX
SAP ABAP DOCUMENT
RETURNING XXX.
● Formal Parameter : The formal parameters are the parameters that you define in
the subroutine declaration..
CHANGING XXX
RETURNING XXX.
● When we PASS lv_num by VALUE, the actual value of lv_num is copied into VAR.
When we PASS lv_num by REFERENCE, the reference, or the memory address of
lv_num is passed to the Function module. So, VAR and lv_num refers to the same
memory address and have the same value.
6. What is the difference between the function module and a normal ABAP/4
subroutine?
● Subroutines do not return values. Subroutines 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.
syntax-
perform form_tc(report_name).
SAP ABAP DOCUMENT
Function Groups :
● Function groups (also called function pools) are ABAP programs of a special type. They
are the only program type that can contain function modules.
● The key components of a function module in SAP ABAP are: Import parameters (input
data), Export parameters (output data), Changing parameters (data that can be
modified both as input and output), Internal tables (used for passing multiple data
values), and Exceptions (error handling mechanisms); all of these are defined within the
function module's interface to clearly define how data is exchanged with the calling
program.
Import Parameters:
These are variables that are passed as input to the function module from the calling
program, and cannot be modified within the function module itself.
Export Parameters:
These are variables that carry the results calculated within the function module back to
the calling program as output data.
Changing Parameters:
These variables act as both input and output parameters, allowing the function module
to modify the data passed in and return the updated values.
Internal Tables:
These are data structures that can be used to pass multiple values as input or output to
a function module, enabling flexible data exchange.
Exceptions:
These are predefined error conditions that can be raised within the function module to
signal issues to the calling program, allowing for proper error handling.
The default option, which runs immediately and synchronously on the current SAP system