Modularization Part 6: Methods and Local Classes
Preview · a free account unlocks the full lesson
Write your first classes for modularization: class definition and implementation, instance vs static methods, attributes, constructors, calling methods, and how a class replaces FORM-based report logic.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Parts 1 through 5 covered classic units like FORMs. Classes are the modern way to modularize code, and this part is the practical introduction — the OOP ABAP topic goes deeper into inheritance, interfaces and polymorphism later on.
A class has a DEFINITION (what) and an IMPLEMENTATION (how). For example: CLASS lcl_flight_service DEFINITION. opens with a PUBLIC SECTION declaring METHODS constructor IMPORTING iv_carrid TYPE s_carr_id. and METHODS get_flights RETURNING VALUE(rt_flights) TYPE ty_flights., followed by a PRIVATE SECTION with DATA mv_carrid TYPE s_carr_id., before ENDCLASS. The matching CLASS lcl_flight_service IMPLEMENTATION. then fills in METHOD constructor. mv_carrid = iv_carrid. ENDMETHOD. and METHOD get_flights. SELECT … WHERE carrid = mv_carrid. ENDMETHOD., closed with ENDCLASS.
There's a real distinction between instance and static members. An instance method belongs to an object, and each object carries its own attributes — mv_carrid above is a good example — created with CREATE OBJECT lo_service EXPORTING iv_carrid = 'LH'. or the more compact NEW lcl_flight_service( 'LH' ).
A static method, declared with CLASS-METHODS, or static data, declared with CLASS-DATA, exists once per class rather than once per object, which suits stateless helpers like conversions or calculations well. Instance methods make sense specifically when the object holds its own state, or needs to be swappable for a test double.
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
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.