Modularization Part 4: Function Modules and Function Groups
Preview · a free account unlocks the full lesson
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 sectionsHide sections
Visual overview
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.
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
Interview questions on this topic
Related SAP topics
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.