Chapter 11 · Real-World Skills
Debugging & Error Handling
How to find bugs in your code, handle errors gracefully, and understand ABAP messages — the skills that separate juniors from professionals.
You can write code. But can you fix it when it breaks? That is the real test of an ABAP developer. In every project you will join, you will spend more time debugging existing code than writing new code. And when your own code fails, you need to handle errors gracefully — not let the program dump on the user’s screen.
This chapter gives you the two essential survival skills every ABAP developer needs: debugging (finding what went wrong) and error handling (making sure it never dumps on the user).
🎯 What You Will Learn in This Chapter
- How to activate and use the ABAP Debugger
- How to set breakpoints and watchpoints
- The difference between session and external breakpoints
- How to read a short dump and find the root cause
- How to handle errors with TRY / CATCH and class-based exceptions
- All six MESSAGE types (A, E, W, I, S, X) and when to use each
- How to debug a background job (the tricky one)
- Introduction to ST05 and SAT for performance analysis
🐞 What is Debugging?
Debugging is the process of pausing a running program, inspecting its state, and stepping through it line by line to find the source of a problem.
Imagine reading a 500-page book and you need to know what a specific character says on page 247. You would not read all 500 pages. You would skip to page 247 and read carefully from there. Debugging works the same way — you jump to the exact line where the problem occurs and watch what happens.
| Without Debugger | With Debugger |
|---|---|
| Print variables with WRITE statements and guess | Inspect any variable at any moment |
| Read code and try to trace mentally | Watch code execute step by step |
| Modify code just to add a message | Zero code changes needed |
| Hours of guessing | Minutes of precision |
🛠 The ABAP Debugger — Two Flavors
SAP provides two debuggers:
| Debugger | When Used |
|---|---|
| Classic Debugger | Older, simpler, works in most transactions. Activated by /h in the command field. |
| New Debugger | Modern, feature-rich, uses Eclipse or SAP GUI. Activated by /h or /hs (system debugging). |
How to activate the debugger
Type /h in the command field (top-left of SAP GUI) and press Enter. This activates debugging for the next screen the program shows.
Open your program in SE38 or SE80. Click on the line number area next to a code line. A small red dot appears — that is a breakpoint. The program will pause when it reaches that line.
Add a BREAK-POINT. statement in your code. This is the same as setting a breakpoint in the editor, but permanent in the source code (not recommended for production).
🎮 Debugger Controls — The Buttons That Matter
Once the debugger opens, you will see a toolbar. These are the buttons you will use most:
| Button | Shortcut | What It Does |
|---|---|---|
| Step Over (Single Step) | F6 | Executes the current line and moves to the next |
| Execute (Return) | F8 | Runs the program until the next breakpoint |
| Step Into (Step Into) | F5 | Jumps inside a FORM, method, or function module |
| Step Out (Return) | Shift+F8 | Exits the current routine back to the caller |
| Continue (Play) | F8 | Continues until the next breakpoint or program end |
| Watchpoint | — | Pause when a variable changes value |
| Table | — | View internal table contents |
| Breakpoints | — | List of active breakpoints |
🎯 Breakpoints vs Watchpoints
These are the two core debugging tools. Understanding the difference will save you hours.
Breakpoints — pause at a specific line
A breakpoint stops the program when execution reaches a specific line of code. You set it where you suspect the bug is.
" Set a breakpoint here to inspect before this line runs
SELECT * FROM scarr INTO TABLE @DATA(lt_scarr).
BREAK-POINT. " Program pauses here
LOOP AT lt_scarr INTO DATA(ls_scarr).
WRITE ls_scarr-carrname.
ENDLOOP.
Watchpoints — pause when a variable changes
A watchpoint does not care about the line — it stops when a specific variable changes value. This is incredibly powerful for tracking down where data gets corrupted.
Session vs External breakpoints
| Type | Scope | Use Case |
|---|---|---|
| Session Breakpoint | Only your session | Debugging your own code in your current session |
| External Breakpoint | Any session (including HTTP/RFC) | Debugging web services, RFC calls, or another user’s session |
💥 Reading a Short Dump
A short dump is what SAP calls a runtime error. It happens when your program does something illegal — dividing by zero, accessing a non-existent table row, referencing a null object.
When a dump occurs, SAP shows the user a screen with technical details. As a developer, you read those details to find the cause.
Where to find dumps
- ST22 — Transaction to view all dumps in the system
- Runtime error screen — The dump itself shows the error text and where it occurred
Common dump types and their causes
| Dump | Cause | Fix |
|---|---|---|
COMPUTE_INT_ZERODIVIDE | Dividing by zero | Check divisor before dividing |
ITAB_ILLEGAL_INDEX | Accessing an internal table row that does not exist | Check sy-subrc or table lines before reading |
DBIF_RSQL_INVALID_RSQL | Invalid Open SQL statement | Check syntax and table names |
OBJECTS_OBJREF_NOT_ASSIGNED | Calling a method on a null object reference | Check IS BOUND before calling |
CONVT_NO_NUMBER | Converting non-numeric string to number | Validate input before conversion |
📢 MESSAGE Types — A, E, W, I, S, X
Every message in ABAP has a type. The type determines how the message appears and what happens after it.
| Type | Name | Effect | Use Case |
|---|---|---|---|
| A | Abend | Terminates the transaction with a dump | Critical errors (rarely used) |
| E | Error | Shows an error message, stops processing | Validation failures |
| W | Warning | Shows warning, allows user to continue | Non-blocking issues |
| I | Information | Popup with OK button, continues | Information dialogs |
| S | Success | Shows on status bar, continues | Confirmation (“Saved successfully”) |
| X | Exit | Terminates silently with a dump | Emergency exits (rarely used) |
MESSAGE statement syntax
" Using a message from message class ZMSG
MESSAGE e001(zmsg). " Error type, message 001
" With dynamic text
MESSAGE i001(zmsg) WITH lv_name.
" Inline syntax (modern)
MESSAGE |Error: { lv_msg }| TYPE 'E'.
" Check message type in code
IF sy-subrc <> 0.
MESSAGE 'Record not found' TYPE 'E'.
ENDIF.
MESSAGE ... TYPE 'E' in a report, the program stops. Use TYPE 'W' or TYPE 'I' if you want the program to continue.
🛡 Exception Handling — TRY / CATCH
Exception handling is the art of catching errors before they crash the program. ABAP has two approaches: classic exceptions (older) and class-based exceptions (modern, recommended).
Class-based exceptions — TRY / CATCH
Modern exception handling uses TRY and CATCH blocks. The idea: run code inside TRY. If an exception is raised, control jumps to CATCH.
TRY.
DATA(lv_result) = 10 / iv_divisor.
WRITE: / 'Result:', lv_result.
CATCH cx_sy_zerodivide INTO DATA(lo_exc).
WRITE: / 'Cannot divide by zero!'.
WRITE: / lo_exc->get_text( ).
CATCH cx_root INTO DATA(lo_root).
WRITE: / 'Unexpected error:', lo_root->get_text( ).
ENDTRY.
Raising exceptions
When writing your own classes, you can raise exceptions intentionally to signal problems:
CLASS zcl_validator DEFINITION.
PUBLIC SECTION.
METHODS validate
IMPORTING iv_amount TYPE p
RAISING cx_sy_arithmetic_error.
ENDCLASS.
CLASS zcl_validator IMPLEMENTATION.
METHOD validate.
IF iv_amount < 0.
RAISE EXCEPTION TYPE cx_sy_arithmetic_error.
ENDIF.
ENDMETHOD.
ENDCLASS.
Classic exceptions — EXCEPTIONS parameter
Older function modules use the EXCEPTIONS parameter. You list possible exceptions and check sy-subrc after the call:
CALL FUNCTION 'Z_VALIDATE_DATE'
EXPORTING
iv_date = sy-datum
EXCEPTIONS
invalid_date = 1
others = 2.
IF sy-subrc = 1.
WRITE: / 'Date is invalid.'.
ENDIF.
⚙️ Debugging a Background Job
Background jobs run without a user session, so you cannot just type /h. But you can still debug them. Three approaches:
Approach 1 — Debug background job from SM37
- Go to transaction SM37 (Job Overview)
- Find and select the job
- Click Job → Debug (or the Debug button)
- A dialog appears asking for a user. Enter your username
- Release the job. When it starts, your debugger opens
Approach 2 — WAIT UP TO statement
WAIT UP TO 10 SECONDS. " Creates a debugging window
Approach 3 — Remote debugging
For RFC and HTTP calls, configure remote debugging in the target system so calls from a specific user trigger the debugger automatically.
📊 ST05 and SAT — Performance Tools (Intro)
Debugging is not only about bugs. It is also about performance. Two tools you must know:
| Tool | Full Name | What It Does |
|---|---|---|
| ST05 | SQL Performance Trace | Records all database calls (SELECT, INSERT, UPDATE, DELETE). Use it to find slow or excessive DB queries. |
| SAT | Runtime Analysis | Measures execution time of ABAP code at the statement level. Use it to find which methods or statements take the longest. |
📝 Chapter Summary
- The ABAP Debugger pauses execution so you can inspect variables and program flow.
- Activate it with
/hin the command field, or set a breakpoint in the editor. - F6 = Step Over (next line). F8 = Execute to next breakpoint.
- Breakpoints pause at a specific line. Watchpoints pause when a variable changes value.
- A short dump is a runtime error. Read it in ST22 to find the cause.
- Six MESSAGE types: A (Abend), E (Error), W (Warning), I (Info), S (Success), X (Exit).
- Class-based exceptions use
TRY / CATCH. Use them for all new code. - Debug background jobs via SM37 → Job → Debug.
- ST05 traces database calls. SAT measures code execution time.
🎤 Interview Questions & Answers
These are real interview questions about debugging and error handling. Being able to describe your debugging approach clearly is often more important than knowing every syntax detail.
The ABAP Debugger is a built-in tool in SAP that lets you pause program execution and inspect variable values, internal table contents, and program flow step by step. You activate it by setting a breakpoint in the editor or by typing /h in the command field. Once triggered, the debugger opens and you can step through code line by line.
A breakpoint pauses the program at a specific line of code. A watchpoint pauses the program when a specific variable changes value, regardless of which line causes the change. Breakpoints are used to inspect specific logic; watchpoints are used to track down when and where a variable gets corrupted.
A = Abend (terminates transaction with dump), E = Error (shows error, stops processing), W = Warning (shows warning, continues), I = Information (popup, continues), S = Success (status bar message, continues), X = Exit (terminates silently with a dump). In most cases, A and X both terminate but differ in messaging.
Exception handling in ABAP is the process of detecting and responding to runtime errors gracefully instead of letting the program crash. ABAP supports two approaches: classic exceptions using EXCEPTIONS parameters with sy-subrc checks, and class-based exceptions using TRY/CATCH blocks with exception classes derived from CX_ROOT.
TRY/CATCH is the modern, object-oriented way to handle exceptions using exception classes. EXCEPTIONS is the older method used with function modules where you list possible exceptions and check sy-subrc after the call. TRY/CATCH is preferred in new code, while EXCEPTIONS still appears in legacy function module calls.
You cannot set breakpoints in a background job because there is no user session. Instead, you use transaction SM37 to schedule the job, then use the Job → Debug option to attach the ABAP Debugger. You enter your username when prompted and release the job. When the job starts, the debugger opens automatically. Alternatively, use WAIT UP TO statements to create debugging windows, or configure Remote Debugging for RFC/HTTP calls.
ST05 is the SAP Performance Trace tool. It records all database calls (SELECT, INSERT, UPDATE, DELETE), RFC calls, and buffer accesses made by a program. You use ST05 to identify slow or excessive database queries and to measure overall program performance.
SAT is the ABAP Runtime Analysis tool. It measures execution time of your ABAP code at the statement level — showing exactly which methods, function modules, and statements take the most time. Use SAT to find performance bottlenecks in your own code, while ST05 is used to analyze database access time.
🛠 Practice Task for This Chapter
Build a report that intentionally fails, then debug it. This exercise teaches you more about debugging than any tutorial.
- Create a program
Z_DEBUG_PRACTICEthat selects rows from SCARR into an internal table. - Add a loop that divides 100 by each row number. Make it fail deliberately by making one of the numbers zero.
- Wrap the loop in
TRY / CATCH cx_sy_zerodivideand display a graceful error message. - Run the report. Verify the error is caught and the program does not dump.
- Now comment out the TRY/CATCH and run again. You will see the dump screen.
- Go to ST22 and read the dump. Identify the exact line where the error occurred.
- Set a breakpoint on that line and re-run with the debugger. Inspect the divisor value when it becomes zero.
- Set a watchpoint on the divisor variable. Observe the debugger pausing exactly when it changes to zero.
Test: Kon Banega Crorepati?
5 questions. ₹1 Crore. Prove you understood Debugging & Error Handling. No pressure — restart anytime.
Explore Our Instructor-Led SAP & IT Courses
Self-study works. But if you want guided training, real project practice, and placement support — here are the courses we offer. Book a free demo before you decide.
WhatsApp us