ABAP Modularization

ABAP Modularization: Forms, Function Modules & Classes (2026 Guide) | ABAP Zero to Hero
ABAP Zero to Hero

Chapter 08  ·  Core Classic ABAP

ABAP Modularization

Forms, Function Modules, and Classes — how to write code that stays readable, reusable, and testable at scale.

Chapter 8 of 20 18 min read Part 2: Core ABAP 8 Interview Q&A

You have written a lot of code in Chapters 3–7. Loops, internal tables, SELECT statements, ALVs. But look at your programs — they are probably 200+ lines of code all sitting in one block.

That works for small exercises. It fails in real projects. When a program is 2,000 lines long, finding bugs takes hours. Reusing logic in another program means copy-paste. Testing one piece means testing everything.

This chapter fixes that. You will learn ABAP modularization — the art of breaking code into small, reusable, testable pieces. There are three main tools: FORMs, Function Modules, and Classes.

The golden rule If a piece of logic could be reused, or could be tested alone, or makes your program hard to read — it belongs in its own unit. Modularize early, not later.

🎯 What You Will Learn in This Chapter

  • Why modularization matters in real ABAP projects
  • How to use FORM / PERFORM subroutines with USING and CHANGING parameters
  • How to create and call Function Modules in SE37 and Function Groups
  • How to write Object-Oriented ABAP classes with methods, attributes, and constructors
  • The difference between static and instance methods
  • When to use each approach — and which one modern ABAP prefers

📘 Why Modularization Matters

Imagine a real SAP project: 500+ custom programs, 200 function modules, and 50 team members touching the same codebase. Without modularization, this becomes chaos.

ProblemWithout ModularizationWith Modularization
Readability2,000-line programs no one wants to touchSmall, focused, easily understood units
ReusabilityCopy-paste everywhere; bugs multiplyCall the same FORM/FM/Class from anywhere
TestabilityTest the whole program or nothingTest each unit in isolation
MaintenanceFix one bug, break three othersFix in one place, all callers get the fix
TeamworkEveryone edits one file; merge conflictsEach person owns their own units
Rule of thumb If you cannot describe what a code block does in one sentence, it should be a FORM, a Function Module, or a Method.

🧩 Method 1: Subroutines (FORM / PERFORM)

A FORM is a local subroutine that lives inside a single ABAP program. You define it once and call it with PERFORM. It cannot be called from other programs — that is its limitation and its simplicity .

Basic syntax

FORM greet_user USING iv_name TYPE string.
  WRITE: / 'Hello,', iv_name.
ENDFORM.

START-OF-SELECTION.
  PERFORM greet_user USING 'Rohit'.

Parameter types

ParameterMeaningPass Mode
USINGInput-only valuesPass-by-value (a copy is passed)
CHANGINGValues returned or modifiedPass-by-reference (original is modified)
TABLESInternal tables (obsolete)Pass-by-reference

Example with USING and CHANGING

FORM calculate_tax
  USING    iv_amount TYPE p
  CHANGING cv_tax    TYPE p.

  cv_tax = iv_amount * '0.18'.
ENDFORM.

DATA: lv_amount TYPE p DECIMALS 2 VALUE '1000.00',
      lv_tax    TYPE p DECIMALS 2.

PERFORM calculate_tax USING lv_amount CHANGING lv_tax.
WRITE: / 'Tax:', lv_tax.
Modern view FORMs are considered legacy in ABAP Cloud. They still appear everywhere in classic ABAP codebases — you must know them for maintenance work — but new development should use classes.

📦 Method 2: Function Modules

A Function Module is a global, reusable unit stored in a Function Group. Unlike FORMs, Function Modules can be called from any ABAP program, support RFC (remote calls), and have a formal parameter interface with typing and exceptions .

Key concepts

  • Function Group: A container created in SE80 that holds related Function Modules and shares global data
  • Function Module: Created in SE37, has a name, a parameter interface, and source code
  • Parameters: IMPORTING, EXPORTING, CHANGING, TABLES (deprecated)
  • Exceptions: Can raise errors that the caller handles
  • RFC: Can be flagged as Remote-Enabled for external system calls

Creating a Function Module — Steps

1 Create the Function Group

Go to SE80. Choose Function Group and enter a name like ZFG_MATH. Save with a transport request.

2 Create the Function Module

Right-click the Function Group and choose Create → Function Module. Name it Z_CALCULATE_TAX.

3 Define parameters

Go to the Import tab. Add a parameter IV_AMOUNT of type P (packed decimal). Go to the Export tab. Add EV_TAX of type P.

4 Write the source code
FUNCTION z_calculate_tax.
  ev_tax = iv_amount * '0.18'.
ENDFUNCTION.
5 Call it from any program
DATA: lv_amount TYPE p DECIMALS 2 VALUE '1000.00',
      lv_tax    TYPE p DECIMALS 2.

CALL FUNCTION 'Z_CALCULATE_TAX'
  EXPORTING
    iv_amount = lv_amount
  IMPORTING
    ev_tax    = lv_tax.

WRITE: / 'Tax:', lv_tax.
When to use a Function Module When the logic needs to be called from many programs, or when it needs to be exposed as an RFC endpoint for external systems.

🏛️ Method 3: Object-Oriented ABAP (Classes)

Classes are the modern standard for ABAP development. They are the only modularization technique allowed in ABAP Cloud, and they are what RAP and CDS development rely on .

The two parts of a class

PartWhat it contains
DefinitionClass name, visibility sections (PUBLIC/PROTECTED/PRIVATE), attributes, method signatures
ImplementationThe actual code inside each method

Attributes and Methods

  • Attributes: Variables that belong to the class (static or instance)
  • Methods: Functions that belong to the class (static or instance)
  • Static: Belongs to the class itself. Called directly with class_name=>method_name( )
  • Instance: Belongs to a specific object created with CREATE OBJECT

Complete example — a Tax Calculator class

CLASS zcl_tax_calculator DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.
    METHODS:
      constructor IMPORTING iv_rate TYPE p,
      calculate   IMPORTING iv_amount TYPE p
                  RETURNING VALUE(rv_tax) TYPE p.

  PRIVATE SECTION.
    DATA mv_rate TYPE p.
ENDCLASS.

CLASS zcl_tax_calculator IMPLEMENTATION.
  METHOD constructor.
    mv_rate = iv_rate.
  ENDMETHOD.

  METHOD calculate.
    rv_tax = iv_amount * mv_rate.
  ENDMETHOD.
ENDCLASS.

" Using the class
DATA: lo_calc TYPE REF TO zcl_tax_calculator,
      lv_tax  TYPE p DECIMALS 2.

CREATE OBJECT lo_calc EXPORTING iv_rate = '0.18'.
lv_tax = lo_calc->calculate( iv_amount = '1000.00' ).
WRITE: / 'Tax:', lv_tax.
Why classes win Encapsulation (private attributes), inheritance (reuse through subclassing), and polymorphism (methods that behave differently per subclass) — none of which FORMs or Function Modules offer.

Static vs Instance — quick comparison

AspectStatic MethodInstance Method
Call syntaxzcl_class=>method( )lo_obj->method( )
Needs instance?NoYes — must call CREATE OBJECT first
Access to instance attributesNoYes
Access to static attributesYesYes
Typical useUtility functions (e.g., date math)Business objects (e.g., an Invoice)

🔧 Constructors — Automatic Setup

A constructor is a special method that runs automatically. ABAP has two:

TypeMethod NameWhen It Runs
Instance ConstructorconstructorEach time CREATE OBJECT is executed
Static Constructorclass_constructorFirst time the class is accessed (only once)

Constructors have no return value and are called automatically — you never call them yourself.

When to use each

  • constructor — to set up instance attributes when an object is created
  • class_constructor — to load static data (buffers, config) once for the whole class

⚖️ Forms vs Function Modules vs Classes

FeatureFORMFunction ModuleClass
ScopeLocal (one program)Global (all programs)Global (all programs)
Reusable?NoYesYes
Object-Oriented?NoNoYes
EncapsulationNoLimitedYes
InheritanceNoNoYes
RFC-capableNoYesYes (with interface)
Cloud-readyNoNoYes
Modern recommendationLegacyLegacy (except RFC)✅ Standard
What to use in 2026 Learn all three — you will see FORMs and Function Modules in existing code for years. But write new code as classes. ABAP Cloud, RAP, and CDS all assume object-oriented design.

📝 Chapter Summary

  • Modularization breaks large programs into small, reusable, testable units.
  • FORM/PERFORM — local subroutines, using USING and CHANGING parameters. Legacy but common.
  • Function Modules — global units in a Function Group, created in SE37, support RFC. Used for integration.
  • Classes — the modern standard. Support encapsulation, inheritance, polymorphism.
  • Static methods belong to the class; instance methods need CREATE OBJECT.
  • Constructors run automatically — constructor on instantiation, class_constructor once when the class is first used.
  • Write new code as classes. Read old code for FORMs and Function Modules.

🎤 Interview Questions & Answers

Modularization is a favorite interview topic — especially “FORM vs Function Module vs Class” comparisons. Know these cold.

1 What is modularization in ABAP?

Modularization in ABAP is the practice of breaking a large program into smaller, reusable, and independently testable units. This improves readability, reusability, and maintainability of code. ABAP supports modularization through subroutines (FORM/PERFORM), function modules, and object-oriented classes.

2 What is the difference between a FORM and a Function Module?

A FORM is a local subroutine that exists only within a single ABAP program and cannot be called from other programs. A Function Module is a global, reusable unit stored in a Function Group that can be called from any ABAP program, and can support remote calls (RFC), updates, and exceptions.

3 What is a Function Group in ABAP?

A Function Group is a container that holds multiple function modules that share global data and subroutines. All function modules in a group can access the shared global data of that group. Function Groups are created and managed in transaction SE80 and stored as a special ABAP program.

4 What are the parameter types of a Function Module?

Function Modules support four parameter types:

  • IMPORTING — values passed into the function module
  • EXPORTING — values returned to the caller
  • CHANGING — values passed in and modified
  • TABLES — for passing internal tables (now deprecated in modern ABAP)

Each parameter must be typed and marked as pass-by-value or pass-by-reference.

5 What is the difference between a Class and a Function Module?

A Class is an object-oriented blueprint that supports inheritance, polymorphism, and encapsulation through methods and attributes. A Function Module is a procedural, functional unit without object-oriented features. Classes are the modern standard in ABAP Cloud, while Function Modules are still used in classic ABAP for RFC and legacy integration.

6 What is the difference between a static and an instance method?

A static method belongs to the class itself and can be called without creating an instance. It cannot access instance attributes. An instance method belongs to a specific instance of the class, can access both static and instance attributes, and requires the class to be instantiated with CREATE OBJECT before it can be called.

7 What is a constructor in ABAP?

A constructor is a special method that runs automatically when a class is instantiated. ABAP has two types: the instance constructor (METHOD constructor) which runs when CREATE OBJECT is executed, and the static constructor (METHOD class_constructor) which runs the first time the class is accessed. Constructors do not have a return type.

8 What is the difference between USING and CHANGING in FORM parameters?

USING parameters are pass-by-value — the FORM receives a copy, and changes made inside the FORM do not affect the caller’s variable. CHANGING parameters are pass-by-reference — the FORM operates on the original variable, and changes are returned to the caller. You use USING for input-only data and CHANGING for output or modified data.

🛠 Practice Task for This Chapter

Build a small modularized program that combines all three techniques. This is a real interview-level exercise.

  1. FORM version: Create a report with a FORM that takes an amount (USING) and returns the tax (CHANGING). Call it twice with different amounts.
  2. Function Module version: Create a Function Group ZFG_MATH with a Function Module Z_CALCULATE_TAX. Call it from the same report.
  3. Class version: Create a class ZCL_TAX_CALCULATOR with an instance constructor taking a rate, and a method calculate returning the tax. Instantiate it with CREATE OBJECT and call it.
  4. Compare the three approaches. Which one is the cleanest to reuse?
Why this matters Interviews almost always include: “Show me how you’d modularize this logic.” Being able to write all three variants proves you understand the history and the modern direction of ABAP.
🎯 Chapter 8 Challenge

Test: Kon Banega Crorepati?

5 questions. ₹1 Crore. Prove you understood modularization. No pressure — restart anytime.

₹1,000 ₹10,000 ₹1,00,000 ₹10,00,000 ₹1 Crore
Question 1 of 5
Score: 0
Q1
🏆
You Did It!
0/5Correct Answers
You won ₹0
➡️ Next Chapter

➡️ Next Chapter

Your code is now modular. In Chapter 9, you will learn ALV Reports — the most common output format in SAP. Every job interview asks about it. Every project uses it.

Chapter 9 ALV Reports — The Most Common Output →
Want to Learn Faster?

Explore Our Instructor-Led SAP & IT Courses

Self-study works. But if you want guided training, real project practice, and placement support — here are the courses we offer. Book a free demo before you decide.

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "ABAP Modularization: Forms, Function Modules & Classes (2026 Guide)",
  "alternativeHeadline": "ABAP Zero to Hero — Chapter 8",
  "description": "Learn ABAP modularization in 2026. Master FORMs, Function Modules, and Object-Oriented Classes with step-by-step examples.",
  "image": "https://www.elearningsolutions.co.in/images/abap-zero-to-hero-chapter-8.jpg",
  "author": {
    "@type": "Person",
    "name": "eLearning Solutions",
    "url": "https://www.elearningsolutions.co.in/about/"
  },
  "publisher": {
    "@type": "Organization",
    "name": "eLearning Solutions",
    "url": "https://www.elearningsolutions.co.in/",
    "logo": { "@type": "ImageObject", "url": "https://www.elearningsolutions.co.in/images/logo.png", "width": 600, "height": 60 }
  },
  "datePublished": "2026-02-26",
  "dateModified": "2026-02-26",
  "mainEntityOfPage": { "@type": "WebPage", "@id": "https://www.elearningsolutions.co.in/abap-zero-to-hero/chapter-08-modularization" },
  "articleSection": "Core Classic ABAP",
  "keywords": "ABAP modularization, ABAP FORM, ABAP Function Module, ABAP Class, Object Oriented ABAP",
  "inLanguage": "en",
  "wordCount": 3200,
  "timeRequired": "PT18M",
  "isPartOf": { "@type": "CreativeWorkSeries", "name": "ABAP Zero to Hero", "url": "https://www.elearningsolutions.co.in/abap-zero-to-hero/" }
}
</script>

WhatsApp WhatsApp us
Call Now Button