ERPClimb logoERPClimb
Modularization
ABAP Developmentbeginner 8 min read

Modularization Part 1: Why and How to Split ABAP Programs

Lessons are open to try during our launch period. Some advanced content may move to Pro later. AI practice limits apply separately.

Key takeaway

Understand ABAP modularization units — includes, FORM routines, function modules, methods and classes — what each is for, and how to structure a classic report into clear, reusable pieces.

In this lessonShow sections

Visual overview

Modularization Part 1: Why and How to Split ABAP Programs — learning sheetIn one line: Understand ABAP modularization units — includes, FORM routines, function modules, methods and classes — what each is for, and how to structure a classic report into clear, reusable pieces.ERPClimb.com / ABAP / LESSON 1/10 / LEARNING SHEETModularization Part 1: Why and How to Split ABAP Programs1 · IN ONE LINEUnderstand ABAP modularization units — includes, FORM routines, function modules, methodsand classes — what each is for, and how to structure a classic report into clear, reusablepieces.2 · KEY IDEAS EXPLAINEDWhy ModularizeReadability: a 3,000-line START-OF-SELECTION isimpossible to understand.Reuse: the same logic (e.g. "calculate freeseats") used in several places.Source Code UnitsInclude programs (INCLUDE zflight_top.) — split aprogram into files: TOP (declarations), SEL(selection screen), F01 (FORMs), classes. No…Macros (DEFINE … END-OF-DEFINITION) — textreplacement; hard to debug; avoid.Processing UnitsFORM routines — subroutines inside a program(PERFORM). Obsolete for new code, but everywherein old reports and user exits.Function modules — in function groups; callableacross programs, remote-enabled (RFC/BAPI), updatetasks.A Typical Classic Report StructureZFLIGHT_REPORT with INCLUDE zflight_report_top(global data, types), zflight_report_sel(selection screen), zflight_report_cls (local…3 · DO · AVOIDBest practice!Common mistakeShort event blocks that call units.Methods in local/global classes for new code.Includes only to organize large programs.✕Huge event blocks without modularization.✕Using includes as if they providedencapsulation.✕Macros for logic.4 · IN A REAL PROJECTA support team inherited a 5,000-line interface program written as one long START-OF-SELECTION with globalvariables. Every change took days because nobody could predict side effects, and two consecutive fixes brokeother parts. The team restructured it step by step into includes and a local class with methods per task…Original ERPClimb learning sheet • Verify against your SAP release and edition

Expert visual walkthrough

ABAP DEVELOPMENT ACADEMY · Architecture hierarchyERPClimb.com

Why and How to Split ABAP Programs

Modularization · Chapter-specific technical teaching map

Architecture hierarchy

1Top level

Report event

2Related level

Service layer

3Related level

Reusable routines

4Related level

Test seams

Tutor's chapter takeaway

Understand ABAP modularization units — includes, FORM routines, function modules, methods and classes — what each is for, and how to structure a classic report into clear, reusable pieces.

In a real project

A support team inherited a 5,000-line interface program written as one long START-OF-SELECTION with global variables. Every change took days because nobody could predict side effects, and two consecutive fixes broke other…

Watch out for

• Huge event blocks without modularization. • Using includes as if they provided encapsulation. • Macros for logic. • Passing everything through global variables. • Creating new FORM routines in new development.

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a real project scenario

A support team inherited a 5,000-line interface program written as one long START-OF-SELECTION with global variables. Every change took days because nobody could predict side effects, and two consecutive fixes broke other parts.
The team restructured it step by step into includes and a local class with methods per task (read, validate, map, send, log), passing data via parameters. The next changes were localized to one method each, and ABAP Unit tests covered the mapping logic.

Explanation

Modularization means splitting code into named units with clear inputs and outputs. Source code units, such as includes and macros, only organize the text itself, while processing units — FORMs, function modules, and methods — actually encapsulate logic behind an interface.

In new code, methods inside classes are the standard, though FORMs and function modules still matter a great deal in existing programs, RFC-enabled logic, and update tasks.

This series covers modularization in ten parts: this lesson on why and how to split programs; Part 2 on FORM routines; Part 3 comparing FORM, method, and function module; Part 4 on function modules and function groups; Part 5 on update function modules and IN UPDATE TASK; Part 6 on methods and classes; Part 7 on global versus local classes; Part 8 on parameter passing; Part 9 on reusable service classes; and Part 10 on modularization for unit testing.

A good unit, as a rule of thumb, does one thing, has a meaningful name, and passes data through parameters rather than through global variables.

There are several reasons modularization matters. Readability suffers badly without it — a 3,000-line START-OF-SELECTION is effectively impossible to understand. Reuse becomes possible, since the same logic, say "calculate free seats," can be called from several places instead of being duplicated. Testability improves, since small units with clear parameters can actually be tested in isolation. And change safety improves too, since a change confined to one unit is much less likely to break something else.

Source code units come in two flavors. Include programs, brought in with INCLUDE zflight_top., split a program across files — a TOP include for declarations, a SEL include for the selection screen, an F01 include for FORMs, and so on — but this gives you no real encapsulation, since it's just text being inserted at compile time. Macros, defined with DEFINE ... END-OF-DEFINITION, are pure text replacement, which makes them hard to debug and generally worth avoiding.

Processing units are where actual encapsulation happens. FORM routines are subroutines inside a single program, called with PERFORM; they're obsolete for new code but still everywhere in older reports and user exits. Function modules live inside function groups and can be called across programs, including remotely via RFC or BAPI, and from update tasks. Methods live inside local or global classes and represent the modern standard for new development.

A typical classic report structure looks like ZFLIGHT_REPORT built from INCLUDE zflight_report_top for global data and types, zflight_report_sel for the selection screen, zflight_report_cls for local classes (or an F01 include holding FORMs instead), with START-OF-SELECTION simply calling the main method. SE80 generates this kind of include structure automatically for module pools and function groups.

A few rules of thumb are worth keeping in mind: keep event blocks like START-OF-SELECTION and AT SELECTION-SCREEN short, calling out to proper units instead of containing logic directly; pass data through parameters and keep global data to a minimum; and aim for one unit, one responsibility.

To practice: compare the unstructured and structured versions of the code example — they produce the same output, but their maintainability is worlds apart. With this you should know the different modularization units available and when each one is the right tool.

Code example

ABAP Code
* ===== BEFORE: everything in one event block =====* START-OF-SELECTION.*   SELECT ... (50 lines)  checks ... (80 lines)  WRITE ... (60 lines) * ===== AFTER: structured report (main program) =====REPORT zflight_report. INCLUDE zflight_report_top.     " global types and data (keep small)INCLUDE zflight_report_sel.     " selection screenINCLUDE zflight_report_cls.     " local class with the logic START-OF-SELECTION.  lcl_report=>run( p_carr ).    " event block only calls the logic * ===== Include ZFLIGHT_REPORT_SEL =====* PARAMETERS p_carr TYPE s_carr_id OBLIGATORY. * ===== Include ZFLIGHT_REPORT_CLS =====* CLASS lcl_report DEFINITION.*   PUBLIC SECTION.*     CLASS-METHODS run IMPORTING iv_carr TYPE s_carr_id.*   PRIVATE SECTION.*     CLASS-METHODS read_flights IMPORTING iv_carr TYPE s_carr_id*                                EXPORTING et_flights TYPE ty_flights.*     CLASS-METHODS display IMPORTING it_flights TYPE ty_flights.* ENDCLASS.* CLASS lcl_report IMPLEMENTATION.*   METHOD run.*     DATA lt_flights TYPE ty_flights.*     read_flights( EXPORTING iv_carr = iv_carr IMPORTING et_flights = lt_flights ).*     display( lt_flights ).*   ENDMETHOD.*   METHOD read_flights.*     SELECT carrid connid fldate seatsocc seatsmax FROM sflight*       INTO TABLE et_flights WHERE carrid = iv_carr.*   ENDMETHOD.*   METHOD display.  " ALV or WRITE*   ENDMETHOD.* ENDCLASS. * ===== Classic equivalent you will meet in old programs =====* START-OF-SELECTION.*   PERFORM read_flights USING p_carr CHANGING gt_flights.*   PERFORM display USING gt_flights.

Watch out

Common mistakes

  • Huge event blocks without modularization.
  • Using includes as if they provided encapsulation.
  • Macros for logic.
  • Passing everything through global variables.
  • Creating new FORM routines in new development.

Do this

Best practices

  • Short event blocks that call units.
  • Methods in local/global classes for new code.
  • Includes only to organize large programs.
  • Parameters instead of globals.
  • One responsibility per unit with a descriptive name.

In the interview

Interview angle

Questions: "What modularization techniques exist in ABAP?", "Difference between an include and a FORM?", "What do you use for new code?"
Strong answer: source code units (includes, macros) only organize text; processing units (FORM routines, function modules, methods) encapsulate logic with parameters; new code uses methods in classes, function modules remain for RFC/BAPI/update tasks, FORMs appear in legacy code and exits; keep event blocks short and avoid globals.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

A 6,000-line report is split into TOP, SEL and F01 includes. What has this achieved?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1When would you use INCLUDE programs?

2A 6,000-line SD report with everything in START-OF-SELECTION is hard to change. How do you restructure it into maintainable modules?

Try a related Code Lab

This published exercise covers the same SAP topic. Apply the ideas in a hands-on scenario, then return to review your answers.

Open: Refactor legacy FORM to a testable method →

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.