Skip to main content

Module 7: Modularization Techniques

Modularization means breaking large programs into smaller, reusable, and maintainable units.
Good modularization improves readability, testing, reuse, and performance.


1. Why Modularization?

Without modularization:

  • Programs become large and unreadable
  • Debugging becomes difficult
  • Code reuse is poor
  • Changes introduce bugs easily
Modern ABAP Philosophy

Modern ABAP strongly prefers object-oriented modularization (classes & methods). Procedural modularization still exists mainly for legacy code.


2. Includes

What is an Include?

An include is a reusable source code block inserted into a program at compile time.

INCLUDE zmy_include.

Typical Uses

  • Declarations

  • Constants

  • Type definitions

  • Common logic (legacy)

Legacy Practice

Using includes for business logic is considered obsolete in modern ABAP.

Modern Recommendation (7.5+)

Use classes and interfaces instead of includes for logic reuse.

3. Subroutines (FORM routines)

What is a Subroutine?

A FORM is a procedural modularization unit used in classic ABAP reports.

FORM calculate_total USING iv_qty TYPE i
iv_price TYPE p
CHANGING cv_total TYPE p.
cv_total = iv_qty * iv_price.
ENDFORM.

Call:

PERFORM calculate_total
USING lv_qty lv_price
CHANGING lv_total.

Characteristics

  • Procedural

  • No exception handling

  • No encapsulation

  • Global data access possible

Legacy Only

FORM routines should not be used in new developments. They exist mainly for maintenance of old reports.

4. Function Modules

What is a Function Module?

A Function Module (FM) is a reusable procedure stored in a Function Group.

CALL FUNCTION 'Z_CALCULATE_TOTAL'
EXPORTING
iv_qty = lv_qty
iv_price = lv_price
IMPORTING
ev_total = lv_total.

Key Features

  • Can be remote-enabled (RFC)

  • Supports exceptions

  • Widely used in classic SAP

  • Central to BAPIs

Real-World Usage

Function Modules are still heavily used for:

  • RFCs

  • BAPIs

  • Integration scenarios

Limitations of Function Modules

  • Procedural, not OO

  • Global data via function groups

  • Harder to unit test

  • Poor encapsulation

Modern Recommendation (7.5+)

For new developments:

  • Use classes and methods

  • Wrap existing FMs inside OO layers if required

Example: Method-Based Modularization

CLASS zcl_calculator DEFINITION.
PUBLIC SECTION.
METHODS calculate_total
IMPORTING iv_qty TYPE i
iv_price TYPE p
RETURNING VALUE(rv_total) TYPE p.
ENDCLASS.

CLASS zcl_calculator IMPLEMENTATION.
METHOD calculate_total.
rv_total = iv_qty * iv_price.
ENDMETHOD.
ENDCLASS.

Usage:

DATA(lv_total) = NEW zcl_calculator( )->calculate_total(
iv_qty = 10
iv_price = 50 ).
Why This Is Best
  • Encapsulation

  • Testability

  • Reusability

  • Clean ABAP compliant

6. Global vs Local Data

6.1 Global Data

Defined outside methods or forms.

DATA gv_total TYPE p.

Problems with Global Data

  • Side effects

  • Hard to debug

  • Not thread-safe

  • Poor testability

Avoid Global Data

Global data is a major source of bugs in large ABAP systems.

6.2 Local Data (Preferred)

Defined inside methods, forms, or blocks.

METHOD calculate.
DATA(lv_sum) = 10 + 20.
ENDMETHOD.
Modern ABAP Rule

Always prefer local data + parameters over global variables.

7. Comparison of Modularization Techniques

TechniqueStatusUsage Recommendation
INCLUDELegacyOnly for declarations
FORMLegacyAvoid in new code
Function ModuleSemi-ModernUse for RFC / BAPI
Class & MethodModernPreferred approach

8. Common Beginner Mistakes

Avoid These
  • Writing logic directly in reports

  • Overusing global data

  • Creating new FORM routines

  • Calling function modules instead of methods

  • Mixing procedural and OO styles randomly

  1. Summary
  • Modularization is essential for maintainable ABAP

  • Includes and FORM routines are legacy

  • Function Modules are still relevant for integration

  • Classes and methods are the modern standard

  • Local data improves reliability and testability

10. Practice Exercises

  • Convert a FORM routine into a method.

  • Wrap a function module call inside a class.

  • Refactor global variables into method parameters.

  • Identify legacy modularization in an existing program.

11. What’s Next?

➡️ Module 8: Selection Screens & Reports

Learning Tip

Interviewers love candidates who can identify legacy code and modernize it.