All skills
secondsky avatar

/sap-abap

@620a19a
by Eddiesecondsky/sap-skills456 stars
120

Comprehensive ABAP development skill for SAP systems. Use when writing ABAP code, working with internal tables, structures, ABAP SQL, object-oriented programming, RAP (RESTful Application Programming Model), CDS views, EML statements, ABAP Cloud development, string processing, dynamic programming, RTTI/RTTC, field symbols, data references, exception handling, or ABAP unit testing. Covers both classic ABAP and modern ABAP for Cloud Development patterns.

Use this Skill: https://skilld.dev/gh/secondsky/sap-skills/sap-abap

This session only. Nothing lands on disk.

referencesdesign-patterns.md

≈1.6k tokens on demand. Your agent reads this file only when SKILL.md points to it.

OO Design Patterns - Complete Reference

Source: https://github.com/SAP-samples/abap-cheat-sheets/blob/main/34_OO_Design_Patterns.md


Factory Method Pattern

Creates objects through a factory method instead of direct instantiation.

Interface Definition

INTERFACE lif_hello.
  TYPES enum_langu TYPE i.
  CONSTANTS: en TYPE enum_langu VALUE 1,
             fr TYPE enum_langu VALUE 2.
  METHODS say_hello RETURNING VALUE(hi) TYPE string.
ENDINTERFACE.

Concrete Implementations

CLASS lcl_en DEFINITION FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES lif_hello.
ENDCLASS.

CLASS lcl_en IMPLEMENTATION.
  METHOD lif_hello~say_hello.
    hi = `Hi`.
  ENDMETHOD.
ENDCLASS.

CLASS lcl_fr DEFINITION FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES lif_hello.
ENDCLASS.

CLASS lcl_fr IMPLEMENTATION.
  METHOD lif_hello~say_hello.
    hi = `Bonjour`.
  ENDMETHOD.
ENDCLASS.

Factory Class

CLASS lcl_hello_factory DEFINITION FINAL CREATE PRIVATE.
  PUBLIC SECTION.
    CLASS-METHODS create_hello
      IMPORTING language TYPE lif_hello=>enum_langu
      RETURNING VALUE(hello) TYPE REF TO lif_hello.
ENDCLASS.

CLASS lcl_hello_factory IMPLEMENTATION.
  METHOD create_hello.
    hello = SWITCH #( language
      WHEN lif_hello=>en THEN NEW lcl_en( )
      WHEN lif_hello=>fr THEN NEW lcl_fr( )
      ELSE NEW lcl_en( ) ).
  ENDMETHOD.
ENDCLASS.

Usage

DATA(oref_en) = lcl_hello_factory=>create_hello( lif_hello=>en ).
DATA(hello_en) = oref_en->say_hello( ).  " 'Hi'

DATA(oref_fr) = lcl_hello_factory=>create_hello( lif_hello=>fr ).
DATA(hello_fr) = oref_fr->say_hello( ).  " 'Bonjour'

Singleton Pattern

Ensures only one instance of a class exists.

CLASS zcl_singleton DEFINITION
  PUBLIC FINAL CREATE PRIVATE.

  PUBLIC SECTION.
    CLASS-METHODS get_instance
      RETURNING VALUE(ro_instance) TYPE REF TO zcl_singleton.

    METHODS do_something.

  PRIVATE SECTION.
    CLASS-DATA go_instance TYPE REF TO zcl_singleton.
    DATA mv_data TYPE string.

ENDCLASS.

CLASS zcl_singleton IMPLEMENTATION.

  METHOD get_instance.
    IF go_instance IS NOT BOUND.
      go_instance = NEW #( ).
    ENDIF.
    ro_instance = go_instance.
  ENDMETHOD.

  METHOD do_something.
    " Implementation
  ENDMETHOD.

ENDCLASS.

Usage

DATA(singleton1) = zcl_singleton=>get_instance( ).
DATA(singleton2) = zcl_singleton=>get_instance( ).
" singleton1 and singleton2 reference the same instance

Strategy Pattern

Encapsulates interchangeable algorithms.

Strategy Interface

INTERFACE lif_sort_strategy.
  METHODS sort
    CHANGING ct_data TYPE STANDARD TABLE.
ENDINTERFACE.

Concrete Strategies

CLASS lcl_bubble_sort DEFINITION.
  PUBLIC SECTION.
    INTERFACES lif_sort_strategy.
ENDCLASS.

CLASS lcl_bubble_sort IMPLEMENTATION.
  METHOD lif_sort_strategy~sort.
    " Bubble sort implementation
  ENDMETHOD.
ENDCLASS.

CLASS lcl_quick_sort DEFINITION.
  PUBLIC SECTION.
    INTERFACES lif_sort_strategy.
ENDCLASS.

CLASS lcl_quick_sort IMPLEMENTATION.
  METHOD lif_sort_strategy~sort.
    " Quick sort implementation
  ENDMETHOD.
ENDCLASS.

Context Class

CLASS lcl_sorter DEFINITION.
  PUBLIC SECTION.
    METHODS constructor
      IMPORTING io_strategy TYPE REF TO lif_sort_strategy.

    METHODS set_strategy
      IMPORTING io_strategy TYPE REF TO lif_sort_strategy.

    METHODS execute_sort
      CHANGING ct_data TYPE STANDARD TABLE.

  PRIVATE SECTION.
    DATA mo_strategy TYPE REF TO lif_sort_strategy.
ENDCLASS.

CLASS lcl_sorter IMPLEMENTATION.
  METHOD constructor.
    mo_strategy = io_strategy.
  ENDMETHOD.

  METHOD set_strategy.
    mo_strategy = io_strategy.
  ENDMETHOD.

  METHOD execute_sort.
    mo_strategy->sort( CHANGING ct_data = ct_data ).
  ENDMETHOD.
ENDCLASS.

Usage

DATA(sorter) = NEW lcl_sorter( NEW lcl_bubble_sort( ) ).
sorter->execute_sort( CHANGING ct_data = my_table ).

" Switch strategy at runtime
sorter->set_strategy( NEW lcl_quick_sort( ) ).
sorter->execute_sort( CHANGING ct_data = my_table ).

Template Method Pattern

Defines algorithm skeleton, subclasses customize steps.

Abstract Base Class

CLASS lcl_data_processor DEFINITION ABSTRACT.
  PUBLIC SECTION.
    METHODS process FINAL.  " Template method

  PROTECTED SECTION.
    METHODS: load_data ABSTRACT,
             validate_data ABSTRACT,
             transform_data ABSTRACT,
             save_data ABSTRACT.
ENDCLASS.

CLASS lcl_data_processor IMPLEMENTATION.
  METHOD process.
    " Template method defines the algorithm structure
    load_data( ).
    validate_data( ).
    transform_data( ).
    save_data( ).
  ENDMETHOD.
ENDCLASS.

Concrete Implementation

CLASS lcl_csv_processor DEFINITION
  INHERITING FROM lcl_data_processor.

  PROTECTED SECTION.
    METHODS: load_data REDEFINITION,
             validate_data REDEFINITION,
             transform_data REDEFINITION,
             save_data REDEFINITION.
ENDCLASS.

CLASS lcl_csv_processor IMPLEMENTATION.
  METHOD load_data.
    " Load CSV-specific data
  ENDMETHOD.

  METHOD validate_data.
    " CSV-specific validation
  ENDMETHOD.

  METHOD transform_data.
    " CSV-specific transformation
  ENDMETHOD.

  METHOD save_data.
    " CSV-specific save
  ENDMETHOD.
ENDCLASS.

Pattern Comparison

Pattern Purpose Key Mechanism
Factory Method Object creation abstraction Factory method returns interface
Singleton Single instance guarantee Private constructor, static accessor
Strategy Interchangeable algorithms Runtime strategy selection
Template Method Algorithm skeleton Abstract methods for steps

Best Practices

  1. Factory Method: Use for complex object creation, multiple implementations
  2. Singleton: Use sparingly, consider dependency injection
  3. Strategy: Prefer over switch/case for behavior selection
  4. Template Method: Use for algorithms with variable steps
  5. Program to interfaces for flexibility
  6. Favor composition over inheritance where appropriate

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    A comprehensive reference for SAP ABAP development, providing documentation and code examples for both classic ABAP and modern ABAP Cloud patterns. No security issues were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    3/32 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 620a19a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 months ago
Other metadata
metadata
{
  "maintainer": "Eduard Jiglau",
  "maintainer_email": "hello@sap-ai-skills.com",
  "website": "https://sap-ai-skills.com",
  "version": "2.4.1",
  "last_verified": "2026-04-02",
  "abap_release": "7.40 SP08+ / 7.50+ / ABAP Cloud",
  "sources": [
    "https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm",
    "https://github.com/SAP-samples/abap-cheat-sheets"
  ]
}

README badge

README badge for secondsky/sap-skills/sap-abap