OOP ABAP Part 2: Local Classes vs Global Classes
Preview · a free account unlocks the full lesson
Know when to write a local class inside a program and when to create a global class in SE24/ADT — visibility, reuse, where-used lists, transport, test classes and the typical classic report structure with a local class.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 1 used a local class without dwelling on the choice. This part asks: when is local fine, and when does a class need to be global?
Local classes are defined directly in a program's source, often in an include such as ZREPORT_CLS, and they are visible only within that program — they cannot be called from outside it. Local classes live inside one program and are visible only there.
Typical uses include a report's own application class, often named lcl_report with methods like get_data, process and display, event handlers for ALV, and local test classes. Order matters when defining them: a class's DEFINITION must come before it is used, and CLASS lcl_x DEFINITION DEFERRED lets you reference a class that is only declared later in the source.
Global classes, by contrast, are repository objects created in SE24 (either the form-based editor or the source-code editor), SE80 or ADT, and their names follow the ZCL_… convention. Global classes are reusable system-wide, with their own where-used list and their own transport entry. They are stored in a class pool and are visible to all programs, subject to package visibility rules. They can still contain local helper types, local classes and local test classes within their own includes.
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.