Classes and interfaces
ABAP Objects has been fully object-oriented for years: classes, interfaces, inheritance, polymorphism. An interface defines a contract that several classes can implement independently.
INTERFACE zif_contract_validator. METHODS: is_valid IMPORTING is_contract TYPE zcontract RETURNING VALUE(rv_valid) TYPE abap_bool. ENDINTERFACE.
CLASS zcl_contract_validator DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. INTERFACES zif_contract_validator. ENDCLASS. CLASS zcl_contract_validator IMPLEMENTATION. METHOD zif_contract_validator~is_valid. rv_valid = xsdbool( is_contract-manager_1 IS NOT INITIAL ). ENDMETHOD. ENDCLASS.
Modern syntax: inline expressions
Since ABAP 7.40, much of the code can be written in a more functional style, avoiding separate helper variable declarations and reducing the number of lines.
" Inline declaration + VALUE constructor DATA(lt_contracts) = VALUE ty_contracts( ( contract_id = '4500001234' manager_1 = 'DOLL' ) ( contract_id = '4500001235' manager_1 = 'JMART' ) ). " REDUCE: ABAP's equivalent of a functional "reduce" DATA(lv_count) = REDUCE i( INIT n = 0 FOR ls_contract IN lt_contracts NEXT n = n + 1 ). " COND: inline conditional expression DATA(lv_label) = COND string( WHEN lv_count = 0 THEN 'No contracts' WHEN lv_count = 1 THEN '1 contract' ELSE |{ lv_count } contracts| ).
Class-based exceptions
Modern error handling uses exception classes (inheriting from CX_STATIC_CHECK or similar) instead of classic return codes, making the error flow explicit and typed.
TRY. DATA(lv_result) = zcl_contract_service=>get_contract( iv_contract_id = '4500001234' ). CATCH zcx_contract_not_found INTO DATA(lx_error). DATA(lv_msg) = lx_error->get_text( ). MESSAGE lv_msg TYPE 'E'. ENDTRY.
Behavior Implementation classes covered on the RAP page are, underneath, ordinary ABAP classes implementing methods generated from the Behavior Definition — everything above applies equally inside them.Eclipse ADT vs. SAP GUI
Modern ABAP development (RAP included) is done in Eclipse with ADT (ABAP Development Tools), not in SAP GUI/SE80. ADT provides real autocompletion, quick fixes, and is mandatory for working with CDS views and Behavior Definitions.
Internal tables: choosing the right type
ABAP gives you three internal table types with very different performance characteristics. Picking the wrong one on a large dataset is a classic cause of slow reports.
- STANDARD TABLE — unsorted, fast to append, linear-time (
O(n)) reads by key unless you sort or use a secondary index. - SORTED TABLE — kept sorted automatically, binary-search (
O(log n)) reads by key, more expensive inserts. - HASHED TABLE — constant-time (
O(1)) reads by a unique key, but no linear access by index — best for large lookup tables accessed only by key.
TYPES: BEGIN OF ty_contract, contract_id TYPE zcontract_id, manager_1 TYPE bu_partner, END OF ty_contract. " Fast key lookups on a large, static reference table TYPES ty_contracts_hashed TYPE HASHED TABLE OF ty_contract WITH UNIQUE KEY contract_id. DATA(lt_lookup) = VALUE ty_contracts_hashed( ( contract_id = '4500001234' manager_1 = 'DOLL' ) ). READ TABLE lt_lookup WITH KEY contract_id = '4500001234' INTO DATA(ls_contract). " O(1)
Unit testing with ABAP Unit
Testable ABAP separates business logic from database access behind an interface, so tests can inject a test double instead of hitting a real table — the same dependency-injection idea used in any other language.
CLASS ltc_contract_validator DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. DATA cut TYPE REF TO zif_contract_validator. METHODS: setup, manager_missing_is_invalid FOR TESTING. ENDCLASS. CLASS ltc_contract_validator IMPLEMENTATION. METHOD setup. cut = NEW zcl_contract_validator( ). ENDMETHOD. METHOD manager_missing_is_invalid. DATA(ls_contract) = VALUE zcontract( manager_1 = '' ). DATA(lv_result) = cut->is_valid( ls_contract ). cl_abap_unit_assert=>assert_false( lv_result ). ENDMETHOD. ENDCLASS.