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

Modularization Techniques

The document discusses different modularization techniques in ABAP including macros, includes, subroutines, function modules, and methods. The key advantages of modularization are readability, code reusability, and providing structure to code to make it easier to maintain. Each technique allows breaking programs into logical blocks that can be reused in different places.

Uploaded by

chetanp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views

Modularization Techniques

The document discusses different modularization techniques in ABAP including macros, includes, subroutines, function modules, and methods. The key advantages of modularization are readability, code reusability, and providing structure to code to make it easier to maintain. Each technique allows breaking programs into logical blocks that can be reused in different places.

Uploaded by

chetanp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Modularization Techniques

• Modularization involves the organization of programs into modular units, also


known as logical blocks of statements.
• Modularization Techniques are used to avoid repetitive coding
• The advantage of modularization is:
1. Readability.
2. Code reusability.
3. Providing structure to code, easy to maintain
1.Macros
2.Includes
3.Subroutines
4.Function modules
5.Methods
Macros
If you want to reuse the same set of statements more than once in a program, you can
include them in a macro. We can use the Macros after the Macro definition only in the
same program in which it is defined. Macros are used for reusing same calculation in many
places of same program instead of writing the same set of statements for same calculation.

Syntax :
DEFINE <macro>.
<statements>
END-OF-DEFINITION.
We can pass up to 9 placeholders to Macros.
To use a macro, use the following form: <macro> [<&1> <&2> ... <&9>].

Example:
DEFINE print.
write:/ 'Hello', &1, &2.
END-OF-DEFINITION.

WRITE:/ 'Before Using Macro'.


print ‘Nitin' ‘ABAPer'.
Include
• Include programs are global repository objects used to modularize the source
code. They allow you to use the same source code in different programs.
• INCLUDE statement has the same effect as copying the source code of the include
program <program_name> into another program.
• As include program can’t run independently(not executable), it has to be built into
other programs.
• You may also nest include programs(include within Include) but you can't call
themselves.
• To create a program as include , go to SE38, Set the Type of the program as
INCLUDE program
• They can be useful if you have lengthy data declarations that you want to use in
different program Ex. Function Group Top include
• Does not have parameter interface
Subroutines
• Subroutines are procedures that you can define in any ABAP program and also call from any
program.
• Subroutines are normally called internally, that is, they contain sections of code or set of
statements that are used frequently locally.
• If you want a function to be reusable throughout the system, use a function module. (Tcode SE37)
• Nested calls are allowed in subroutines (i.e. PERFORM within a FORM ... ENDFORM ).
• To define local data, use the DATA statement after FORM . Each time you enter the subroutine, the
data is recreated (with an initial value) and released at the end (from the stack).
• Internal
– Subroutine defined in same program being called.
– Can access all the data objects declared in the main ABAP/4 program.
– Data declared in main program is automatically available.
– Calling subroutine PERFORM <subroutine> [<pass>]
• External
– Subroutine defined outside the program being called.
– Need to use the <pass> option or declare data objects in common parts of memory.
– Calling Subroutine PERFORM (<subroutine>) IN PROGRAM (<Program>) [<pass>]
Function Module
• Function Modules are stored in Central library and hence available to Entire system
• Similar functionality Function modules stored under common Function groups
which are containers for function modules. Function Group is 26 characters long
• Function Groups cannot be executed.
• the main program and include programs are generated automatically.
• Function Modules are organized into Function Groups: Collections of logically
related functions. A Function module always belongs to a Function Group.
• Import/Changing/Export parameters.
• Global data Top Include for the function group- Accessible across function
modules in the function group. L<fgrp>TOP
• Source code - L<fgrp>U01
• Main Program - SAPL<fgrp>
• To call a function module, use the CALL FUNCTION statement:
• RFC(Remote Function call ) enables function modules that can be called from non-
sap system
Class & Methods
• Global classes are accessed by all ABAP programs.
• Global classes are defined in the Class Builder (Transaction
SE24) in the ABAP Workbench.
• Local classes are defined within ABAP program.
• Local classes can only use in the program where they are
defined and not available to other program.
• Local classes consist of ABAP source code and should code
in between the CLASS and ENDCLASS
• The system first searches for a local class with the specified
name when a class in an ABAP program. If it does not find
any local classes, then looks for a global class. There is no
difference between using a global class or a local class
apart from visibility.

You might also like