Modularization Techniques
Modularization Techniques
Modularization techniques are used to divide the business processing logic into reusable block of
statements. This is two steps procedure.
Macros
Include Programs
Function Modules
Subroutines
1. Macros:
Macros are reusable code blocks that can be defined once and called multiple times within a
program. They are similar to functions or subroutines in other programming languages but are
processed differently by the ABAP compiler.
If you need to use macros one or two times in program then only use it otherwise go with other options.
Syntax: Define M1
..
End-of-definition.
Example:
*&---------------------------------------------------------------------*
*& Report ZMODULARIZATION
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMODULARIZATION.
DEFINE MOD1.
NUM1 = 10.
NUM2 = 15.
RESULT = NUM1 + NUM2.
END-OF-DEFINITION.
*MOD1.
WRITE: RESULT.
DEFINE MOD1.
NUM1 = &1.
NUM2 = &2.
RESULT = NUM1 + NUM2.
END-OF-DEFINITION.
MOD1 5 15.
WRITE: RESULT.
2. Include program
We can’t execute an include independently where as the same include program can be include to any
number of executable programs.
In the real time include programs are used to maintain the all declarations of the program.
Execute SE38.
Click on create.
Provide title.
Click on create
SOURCE CODE:
*&---------------------------------------------------------------------*
*& Include ZMODULIZATION_P2
*&---------------------------------------------------------------------*
gs_sinfo-snum = '1'.
gs_sinfo-sname = 'karthik'.
gs_sinfo-sclass = 'ABAP'.
gs_sinfo-scity = 'Banglore'.
gs_sinfo-sfee = '15000'.
APPEND gs_sinfo TO gt_sinfo.
CLEAR gs_sinfo.
gs_sinfo-snum = '2'.
gs_sinfo-sname = 'Sairam'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
APPEND gs_sinfo TO gt_sinfo.
CLEAR gs_sinfo.
gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.
CLEAR gs_sinfo.
gs_sinfo-snum = '4'.
gs_sinfo-sname = 'Harish'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '18000'.
COLLECT gs_sinfo INTO gt_sinfo.
CLEAR gs_sinfo.
gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.
CLEAR gs_sinfo.
gs_sinfo-snum = '5'.
gs_sinfo-sname = ' '.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.
CLEAR gs_sinfo.
gs_sinfo-snum = '6'.
gs_sinfo-sname = 'Rahul'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 1.
CLEAR gs_sinfo.
gs_sinfo-snum = '7'.
gs_sinfo-sname = 'vishwa'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'chennai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 6.
CLEAR gs_sinfo.
gs_sinfo-snum = '8'.
gs_sinfo-sname = 'mahesh'.
gs_sinfo-sclass = ''.
gs_sinfo-scity = 'mumbai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 2.
CLEAR gs_sinfo-sclass.
gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.
gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.
gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.
➢ Press enter. Click on ‘yes’ button. Provide short text. Function Group
will be created.
➢ Whenever a function Group is created, by default a main program and
two include programs will be created.
➢ Now right click on the function group and activate entire group.
➢ To display and modify function group double click on function
group object name. (ZSB_FUNCTION_GROUP)
➢ Now go to SE37 Transaction code. Give function module
name (ZSB_FUNCTION MODULE) and click on create.
➢ IMPORT:
Input to a Function module is called Importing parameter.
➢ EXPORT:
Output from a function module is called as exporting
➢ CHANGING:
A variable/work area which acts as Imports/ Export are called as
changing parameters
➢ TABLES:
Internal tables as Input & output are called as table parameters
➢ EXCEPTIONS:
Exceptions are used to catch certain type of errors
➢ SOURSE CODE:
Contain the ABAP code for a FMOD.
➢ OUTPUT:
Subroutines contains piece of ABAP code which are mainly used for
readability and reusability.
These are also used for local modularization.
Subroutines are procedures that we can define in any ABAP program & calling from
the same or some other ABAP program.
Procedure is the collection of statements.
SYNTAX: The Syntax contains two steps
2. FERFORM.
Local sub routines: If Sub routine definition and implementation are available in same program then it is
called as local sub routines. i.e., if PERFORM And FORM…… END FORM, are available in same program then
it is called as local sub routines.
Global sub routines: If sub routines definition is available in one program and sub routine implementation
is available in another program then it is called as global Subroutines (or) external sub routines.
EXAMPLE:
*&---------------------------------------------------------------------*
*& Report ZMODULARIZATION
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMODULARIZATION.
DEFINE MOD1.
NUM1 = &1.
NUM2 = &2.
RESULT = NUM1 + NUM2.
END-OF-DEFINITION.
MOD1 5 15.
PERFORM RESULT.
FORM RESULT.
WRITE: 'Result is = ', result.
ENDFORM.
START-OF-SELECTION.
mod1 10 50.
PERFORM result.
skip.
mod1 50 50.
PERFORM result.
Output: