ERPClimb logoERPClimb
Modularization
ABAP Developmentbeginner 9 min read

Modularization Part 4: Function Modules and Function Groups

Preview · a free account unlocks the full lesson

Key takeaway

Create and use function modules the classic way: function groups and their includes, the interface (IMPORTING, EXPORTING, CHANGING, TABLES, EXCEPTIONS), calling with CALL FUNCTION, handling sy-subrc, and RFC-enabled modules.

In this lessonShow sections

Visual overview

Modularization Part 4: Function Modules and Function Groups — learning sheetIn one line: Create and use function modules the classic way: function groups and their includes, the interface (IMPORTING, EXPORTING, CHANGING, TABLES, EXCEPTIONS), calling with CALL FUNCTION, handling sy-subrc, and RFC-enabled modules.ERPClimb.com / ABAP / LESSON 5/10 / LEARNING SHEETModularization Part 4: Function Modules and FunctionGroups1 · IN ONE LINECreate and use function modules the classic way: function groups and their includes, theinterface (IMPORTING, EXPORTING, CHANGING, TABLES, EXCEPTIONS), calling with CALL FUNCTION,handling sy-subrc, and RFC-enabled modules.2 · KEY IDEAS EXPLAINEDFunction GroupsCreated in SE80 / SE37 (Goto → Function groups) orADT.Main program SAPLZFLIGHT with includes:LZFLIGHTTOP (global data), LZFLIGHTUXX (functionmodule includes, generated), LZFLIGHTF01…The Interface (SE37 Tabs)Import — inputs; mark optional/default values;pass by value for RFC.Export — outputs.Raising Classic ExceptionsThe caller receives sy-subrc = assigned number.If the caller didn't list the exception (and noOTHERS), a runtime error occurs.CallingCALL FUNCTION 'Z_FLIGHT_GET' EXPORTING iv_carrid =… IMPORTING es_flight = … EXCEPTIONSflight_not_found = 1 OTHERS = 2.3 · DO · AVOIDBest practice!Common mistakeInsert calls with Pattern.List all exceptions plus OTHERS; handlesy-subrc.Use table types instead of TABLES.✕Calling FMs without EXCEPTIONS and OTHERS.✕Not checking sy-subrc after CALL FUNCTION.✕Using TABLES parameters in new FMs.4 · IN A REAL PROJECTA report called a function module without listing its exceptions. When a flight was missing, the FM raisedFLIGHT_NOT_FOUND, and — because the caller had no EXCEPTIONS clause — the job dumped with RAISE_EXCEPTION inthe middle of the night. Adding the EXCEPTIONS block with OTHERS and sy-subrc handling turned the dump into a…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 3 explained when function modules are the right tool; this part shows how to actually build and call one. A function module lives inside a function group, with a main program named SAPL<group>, which holds includes shared across all the function modules in that group, along with the group's own global data.

The interface consists of IMPORTING, EXPORTING, CHANGING, and TABLES parameters — TABLES is obsolete for new code — plus either classic EXCEPTIONS or class-based exceptions. You call one with CALL FUNCTION 'NAME' ... EXCEPTIONS ... and should always check sy-subrc afterward.

One practical tip: use "Pattern" in SE38 or ADT to insert the call with its full interface already filled in, which avoids typos in parameter names.

Function groups are created in SE80, in SE37 via Goto → Function groups, or in ADT. A group like ZFLIGHT has a main program SAPLZFLIGHT, built from includes: LZFLIGHTTOP for global data, LZFLIGHTUXX, which holds the generated function module includes, and LZFLIGHTF01 for FORMs or local classes.

Every function module in the group shares that global data, which is useful for things like buffering but can also create dangerous hidden state if you're not careful. The group gets loaded the first time any of its function modules is called, and then stays loaded for the rest of the internal session.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

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.