Chapter 08 · Core Classic ABAP
ABAP Modularization
Forms, Function Modules, and Classes — how to write code that stays readable, reusable, and testable at scale.
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.
🎯 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.
| Problem | Without Modularization | With Modularization |
|---|---|---|
| Readability | 2,000-line programs no one wants to touch | Small, focused, easily understood units |
| Reusability | Copy-paste everywhere; bugs multiply | Call the same FORM/FM/Class from anywhere |
| Testability | Test the whole program or nothing | Test each unit in isolation |
| Maintenance | Fix one bug, break three others | Fix in one place, all callers get the fix |
| Teamwork | Everyone edits one file; merge conflicts | Each person owns their own units |
🧩 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
| Parameter | Meaning | Pass Mode |
|---|---|---|
USING | Input-only values | Pass-by-value (a copy is passed) |
CHANGING | Values returned or modified | Pass-by-reference (original is modified) |
TABLES | Internal 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.
📦 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
SE80that 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
Go to SE80. Choose Function Group and enter a name like ZFG_MATH. Save with a transport request.
Right-click the Function Group and choose Create → Function Module. Name it Z_CALCULATE_TAX.
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.
FUNCTION z_calculate_tax.
ev_tax = iv_amount * '0.18'.
ENDFUNCTION.
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.
🏛️ 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
| Part | What it contains |
|---|---|
| Definition | Class name, visibility sections (PUBLIC/PROTECTED/PRIVATE), attributes, method signatures |
| Implementation | The 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.
Static vs Instance — quick comparison
| Aspect | Static Method | Instance Method |
|---|---|---|
| Call syntax | zcl_class=>method( ) | lo_obj->method( ) |
| Needs instance? | No | Yes — must call CREATE OBJECT first |
| Access to instance attributes | No | Yes |
| Access to static attributes | Yes | Yes |
| Typical use | Utility 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:
| Type | Method Name | When It Runs |
|---|---|---|
| Instance Constructor | constructor | Each time CREATE OBJECT is executed |
| Static Constructor | class_constructor | First 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
| Feature | FORM | Function Module | Class |
|---|---|---|---|
| Scope | Local (one program) | Global (all programs) | Global (all programs) |
| Reusable? | No | Yes | Yes |
| Object-Oriented? | No | No | Yes |
| Encapsulation | No | Limited | Yes |
| Inheritance | No | No | Yes |
| RFC-capable | No | Yes | Yes (with interface) |
| Cloud-ready | No | No | Yes |
| Modern recommendation | Legacy | Legacy (except RFC) | ✅ Standard |
📝 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 —
constructoron instantiation,class_constructoronce 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.
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.
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.
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.
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.
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.
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.
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.
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.
- FORM version: Create a report with a FORM that takes an amount (USING) and returns the tax (CHANGING). Call it twice with different amounts.
- Function Module version: Create a Function Group
ZFG_MATHwith a Function ModuleZ_CALCULATE_TAX. Call it from the same report. - Class version: Create a class
ZCL_TAX_CALCULATORwith an instance constructor taking a rate, and a methodcalculatereturning the tax. Instantiate it withCREATE OBJECTand call it. - Compare the three approaches. Which one is the cleanest to reuse?
Test: Kon Banega Crorepati?
5 questions. ₹1 Crore. Prove you understood modularization. No pressure — restart anytime.
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.
SAP Courses
Technology & Other Courses
<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 us