All topics
ABAPIntermediate

OOP ABAP

Master Object-Oriented ABAP with classes, objects, methods, constructors, encapsulation, interfaces, factory methods, testing and S/4HANA-ready design.

Overview

Master Object-Oriented ABAP with classes, objects, methods, constructors, encapsulation, interfaces, factory methods, testing and S/4HANA-ready design.

Lessons in this topic

  • OOP ABAP Part 1: Classes, Objects, Attributes and MethodsStart object-oriented ABAP the classic way: define and implement a local class, create objects with CREATE OBJECT, use attributes and methods, and understand why SAP moved from FORMs and function groups to classes.
  • OOP ABAP Part 2: Local Classes vs Global ClassesKnow 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.
  • OOP ABAP Part 3: Inheritance, Interfaces and PolymorphismLearn inheritance (INHERITING FROM, REDEFINITION, super->), interfaces (INTERFACES, alias access), polymorphism through superclass and interface references, and up/down casts with ?= and CX_SY_MOVE_CAST_ERROR.
  • OOP ABAP Part 4: Class-Based ExceptionsHandle errors the class-based way: TRY/CATCH/CLEANUP, RAISE EXCEPTION TYPE, the CX_STATIC_CHECK / CX_DYNAMIC_CHECK / CX_NO_CHECK hierarchy, custom exception classes with message texts, and how they compare with classic EXCEPTIONS and sy-subrc.
  • OOP ABAP Part 5: Instance Methods, Static Methods and ConstructorsUnderstand instance vs static components, the instance CONSTRUCTOR and CLASS_CONSTRUCTOR, when each runs, and practical patterns such as validating objects at creation and caching customizing in static attributes.
  • OOP ABAP Part 6: Encapsulation and Visibility — PUBLIC, PROTECTED, PRIVATEUse visibility sections to protect object state: PUBLIC, PROTECTED and PRIVATE components, READ-ONLY attributes, getter/setter methods with validation, FRIENDS, and CREATE PRIVATE for controlled instantiation.
  • OOP ABAP Part 7: Composition vs InheritanceDecide between "is-a" (inheritance) and "has-a" (composition): the fragile base class problem, delegating to helper objects, combining interfaces with composition, and refactoring a deep hierarchy into composed parts.
  • OOP ABAP Part 8: Interfaces and Factory MethodsCreate objects in one controlled place: static factory methods, CREATE PRIVATE, selecting an implementation from customizing, the singleton pattern, and how SAP itself uses factories (CL_SALV_TABLE=>FACTORY, BAdI GET BADI).
  • OOP ABAP Part 9: Dependency Injection and ABAP UnitMake classes testable with dependency injection: constructor injection, optional parameters with defaults, injection through a factory, and ABAP Unit test doubles written by hand or generated with CL_ABAP_TESTDOUBLE.
  • OOP ABAP Part 10: OOP in S/4HANA, RAP and Clean CoreSee where classic OOP knowledge is used in S/4HANA: BAdIs as interfaces, released APIs and wrapper classes, RAP behaviour pools with local handler classes, ABAP Cloud restrictions and Clean ABAP guidelines for classes.

Interview questions covered

  • Explain the difference between an interface and an abstract class in ABAP Objects.
  • Explain visibility modifiers (PUBLIC, PROTECTED, PRIVATE) in ABAP OO. How do they enforce encapsulation, and what is the impact on inheritance hierarchies?
  • Explain RTTI (Runtime Type Information) and RTTS (Runtime Type Services) in ABAP. Design a generic data validation and serialization class using RTTI.
  • Explain the difference between the instance constructor and the static constructor in ABAP OO. When is each executed, and when would you use each?
  • Explain abstract classes and final classes in ABAP OO. When would you mark a class as ABSTRACT or FINAL, and what design constraints does this enforce?
  • Compare static methods and instance methods. When should you use each, and what are the implications for state management and testability?
  • Explain object references and object lifetime in ABAP OO. When are objects automatically garbage collected, and how does this differ from function module data?
  • Explain exception handling in OO ABAP. Design a custom exception hierarchy for a material master API that handles validation errors, not-found errors, and database errors gracefully.
  • How do you evolve an ABAP monolith toward clean OO without a rewrite?
  • What is the difference between an interface and an abstract class?
  • Method call raises CX_SY_REF_IS_INITIAL. What happened?
  • What is polymorphism in ABAP?
  • Explain the difference between a local class and a global class in ABAP OO. When would you use each, and what are the implications for maintainability and reusability?
  • A report has customer, material and pricing validation all inside one START-OF-SELECTION block. How would you restructure it using classes?
  • A service catches CX_ROOT and raises a generic "Save failed" error, so support cannot see whether it was a locking or SQL problem. How should exceptions be handled instead?
  • Country tax rules are implemented as a long CASE statement in several programs. How would you introduce a factory, and how would you make it extensible without code changes?
  • Country-specific tax logic was written as IF/CASE blocks in several programs. How would you use interfaces and polymorphism to redesign it?
  • You need to send notifications through Email, SMS, and Teams. How would you design this in ABAP OOP?
  • An ALV event handler is a local class in a report, while a material validation rule is needed by several programs. Where should each class live and why?
  • A custom document class exposes its status as a public attribute, and different programs set invalid status values. How do you fix this with encapsulation?

Related topics

Interview questions on this topic