ABAP Cloud Debugging: Tools & Techniken 2025

kategorie
Tools
Veröffentlicht
autor
Johannes

Debugging in ABAP Cloud ist anders als in Classic ABAP. Dieser Guide zeigt dir die neuen Tools und Techniken.

🎯 Was ist anders in ABAP Cloud?

❌ Geht NICHT mehr

  • /h Debugger-Kommando
  • SAP GUI Debugger (SE38, SE80)
  • BREAK-POINT Statement
  • Dynpro-Debugging
  • Direkter DB-Zugriff im Debugger

✅ Neue Tools

  • ADT Debugger (Eclipse)
  • ABAP Console (cl_demo_output)
  • Feed Reader (Background Jobs)
  • Application Log (BAL)
  • SQL Trace (Performance)

1. ADT Debugger (Haupt-Tool)

Debugger starten

Methode 1: Breakpoint setzen

  1. In ADT: Doppelklick auf Zeilennummer → Breakpoint (blauer Punkt)
  2. Programm ausführen (F9 oder Preview)
  3. Debugger stoppt an Breakpoint

Methode 2: Run As → ABAP Application (Debug)

  1. Rechtsklick auf Klasse/Programm
  2. Debug AsABAP Application

Debugger-Layout

┌─────────────────────────────────┐
│ Code (aktuell Zeile markiert) │
├─────────────────────────────────┤
│ Variables (Variablen-Werte) │
├─────────────────────────────────┤
│ Breakpoints (alle Breakpoints) │
├─────────────────────────────────┤
│ Call Stack (Aufruf-Historie) │
└─────────────────────────────────┘

Wichtigste Shortcuts

ShortcutAktion
F5Step Into (in Methode springen)
F6Step Over (Zeile ausführen)
F7Step Return (aus Methode zurück)
F8Resume (bis nächster Breakpoint)
Ctrl+Shift+BToggle Breakpoint
Ctrl+Alt+BAlle Breakpoints zeigen

Variablen inspizieren

METHOD calculate.
DATA(lv_a) = 5.
DATA(lv_b) = 3.
DATA(lv_result) = lv_a + lv_b. " Breakpoint hier
" Im Variables Tab:
" lv_a = 5
" lv_b = 3
" lv_result = 8
ENDMETHOD.

Variablen ändern:

  1. Rechtsklick auf Variable → Change Value
  2. Neuen Wert eingeben
  3. Weiter debuggen mit geändertem Wert

Watchpoints

Stoppt, wenn Variable sich ändert:

  1. Rechtsklick auf Variable → Toggle Watchpoint
  2. Debugger stoppt bei jeder Änderung

Conditional Breakpoints

Nur stoppen wenn Bedingung erfüllt:

  1. Rechtsklick auf Breakpoint → Breakpoint Properties
  2. Condition: lv_id = '12345'
  3. Stoppt nur wenn lv_id diesen Wert hat

2. ABAP Console (Output während Entwicklung)

Statt WRITE oder Debug-Ausgaben:

METHOD process_data.
" Einfache Ausgabe
cl_demo_output=>display( 'Starting processing' ).
" Variable ausgeben
cl_demo_output=>write( |Customer ID: { lv_customer_id }| ).
" Tabelle ausgeben
cl_demo_output=>write( lt_customers ).
" Finale Ausgabe
cl_demo_output=>display( ).
ENDMETHOD.

Output:

  • Erscheint im Console Tab in ADT
  • Nur in Entwicklung nutzen!
  • In Produktion: Application Log verwenden

Vorteile:

  • ✅ Schneller als Debugger
  • ✅ Für komplexe Datenstrukturen
  • ✅ Bleibt im Log (scrollen möglich)

3. Logging mit Application Log

Für produktiven Code:

METHOD process_order.
TRY.
" Log erstellen
DATA(lo_log) = cl_bali_log=>create_with_header(
header = cl_bali_header_setter=>create(
object = 'ZORDERS'
subobject = 'PROCESS'
external_id = |Order { iv_order_id }|
)
).
" Info-Meldung
lo_log->add_item(
item = cl_bali_free_text_setter=>create(
severity = if_bali_constants=>c_severity_information
text = |Processing order { iv_order_id }|
)
).
" Verarbeitung...
" Erfolgs-Meldung
lo_log->add_item(
item = cl_bali_free_text_setter=>create(
severity = if_bali_constants=>c_severity_status
text = 'Order processed successfully'
)
).
" Log speichern
cl_bali_log_db=>get_instance( )->save_log( log = lo_log ).
CATCH cx_bali_runtime INTO DATA(lx_error).
" Error handling
ENDTRY.
ENDMETHOD.

Log ansehen:

  • Transaktion SLG1 (Classic)
  • Fiori App: “Application Logs”

Severity-Levels:

  • c_severity_error - Fehler (rot)
  • c_severity_warning - Warnung (gelb)
  • c_severity_information - Info (blau)
  • c_severity_status - Status (grün)

4. SQL Trace (Performance-Debugging)

Problem: Langsame SELECT-Statements finden

SQL Trace aktivieren

In ADT:

  1. RunRun Configurations
  2. Tab Trace Requests
  3. SQL Trace aktivieren
  4. Programm ausführen

Trace analysieren

SQL Console öffnet sich:

SELECT * FROM kna1
Duration: 1.2s ❌ LANGSAM!
Rows: 1,000,000
SELECT name1 FROM kna1
WHERE kunnr = '12345'
Duration: 0.001s ✅ Schnell
Rows: 1

Optimierung:

  • SELECT * vermeiden
  • FOR ALL ENTRIES mit leerer Tabelle
  • ✅ Explizite Felder
  • ✅ WHERE auf indexed Feldern

5. Feed Reader (Background Jobs)

Problem: Background Jobs debuggen

Setup

  1. Job starten (Fiori App / SM37)
  2. In ADT: WindowShow ViewFeed Reader
  3. Feed-URL eintragen:
    https://<system>/sap/bc/adt/runtime/traces/abaplogs

Output

Feed Reader zeigt:

  • Console-Outputs
  • Application Logs
  • Laufzeit-Fehler

Live-Updates während Job läuft!


6. Debugging-Strategien ohne Debugger

Strategie 1: Unit Tests

Statt Debuggen: Test schreiben

METHOD test_calculate_discount.
" Given
DATA(lv_amount) = 1000.
" When
DATA(lv_discount) = zcl_pricing=>calculate_discount( lv_amount ).
" Then
cl_abap_unit_assert=>assert_equals(
act = lv_discount
exp = 100
msg = |Expected 100, got { lv_discount }| " Debug-Info!
).
ENDMETHOD.

Vorteil: Reproduzierbar, automatisiert

Strategie 2: Defensive Assertions

METHOD process_order.
" Precondition prüfen
ASSERT iv_order_id IS NOT INITIAL.
" Geschäftslogik
DATA(lv_customer) = get_customer( iv_order_id ).
" Postcondition prüfen
ASSERT lv_customer IS BOUND.
ENDMETHOD.

In Production: ASSERT wird ignoriert (nur in Debug-Modus aktiv)

Besser für Production: Exceptions

IF lv_customer IS NOT BOUND.
RAISE EXCEPTION TYPE zcx_customer_not_found.
ENDIF.

Strategie 3: Logging-Framework

Eigenes Logging-Wrapper:

CLASS zcl_logger DEFINITION.
PUBLIC SECTION.
CLASS-METHODS log
IMPORTING iv_level TYPE string DEFAULT 'INFO'
iv_text TYPE string.
ENDCLASS.
CLASS zcl_logger IMPLEMENTATION.
METHOD log.
" In Dev: Console
IF sy-sysid = 'DEV'.
cl_demo_output=>write( |[{ iv_level }] { iv_text }| ).
ELSE.
" In Prod: Application Log
" ... BAL Code ...
ENDIF.
ENDMETHOD.
ENDCLASS.
" Verwendung
zcl_logger=>log( iv_level = 'DEBUG'
iv_text = |Processing customer { lv_id }| ).

7. Häufige Debug-Szenarien

Szenario 1: Exception im RAP

Problem: Validation schlägt fehl, aber warum?

METHOD validateIsbn.
READ ENTITIES OF zi_book IN LOCAL MODE
ENTITY Book
FIELDS ( Isbn )
WITH CORRESPONDING #( keys )
RESULT DATA(lt_books).
LOOP AT lt_books INTO DATA(ls_book).
" Debug-Output
cl_demo_output=>write( |Checking ISBN: { ls_book-Isbn }| ).
IF strlen( ls_book-Isbn ) <> 13.
cl_demo_output=>write( 'ISBN invalid - length mismatch' ).
APPEND VALUE #( ... ) TO reported-book.
ENDIF.
ENDLOOP.
cl_demo_output=>display( ).
ENDMETHOD.

Szenario 2: CDS View gibt falsche Daten

Strategie:

  1. SQL Console: CDS View direkt abfragen
  2. Data Preview: In ADT Rechtsklick auf View → Open WithData Preview
  3. Quell-Tabellen prüfen: Sind Rohdaten korrekt?

Szenario 3: Performance-Problem

Vorgehen:

  1. SQL Trace aktivieren
  2. Langsame SELECTs identifizieren
  3. ABAP Console: Zeitstempel loggen
DATA(lv_start) = cl_abap_context_info=>get_system_time( ).
" Langsame Operation
SELECT ... INTO TABLE lt_data.
DATA(lv_end) = cl_abap_context_info=>get_system_time( ).
cl_demo_output=>write( |Duration: { lv_end - lv_start } µs| ).

8. Debugging Best Practices

✅ DO

  1. Breakpoints sparsam setzen (nicht 50 Stück!)
  2. Conditional Breakpoints für große Datasets
  3. Unit Tests statt live debuggen
  4. Logging in produktivem Code
  5. SQL Trace für Performance

❌ DON’T

  1. Production Debuggen (nur als letztes Mittel!)
  2. BREAK-POINT im Code lassen
  3. Console-Output in Produktion
  4. Debugger als einziges Tool nutzen

9. Tools-Übersicht

ToolUse CaseWo verfügbar?
ADT DebuggerInteraktives DebuggingADT/Eclipse
ABAP ConsoleSchnelle OutputsADT (Dev only)
Application LogProdukt-LoggingAlle Systeme
SQL TracePerformance-AnalyseADT
Feed ReaderBackground Job LogsADT
Data PreviewCDS View Daten prüfenADT

🎯 Zusammenfassung

ABAP Cloud Debugging Workflow:

1. Unit Tests schreiben
↓ (wenn Test fehlschlägt)
2. ADT Debugger nutzen
↓ (Performance-Problem?)
3. SQL Trace aktivieren
↓ (Produktion?)
4. Application Log analysieren

Mindset-Shift:

  • Classic ABAP: Debugger-First
  • ABAP Cloud: Test-First, Logging, dann Debugger

Siehe auch:

Happy Debugging! 🐛