Modularization in SAP ABAP [ Introduction ]

Modularization is a means by which code is broken down into pieces(modules/blocks) each performing one task. It reduces redundant code, better readability and debugging. Modularization is possible by 3 ways in SAP ABAP:

  • Includes
  • Subroutines
  • Function Modules


It just copies all the code of the included program.
The included program or report is of type I.
Syntax: Include <include_program_name>.


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 algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.


Defining Subroutine:
FORM <subroutinename> [<pass>].
<statements block>.

<Subroutine> = Name of the subroutine
<pass> = Parameters being passed

Calling subroutine:
 PERFORM <subroutine> [<pass>]

<subroutine> = Name of the subroutine
<pass> = Parameters being passed

 The parameters we specify in PERFORM while calling are called Actual parameters and the parameters in FORM are called formal parameters.

Function modules:

They are general purpose subroutines that can be used in ABAP program.
Function Modules are organized into Function Groups: Collections of logically related functions. A Function module always belongs to a Function Group.


FUNCTION <function module>.

Function can be called using Pattern >> Call Function.
A function module can be set remote enabled which will make it accessible outside SAP system also.