Modularization
ABAP Developmentintermediate

FORM vs Method vs Function Module

When to pick each and why FORMs are legacy.

Explanation

FORM subroutines are procedural, share the program's global state and cannot be unit-tested cleanly โ€” reserved for legacy maintenance. Methods (in local or global classes) support encapsulation, exceptions and ABAP Unit tests. Function modules are still required for RFC/BAPI/tRFC/qRFC and update tasks. New code should default to classes.

Code example

ABAP Code
CLASS lcl_order DEFINITION.  PUBLIC SECTION.    METHODS confirm IMPORTING iv_id TYPE vbeln_va                    RAISING zcx_order.ENDCLASS.

Real project scenario

Rewriting order-confirmation FORMs as service class methods enabled ABAP Unit tests and cut regression bugs.

Common mistakes

Creating new FORMs; using FMs for pure in-system logic; putting business logic in includes.

Best practices

Use classes for new code; keep FMs only for RFC and update-task boundaries.

Interview angle

Why is dependency injection easier with classes?