Debugging
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
A program that runs without an error message can still give a wrong answer: a total that is too small, a loop that
stops too early, a status that is never set. Reading the code again often does not show why. A debugger lets you stop the
program at a chosen line, look at the real values of its variables, and then run it one statement at a time, so that
you see where the program does something different from what you expected. After reading this page you can set the
different kinds of breakpoint, stop when a variable changes, step through code, look at a short dump after a crash, and
you know which other tool to reach for when the problem is speed and not correctness. The page is written against
Standard ABAP release 8.16 and ABAP for Cloud Development release 9.20 (2608). The ABAP Debugger of ABAP Development
Tools (ADT) works with ABAP Cloud, with classic ABAP, on premise and in the Public Edition. The debugger of SAP GUI, the
statements BREAK-POINT and LOG-POINT, transaction ST22 and transaction SAT belong to classic Standard ABAP systems
that you reach with SAP GUI. Every debugger feature on this page needs a running SAP system, so nothing about the
debugger itself could be run here; the only program that was run is the small debuggee in the first example.
Before you read
-
ADT Eclipse Setup: installing ABAP Development Tools and connecting an ABAP project, which the debugger needs.
-
Control Flow: loops and conditions, the code you will step through.
-
Class-Based Exceptions: what an uncaught exception does, which is the usual cause of a short dump.
-
Internal Tables: the table the example loops over.
Key terms
-
ABAP Debugger: the tool that stops a running program and shows its variables and call chain.
-
Breakpoint: a marker that makes the debugger stop when execution reaches a line, a statement, a message or an exception.
-
Watchpoint: a marker on a variable that makes the debugger stop as soon as the value of that variable changes.
-
Debuggee: the program that runs under the control of the debugger.
-
Short dump: the error log that ABAP writes when a program ends with a runtime error, read in transaction ST22 or in ADT.
-
ABAP Profiler: the tool that measures where a program spends its run time; the successor of transaction SAT.
The debugging loop
Debugging is a short loop that you repeat until the mistake is found. First you decide where you want to look: usually the line where a wrong value is first used. You set a breakpoint there and start the program. When the program stops, you look at the variables. If they are right, the mistake is further on, so you step forward or run to the next breakpoint. If they are already wrong, the mistake is earlier, so you move the breakpoint back, or you set a watchpoint on the variable and restart the program to find the statement that changed it.
A small program to debug
The examples use a report that adds up the amounts of four claim items of the Expense claims application. One amount is negative, which is the kind of data mistake that a debugger makes visible. This is a reduced version of the claim items: only the claim number and an integer amount. The listing was run in the local ABAP lab, which runs a subset of ABAP in Node.js and has no debugger, so the output below is the real result of the run and the debugging steps that follow are described, not run.
REPORT zdebug_demo.
TYPES: BEGIN OF ty_item,
claim_id TYPE i,
amount TYPE i,
END OF ty_item.
DATA items TYPE STANDARD TABLE OF ty_item WITH EMPTY KEY.
DATA total TYPE i.
items = VALUE #( ( claim_id = 1 amount = 40 )
( claim_id = 2 amount = 25 )
( claim_id = 3 amount = -5 )
( claim_id = 4 amount = 60 ) ).
LOOP AT items INTO DATA(item).
total = total + item-amount.
WRITE / |After claim { item-claim_id }: total = { total }|.
ENDLOOP.
WRITE / |Final total: { total }|.
Output of the run in the ABAP lab (a copy of the lab; Node.js 22):
After claim 1: total = 40 After claim 2: total = 65 After claim 3: total = 60 After claim 4: total = 120 Final total: 120
Suppose a reader expected 130, because the negative amount of claim 3 was meant to be ignored. Reading the output shows
that the total dropped at claim 3, but not why the item was accepted. In a debugger you would put a breakpoint on the
line total = total + item-amount., and the program would stop once for each of the four items.
The ABAP Debugger in ADT
ADT has its own ABAP Debugger that looks and behaves like the rest of Eclipse. SAP lists the main features as setting and managing breakpoints, watchpoints, managing variables, debugging dynpro flow logic and enhancement implementations, displaying exceptions, and stepping. The requirements are a back-end kernel of release 721 or later and SAP NetWeaver 7.3 EHP1 SP04 or later, which every current system meets.
Starting the debugger
You start the debugger by setting a breakpoint in the source code and running the program, as in
ADT Eclipse Setup. Run the program with F9 or run its ABAP
Unit tests, and Eclipse switches to the Debug perspective when the program stops at the breakpoint.
Breakpoints
A breakpoint in ADT is by default an external user breakpoint. It is valid in your current ABAP project, for requests
that you start from the project (a program run with F9, an ABAP Unit run, or anything inside an embedded SAP GUI),
and for any new request of your ABAP user on any application server of the system, whatever its origin. Setting such a
breakpoint activates the debugger in the whole system for your user: every new request of yours, for example an
HTTP call or an RFC call from another system, loads the breakpoints and stops when one is reached. Breakpoints that
you set in ADT are not used by a stand-alone SAP GUI logon session.
| Kind | What it does | How you set it in ADT |
|---|---|---|
Line breakpoint (static) |
Stops at one line. It sticks to the line: if you add or delete code above it, the breakpoint moves with the line. |
Double-click the ruler next to an executable line, or |
Statement breakpoint (dynamic) |
Stops whenever a given ABAP statement is reached, in any program that runs under your user. |
|
Exception breakpoint (dynamic) |
Stops when an exception of a given exception class is raised. |
|
Message breakpoint (dynamic) |
Stops when a given message is issued. |
|
The three dynamic kinds are soft breakpoints by default. A soft breakpoint cannot start the debugger by itself. It only
takes effect once a debug session has been started by another breakpoint, such as a normal line breakpoint, and then it
can make that session stop. SAP recommends keeping this default. If you switch the property off, many requests can
stop in the debugger, for example when you break on a very frequent statement such as MOVE or CALL.
The Breakpoints view of the Debug perspective lists and manages all breakpoints.
Conditions on breakpoints
In the example above, a line breakpoint that stops four times is a nuisance. A condition makes it stop only when
something is true. Open the breakpoint properties from the ruler context menu (Breakpoint Properties...), or type the
condition in the Breakpoints view. If the condition is true when the line is reached, the program stops; an empty
condition is always true. A condition can be at most 255 characters. Its syntax is a subset of an ABAP logical
expression: elementary comparisons joined with AND and OR, brackets, and short-circuit evaluation. The syntax is
checked when you save it, but whether a variable exists is only checked at run time, and an invalid operand stops the
program at the breakpoint with an error message.
For the example, the condition item-amount < 0 on the line total = total + item-amount. stops only for claim 3.
This condition is an application of the rule above; it was not run, because it needs an SAP system with the
debugger. The following are some of the valid conditions that SAP shows:
sy-index > 5 lines( itab ) > 0 strlen( s ) >= sy-index oref is bound and oref->attr = 'abc' a > b AND (c > b OR c > d)
Watchpoints
A watchpoint tracks one variable. While a debug session is running, place the cursor on the field in the source editor
of the Debug perspective, or select the variable in the Variables view, open the context menu and choose
Set Watchpoint. The debugger then stops as soon as the value changes after a debug step. You can also enter a
condition for the watchpoint in the Breakpoints view, and then it stops only when the value has changed and the
condition is true. A watchpoint exists only inside a suspended debug session and is removed when that session ends, so
you set it again in the next session.
In the example, a watchpoint on total stops after each of the four additions and shows which statement changed it.
This was not run here; it needs an SAP system.
Stepping and looking at values
The Debug perspective has buttons for the movements below, and the keyboard shortcuts in brackets.
| Action | Effect |
|---|---|
Resume |
Run to the next breakpoint or to the end of the program. |
Step Into ( |
Execute the next single instruction; if it is a call, step into the called procedure. |
Step Over ( |
Execute the next statement; if it is a call, run the whole procedure. |
Step Return ( |
Run until the current procedure returns to its caller. |
Run to Line ( |
Run to the statement where the cursor is. |
Jump to Line ( |
Move the execution pointer to the cursor line without running anything in between. Variables are not reset, so use it with care. |
Terminate |
Abort the program. |
Disconnect |
Run to the end of the program and ignore all later breakpoints. |
The Variables view shows the current values, including structures, internal tables and objects. You can also change a variable value in a debug session while you test a theory, which is quicker than editing and restarting. The ADT user guide documents the details of changing values separately for ABAP Platform systems and for the Public Cloud, so check the page of your release before relying on it. The call stack in the Debug view lists the procedures that led to the current line; clicking an entry opens that code in the editor.
Debugging in ABAP Cloud
Everything above works in ABAP Cloud projects, because ADT is the development tool for ABAP Cloud. In the context of the ABAP environment, the Feed Reader view is the central view for analyzing runtime errors. The classic statements and tools of the next sections are described in the Keyword Documentation for Standard ABAP, so in an ABAP Cloud project set your breakpoints in ADT.
The ABAP Debugger in SAP GUI
Classic systems also have a debugger inside SAP GUI. SAP states that the ADT debugger can satisfy most requirements and adds comfort, but that it does not implement every tool of the back-end debugger. The comparison page lists the cases for which you may switch to the SAP GUI debugger.
| Use case | Where SAP says to do it |
|---|---|
Layer-based debugging, which hides the framework layers that you do not care about |
In the back-end debugger. ADT step filters work only with Java code. |
Customized display of a structure or an object |
In the back-end debugger (layouts for the Structure and Objects tools). |
Comparing complex data objects |
The diff tool of the back-end debugger. |
Memory use of objects |
The back-end debugger. |
Automating a debugging task with debugger scripts |
The back-end debugger. |
Requires an SAP system with SAP GUI; not run here.
Breakpoints and checkpoints in the source code
You can also write a stop into the program. The statement BREAK-POINT defines a breakpoint at that position. In dialog
processing the program stops and the debugger opens. In background processing it does not stop: a BREAK-POINT
without ID writes the entry "Breakpoint reached" into the system log and the program goes on, and a breakpoint with
ID is ignored. A permanent BREAK-POINT is for tests only and not allowed in production programs: the extended
program check reports it as an error. With ID group the breakpoint is activated from outside the program, through a
checkpoint group.
BREAK-POINT.
BREAK-POINT ID zexp_checkpoint_group.
Requires an SAP system; not run here. The checkpoint group zexp_checkpoint_group is an invented name; a checkpoint
group must exist in the system before it can be used.
Breakpoints that you set in the editor, without changing the source code, come in three kinds in the classic tools:
session breakpoints are valid in all ABAP sessions of the current user session; external breakpoints are valid for other
user sessions too, even after the current session ends, which suits RFC, ICF and APC calls; and debugger breakpoints are set
inside the running debugger and can be saved as external breakpoints. A breakpoint in a SELECT loop can raise an
exception, because a database commit may happen during debugging and the database cursor is lost.
The statement LOG-POINT ID group is a quieter relative. When its checkpoint group is active, it writes an entry
into a log, with the values you list after FIELDS, and the program continues without stopping. You evaluate the log
with transaction SAAB. Logpoints are meant for tests: there is no API to read the logged data, so they are not suitable
for general logging. Besides these static logpoints you can define dynamic logpoints with transaction SDLP or in ADT.
Reading a short dump
When a program meets an uncaught exception, an exit message or a failed ASSERT, it ends with a runtime error and
ABAP writes a short dump. A short dump holds a description of the error and its likely cause, an excerpt of the source
code at the place of the error, and a table of variables and their values.
In ADT, a dialog appears at the bottom right when a program that you ran ends with a runtime error. Choose Show to
open the ABAP Runtime Error Viewer. You can open the same viewer by double-clicking the entry in the Feed Reader view,
which by default has one feed for runtime errors caused by you and one for objects you are responsible for, or from
the failure trace of an ABAP Unit run. The viewer has a Summary tab (header, error analysis, the place where the program
terminated, a source extract with the failing line highlighted, and the active calls), a Long Text tab in the familiar
format of transaction ST22, and an Unformatted Display tab for special cases. The viewer is supported as of SAP S/4HANA
1809.
In classic systems, the dump analysis is started with transaction ST22 in SAP GUI. It lists the runtime errors and gives access to their short dumps.
Because the program context still exists while the dialog is shown, a program that you started from ADT and that ended
with a dump can be examined in the post-mortem debugger: choose Debug in the dialog. You cannot step any more, but all
variables and runtime information at the moment of the error are available. The post-mortem debugger is offered only for a program that you started from ADT.
All of this requires an SAP system; not run here.
When the problem is speed: ABAP Profiler and SAT
A debugger answers why a result is wrong. It does not tell you why a program is slow. The ABAP Profiler measures the run time of transactions, programs, function modules, classes and Web Dynpro applications, and its result, the ABAP trace, shows which statements use the most time and how the calls are nested. SAP calls it the successor of the Runtime Analysis toolset, which is transaction SAT, and recommends it from SAP NetWeaver 7.4 SP2 on. On back ends older than 7.0 EHP3 you use transaction SAT in the embedded SAP GUI instead. SAP also notes that, to analyze or compare program flow, the profiler can be faster than stepping with the debugger.
To measure a program in ADT, choose Profile As > ABAP Application (or ABAP Application (Console) or
ABAP Unit Test) from the editor or the Project Explorer, then open the new trace in the ABAP Traces view of the
ABAP Profiling perspective. You can also let the profiler measure only a section: start the profiler wizard with
Run > Profile ABAP Development Object... (Alt+F9), choose Explicitly switch on and off for when the trace should
start, and then use Switch ABAP Trace On and Switch ABAP Trace Off on a breakpoint in the debugger. The profiler
switches off by itself when the program ends. SQL trace and code pushdown are measured with the same family of tools and belong
to a page of their own on performance.
Source: ADT user guide: Profiling ABAP Code, Launching Profiler for an ABAP Development Object and Starting and Stopping the ABAP Profiler in the Debugger
Requires an SAP system; not run here.
Debugging database procedures: the AMDP debugger
Code of an ABAP Managed Database Procedure (AMDP), of a CDS table function and of GraphScript does not run in ABAP but in the SAP HANA database, so the ABAP Debugger cannot step through it. For that, ADT has a separate AMDP Debugger. It is part of the ADT client and offers activation and deactivation, breakpoints, stepping, viewing variables and viewing table contents. SAP states the prerequisites per feature: for AMDPs SAP NetWeaver 7.5 SP00 or higher and SAP HANA DB SPS9 or higher; for CDS table functions SAP NetWeaver AS for ABAP 7.51 innovation package SP00 or higher and SAP HANA DB SPS11 or higher. AMDP itself is explained on Native SQL, ADBC and AMDP.
Requires an SAP system on SAP HANA; not run here.
Older material you may meet
The book Complete ABAP (SAP PRESS, 1st edition 2016, written for SAP NetWeaver AS ABAP 7.4 and 7.5) devotes its debugging chapter to the classic debugger in SAP GUI, with separate views for fields, tables, breakpoints, watchpoints, calls, overview and settings, then a "new" debugger, with the ADT and AMDP debuggers only briefly. That order is now reversed. Today ADT is the main tool for new work, and the SAP GUI debugger is kept for the special cases in the table above. Book screenshots of the SAP GUI debugger therefore do not match what ADT shows, although the ideas (breakpoint, watchpoint, step, variable view) are the same. The publisher page is Complete ABAP (SAP PRESS).
Summary
-
A debugger stops a program at a breakpoint so that you can read real values and step through the code; use it when a result is wrong.
-
In ADT, breakpoints are external user breakpoints by default and work for HTTP and RFC calls of your user; line breakpoints are static, while statement, exception and message breakpoints are dynamic and soft by default.
-
A condition limits a breakpoint to the cases you care about, and a watchpoint stops when one variable changes; a watchpoint lives only as long as its debug session.
-
A runtime error leaves a short dump, which you read in the ABAP Runtime Error Viewer of ADT or in transaction ST22, and a program started from ADT can be examined in the post-mortem debugger.
-
BREAK-POINTandLOG-POINTare classic statements for tests; they do not belong in production code. -
For slow code use the ABAP Profiler (successor of transaction SAT), and for code that runs in SAP HANA use the AMDP debugger.