SAP technical topicObjectObject-Oriented ABAP: Classes, Interfaces and InheritanceModuleABAP

Object-Oriented ABAP: Classes, Interfaces and Inheritance

Object-oriented ABAP structures behavior around classes and objects, uses interfaces to define contracts independent of implementations, and supports inheritance for genuine 'is-a' specialization. In maintainable SAP code, interfaces and composition are usually more important than deep inheritance trees because they make dependencies replaceable for tests and allow legacy services, BAPIs, database readers, and external clients to sit behind stable contracts.

Practitioner guide to Object-Oriented ABAP: Classes, Interfaces and Inheritance: what it means, when to use it, how it fits SAP architecture, a concrete support/development example, decision rules, production pitfalls, S/4HANA implications, ownership, and related technical objects.

Reviewed by an ERPClimb SAP consultant on 20 Sept 2026· 754 words

What it is

An ABAP class contains attributes, methods, events, and type definitions and can create object instances or expose static behavior. Interfaces define method/event/type contracts without tying callers to one implementation. A class can implement multiple interfaces but inherit from one superclass. Visibility sections—PUBLIC, PROTECTED, PRIVATE—control access. Abstract/final classes and methods constrain specialization. The design benefit comes from dependency direction: callers program to a contract while implementations encapsulate technical details such as persistence, RFC, API calls, or application logic.

When to use it

Use OO ABAP for services with state, replaceable dependencies, domain logic, testability, RAP behavior implementations, API wrappers, and reusable technical components. Use interfaces when multiple implementations or test doubles are plausible, or when you want to isolate unreleased/legacy dependencies behind one boundary. Use inheritance only when the subtype truly satisfies the superclass contract; prefer composition for assembling behavior from services. A procedural report can still contain straightforward local logic without forcing every helper into a class hierarchy.

How it fits the stack

Modern ABAP frameworks are heavily object-oriented: RAP behavior pools, BAdIs, test-double frameworks, HTTP clients, ADT tooling, exceptions, and many released APIs are class/interface based. OO design also enables dependency injection for ABAP Unit. Legacy function modules and BAPIs can be wrapped behind classes, allowing callers to depend on a clean interface while the wrapper handles RETURN tables, commits, or release-specific quirks.

A worked example

A pricing-check report directly calls a custom function module, reads customizing tables, and sends email. Unit testing becomes almost impossible. The refactored design defines interfaces for pricing data, notification, and clock/date services. Production classes implement those interfaces using the standard APIs; the business service depends only on the interfaces. Tests inject doubles with known responses. No inheritance is required—the design improves because dependencies are explicit and replaceable.

How to choose

  • Create an interface when callers need a stable contract independent of one implementation.
  • Use instance classes for behavior with dependencies/state; use static helpers sparingly for truly stateless utilities.
  • Prefer composition/dependency injection to deep inheritance trees.
  • Use FINAL when extension is not part of the supported design; use ABSTRACT only when subclasses are intentionally required.
  • Keep database/RFC/UI details outside domain methods when that separation improves testability.

Common pitfalls

  • Creating 'god classes' that combine UI, database, RFC, business rules, commits, and logging.
  • Using inheritance only to reuse code even when the subtype relationship is false.
  • Making every method static, which hides dependencies and makes tests harder.
  • Exposing implementation classes where an interface would protect callers from change.
  • Wrapping a legacy API but still leaking all of its technical structures through the new interface.

ECC, S/4HANA and clean core

OO ABAP is foundational to S/4HANA, RAP, ABAP Cloud, and released APIs. Cloud-ready development increases the value of interfaces because implementations may need to swap from classic function modules/table reads to released CDS/classes or remote APIs. The language remains familiar, but clean-core boundaries make dependency design more important.

Whose problem this is

ABAP developers and solution architects own class boundaries and contracts. Reviewers should focus on dependency direction, testability, and whether inheritance expresses a real semantic relationship. Functional teams contribute domain rules but should not dictate technical coupling to specific tables or function modules.

Related SAP objects

Reviewed pages this object connects to in the ERPClimb knowledge graph.

Source: ERPClimb — https://erpclimb.com/sap-technical-topics/object-oriented-abap-classes-interfaces-inheritanceERPClimb is an independent platform and is not affiliated with SAP SE. Reference pages are written and reviewed by SAP consultants for learning and troubleshooting.