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



Includes:

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:

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.

Syntax's:

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

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

Syntax:

FUNCTION <function module>.
 <Statements>.
ENDFUNCTION.

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.