IT CanvassTalk to an advisor
SAP ABAP development · LessonBy , SAP Solution Architect · Published · SAP S/4HANA 2023 · all levels

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.

Quick answer

Learn encapsulation (public/private sections), instantiation (NEW), inheritance and interfaces, and static vs instance members.

Key takeaways
  • 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.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
Which statement is true of Classes?

Frequently asked questions

What does the term Classes refer to in SAP?
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.
What is the practical takeaway on Classes?
Learn encapsulation (public/private sections), instantiation (NEW), inheritance and interfaces, and static vs instance members.
What is worth remembering about Classes in practice?
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.
What tends to go wrong with Classes?
Writing procedural code where OO would be cleaner/reusable. Exposing everything public, breaking encapsulation. Ignoring ABAP Unit testing that OO enables.
Already working on SAP and stuck on a live ticket?Get an expert SAP developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support