Classes
Classes bring object-oriented programming to ABAP. Modern ABAP is object-oriented, code is organised into classes with attributes and methods, and understanding OO ABAP is essential for writing clean, reusable, testable code.
Learn encapsulation (public/private sections), instantiation (NEW), inheritance and interfaces, and static vs instance members.
- OO ABAP replaces sprawling procedural programs with encapsulated classes: data (attributes) and behaviour (methods) bundled…
- Local classes: defined inside a program (DEFINITION/IMPLEMENTATION).
- Global classes: created in class builder (SE24) or ADT, reusable across the system.
- Watch out: Writing procedural code where OO would be cleaner/reusable.
Why object-oriented ABAP
OO ABAP replaces sprawling procedural programs with encapsulated classes: data (attributes) and behaviour (methods) bundled together, with clear interfaces and reuse through inheritance and interfaces. SAP’s modern frameworks (RAP, many APIs) are OO, and unit testing (ABAP Unit) works naturally with classes.
Local vs global classes
- Local classes: defined inside a program (DEFINITION/IMPLEMENTATION).
- Global classes: created in class builder (SE24) or ADT, reusable across the system.
A simple class
CLASS lcl_calculator DEFINITION.
PUBLIC SECTION.
METHODS add IMPORTING iv_a TYPE i iv_b TYPE i
RETURNING VALUE(rv_sum) TYPE i.
ENDCLASS.
CLASS lcl_calculator IMPLEMENTATION.
METHOD add.
rv_sum = iv_a + iv_b.
ENDMETHOD.
ENDCLASS.
DATA(lo_calc) = NEW lcl_calculator( ).
DATA(lv_result) = lo_calc->add( iv_a = 2 iv_b = 3 ).Key OO concepts
Learn encapsulation (public/private sections), instantiation (NEW), inheritance and interfaces, and static vs instance members. These enable clean, reusable designs and are expected in modern SAP development.
Common pitfalls
- Writing procedural code where OO would be cleaner/reusable.
- Exposing everything public, breaking encapsulation.
- Ignoring ABAP Unit testing that OO enables.