0% found this document useful (0 votes)
20 views27 pages

Modularization Techniques

Uploaded by

Laksh Mhr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views27 pages

Modularization Techniques

Uploaded by

Laksh Mhr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

MODULARIZATION TECHNIQUES

Modularization techniques are used to divide the business processing logic into reusable block of
statements. This is two steps procedure.

1. Define the reusable block,

2. Calling the reusable block.

There are 2 types of modularization techniques.

1. Source code modularizing technique: Include and Macros

2. Functionality modularizing technique: Subroutine and Function module

In real time, every program must be divided into modules.

In ABAP, Modularization is implemented using following techniques.

 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.

Place Holders: &1 to &9.

Call a macros by its name.


Before macros calling statement, the macro must define in the program.

Call: macros within macros, a macros cannot call itself.

Macro at debugging session.

Example:
*&---------------------------------------------------------------------*
*& Report ZMODULARIZATION
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMODULARIZATION.

DATA: NUM1 TYPE I,


NUM2 TYPE I,
RESULT TYPE I.

DEFINE MOD1.
NUM1 = 10.
NUM2 = 15.
RESULT = NUM1 + NUM2.

END-OF-DEFINITION.

*MOD1.
WRITE: RESULT.

With place holders:

DATA: NUM1 TYPE I,


NUM2 TYPE I,
RESULT TYPE I.

DEFINE MOD1.
NUM1 = &1.
NUM2 = &2.
RESULT = NUM1 + NUM2.

END-OF-DEFINITION.
MOD1 5 15.
WRITE: RESULT.

2. Include program

It contains set of reusable statements & cannot be executed.

It should be inserted in the main program, or executable program

Include programs are used to improve the readability of the 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.

Syntax: INCLUDE<Include Program Name>

Steps to create INCLUDE program:

Execute SE38.

Provide the include program name.

Click on create.
Provide title.

Select the type is “Include program”.

Click on save, give package and continue.


Save in local objects.
SOURCE CODE:
*&---------------------------------------------------------------------*
*& Include ZMODULIZATION_P1
*&---------------------------------------------------------------------*

TYPES: BEGIN OF TY_SINFO,


SNUM TYPE N3,
SNAME TYPE CHAR10,
SCLASS TYPE CHAR6,
SFREE TYPE I,
END OF TY_SINFO.

DATA: GT_SINFO TYPE TABLE OF TY_SINFO,


GS_SINFO TYPE TY_SINFO.

SAVE AND ACTIVATE.


INCLUDE PROGRAM 2.

Give program name.

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.

SAVE AND ACTIVATE.


CREATE MAIN PROGRAM
SOURCE CODE:
Output:
3. Function module

➢ A Function module is a sub program which contains a piece of abap


code which is used for specific functionality or a task.
➢ Function modules contains importing and exporting parameters.
➢ Function modules also contains Exceptions to raise Error messages.
➢ Function modules can be tested independently.
➢ Function modules can be debugged independently.
➢ Function modules are mainly used for global modularization i.e., once a
function module is created it can be used by multiple programs
throughout SAP.
FUNCTION GROUP:
➢ It is a Group or container of function modules.
➢ Whenever we create a function module, it must be saved under a
group called as function group.
➢ Different Function modules in a function group can share global data.
(TOP include program)
➢ There are two ways to create a function group.
1. From Tcode SE80
2. From Tcode SE37 click on Menu Go to Function groupscreate
group

STEPS TO CREATE FUNCTION GROUP:

➢ Go to SE80. Select Function group. Give the function group name


as ZSB_FUNCTION_GROUP.

➢ 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.

➢ Always the function group should be activated immediately.

➢ 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.

➢ Give function group name (ZSB_FUNCTION_GROUP) and provide


short text. Click on save.

➢ A warning pop-up will come. Click on continue.

➢ Our Function Module is created.


COMPONENTS OF FUNCTION MODULE:
Function module consists of following components.
➢ ATTTIBUTES:

➢ 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:

➢ Give input parameter value


➢ Click on “Display output list of Function module:
2. Subroutines

 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

1. Define: FORM & ENDFORM.

2. FERFORM.

Types of Sub Routines:

There are two types of Sub routines.

1. Local Sub Routines


2. Global Sub Routines

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.

DATA: NUM1 TYPE I,


NUM2 TYPE I,
RESULT TYPE I.

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:

You might also like