ERPClimb logoERPClimb
Login
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?

How to study OOP ABAP

OOP ABAP has 10 lessons (2 beginner, 4 intermediate, 4 advanced) with about 97 minutes of reading in total. Start with the lesson that matches your level, then read the real project scenario and common mistakes in each one before moving on. After the lessons, say the 29 interview questions out loud in your own words, then check yourself against the model answer in each question (shown once you open it). Use the 31 mock questions to check recall. Finish with the 1 code lab scenario: read the buggy code first, say what is wrong, and only then open the optimized version.

Mock test questions covered

Try answering each one before you open the mock test; the answer options and scoring are in the Mock Questions tab.

  • What does CREATE OBJECT ro_tax TYPE zcl_tax_in do when ro_tax is TYPE REF TO zif_tax_calculator?
  • A save method catches a database exception. How should it pass the error on without losing the root cause?
  • Which call demonstrates polymorphism?
  • Why is constructor injection of an interface-typed DAO useful for ABAP Unit?
  • Which operator accesses a static attribute of class lcl_flight?
  • In a class, where is the code of a method written?
  • Which statement about global classes is TRUE?
  • Two CATCH blocks follow a TRY: CATCH cx_root first, then CATCH zcx_flight_error. What happens when zcx_flight_error is raised?
  • When does CLASS_CONSTRUCTOR run?
  • Which parameters can an instance CONSTRUCTOR have?
  • What does READ-ONLY on a public attribute mean?
  • Which statement best describes composition?
  • A constructor parameter io_dao TYPE REF TO lif_order_dao is OPTIONAL and the constructor creates the real DAO if it is not bound. What is the benefit?
  • What distinguishes a spy (mock) from a simple stub?
  • In a clean core approach, how should cloud-ready custom code use an unreleased SAP function module?

Code lab scenarios

  • God class doing everythingA single class ZCL_ORDER_MANAGER reads orders, validates them, sends emails and writes to a log. It is hard to test and change.

Related topics

Interview questions on this topic