Debugging an ABAP Program

After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Identify and correct problems in an ABAP application using the Debug perspective
  • Use watchpoints in the ADT in Eclipse

Start using ABAP Debugger

The Debugger in the ADT is an important diagnostic tool that you can use to analyze an ABAP application.

With the Debugger, you can determine why a program is not working correctly by stepping inside the program at runtime. This allows you to see the statements being executed and the changing value of values of variable as the program proceeds.

To use the Debugger, you first decide where to start the Debug process. One way is to set breakpoints in the source code, run you program and stop at that set breakpoint.

Some of the features in the Debugger that are available are as follows:

Features of the ADT Debugger

FeatureADT Debugger
Setting BreakpointsYes
WatchpointsYes (Depending on release)
Conditional breakpointsYes
Stepping through codeYes
Displaying variable valuesYes
Analyzing internal tablesInternal table rows can be displayed and edited in the ABAP Internal Table view, but the view can be customized.
Displaying structuresStructures can be displayed by field, but the view cannot be customized.
Displaying objectsStructured display of object contents is supported, but the capabilities for customizing the data display of the Objects tool are not offered.
Comparing data objectsnot for complex data objects
Analyzing memory useNo
Debugger scriptingNo
Change debugger settingsYes
Direct editing of code in the debuggerYes

Debug an ABAP Program using ADT

When you debug an ABAP Program using ADT, you use the Debug perspective. This is a customized version of the standard Eclipse Debug perspective, and it contains views and functions that are particularly important for debugging.

Some important elements of the debugger perspective are as follows:

Source Code View

The Source Code view is the central part of the debugger perspective. It displays the source code and highlights the current position in the program.

Variables View

The Variables view is also very important. You use this view to display the current values of variables of variables.

Breakpoints View

The Breakpoints view is displayed next to the Variables view (not selected in the preceding figure, Debug Perspective). You use this view to display, delete or create breakpoints. Breakpoints are points in the program at which normal processing is interrupted and the system shows you the Debugger so that you can analyze the state of the program at exactly that moment.

Navigation Functions

While you are debugging a program, you use the navigation functions to control the execution of the code.

Debug View

The Debug view on the upper left shows the debugging session and the call hierarchy. You will need this later when you debug calls of modularization units, for example, methods.

Perspective Selector

You can switch back to the ABAP perspective with the Perspective Selector buttons in the upper right corner.

Controlling the Execution of the Code

Some Navigation Functions

When you start debugging, use the navigation functions to control the execution of the code.

Some important navigation functions follow:

Step Into (F5)

Choose Step Into or press F5 on your keyboard to execute a single step. Use this function for a step-by-step analysis. If, for example, you want to see which code block of a control structure is actually executed.

Resume (F8)

Choose Resume or press F8 on your keyboard to execute the program up to the next breakpoint.  If the debugger does not hit any more breakpoints, the program is executed to the end and the debugging session terminates.

Run to Line (Shift+F8)

Choose Run to Line or press Shft+F8 on your keyboard to execute the program up to the current cursor position. Choosing a code line and choosing this function is a convenient alternative to setting a breakpoint, choosing Resume and removing the breakpoint again.

Jump to Line (Shift+F12)

Choose Jump to Line or press Shift+F12 on your keyboard to skip some lines of code or to jump backwards to some already executed code. This function can be helpful to simulate what would happen if a certain piece of code was removed or to repeat debugging a bit of code you missed analyzing the first time. Keep in mind that this is jumping, not executing the code. When you jump backwards, changes to the data objects are not reverted.


Choose Terminate (red box icon) if you are done with debugging and you do not want to execute the remaining program. The debug session terminates immediately.


If an unexpected value of a variable is causing you problems, you can track its value during the course of the program execution using a Watchpoint.

A simple Watchpoint on a variable causes the program to stop in the debugger whenever the value of this variable changes. By adding a condition, the program does not stop at every value change of the variable, but only in those cases where also the condition is fulfilled.

To set a Watchpoint on a variable, only while in the debugger, highlight the variable in the source code, then right-click on it and choose Set Watchpoint. This creates a Watchpoint on the variable, which you can see in the Breakpoints view.

Select the Watchpoint variable to add a condition to a Watchpoint, choose it in the list of Breakpoints and enter the condition in the Condition field. Press Enter on your keyboard to save the Watchpoint with the condition.

To remove the Watchpoint, go to the Breakpoints view, right-click on the Watchpoint variable, and choose Remove.

Create an ABAP Application

Business Example

We will now look at how to create an ABAP application. As prerequisite we need a package and a class if you don't have please create them.


  1. Create a new class.

    1. Right-click on your package.

    2. Choose NewABAP Class.

  2. Name a program and add a description.

    1. In the Name field, enter ZCL_S4D100_00_DEBUG.

    2. In the Description field, enter Debug Program.

    3. Choose Next.

    4. Select the Transport request and choose Finish

  3. Define the interface in the public section.

    1. Define the interface in the PUBLIC SECTION: IF_OO_ADT_CLASSRUN.

  4. Add code to the program and activate it.

    1. Add the following code to the program

      This example program code has a SELECT, IF-ENDIF logic and a WRITE statement.

    2. Activate the program: to do this, choose F9 on your keyboard.

  5. In the code block, you can use OUT->WRITE(  |No data found!| ).| to display information in the console. The line OUT->WRITE(  ls_airport  ). This prints the Airport ID that is used in the SELECT statement to the console. You do not have to know how it works; you just have to type it in the code. This ensures the following:

    • There is no space between the write and the opening parenthesis
    • There is at least one space after the opening parenthesis
    • There is at least one space before the closing parenthesis
    • There is a period at the end of the line
  6. Run the application and clear console:

    1. Run the application, press F9 on your keyboard.

    2. Select the Clear Console button in the top-right row to clear the console contents.


How to Debug a Program and Set a Watchpoint

Business Exercise

We will now look at how to set a breakpoint and create a watchpoint. There are a couple of different ways to set a breakpoint in the application program.


  1. Set a breakpoint in line 12 and line 17.

    1. To set a breakpoint at Line 12, double-click to the left of the column number of the line of code.

    2. Right-click to the left of the column number and choose Toggle Breakpoint to set a breakpoint at Line 17.

      Starting the Debugger here allows you to follow the program logic from start to finish. To start the Debugger from the ADT editor, press F9 (on your keyboard) or choose the Run Application button.

  2. Open the program, ZCL_09_S4D100_DEBUG, in the ABAP editor (the one that you created in the previous exercise entitled Create an ABAP application).

    1. Open the program, ZCL_09_S4D100_DEBUG.

  3. Set a breakpoint.

    1. Double-click to the left of the column number in the editor of an executable line of code or, right-click to the left of the column number.

    2. Choose Toggle Breakpoint. Try this at lines 12 and 17.

  4. Execute the application program

    1. Execute the application program by pressing F9 (on your keyboard).

      The debugger starts.

    2. Take note that the debugger stops at the first breakpoint and the Debug perspective is displayed.

      You can view the source code, variables, breakpoints, navigation functions (F5, F6, F7, and F8) to step through the ABAP code. The blue arrow and the highlighted line (at Line 12) indicate the statement being processed; the Variables screen area can be used to track how the values of variables change as the program runs.

    3. The toolbar navigation buttons control how the Debugger moves through the code.  Each button in the image below from left to right represents the keyboard functions (F5, F6, F7, and F8).

  5. Step forward with single step navigation.

    1. Step forward with single step navigation by pressing F5 on your keyboard.

      Notice how the variables values change between the breakpoint navigation.

    2. To exit the Debug session and execute the remaining ABAP code, choose Resume (F8 button).

  6. Clear the contents.

    1. Notice the output is displayed in the ABAP console. You can clear the contents by choosing the Clear Console button that is located on the toolbar in the console.

  7. Return to the ABAP editor change the AIRPORT_ID.

    1. Return to the ABAP editor change the AIRPORT_ID value from FRA to ABC (an invalid airport id).

    2. Activate the program.

    3. Remove the breakpoint at Line 17 by double-clicking on it.

  8. Create a watchpoint on a variable.

    1. To create a watchpoint on a variable, you must be in the debugger.

    2. Execute the program by pressing F9 on your keyboard.

    3. Highlight the variable SY-SUBRC and right-click on it, or just right-click on it and choose Set Watchpoint.

      The watchpoint is in the breakpoint view.

    4. Choose the OK button when the dialog popup is displayed.

  9. Select the watchpoint variable in the breakpoint list.

    1. Select the Breakpoints tab.

      At this point, you can add a condition.

    2. Add the condition (= 4) and press Enter (on your keyboard) to save the condition. Make sure you have a space between = and 4.

      The number 4 is set at runtime by the system if there is a problem after executing that line of code (for example: no data found).

  10. Stop the Debugger.

    1. Choose Step Into (F5) and the debugger stops at the watchpoint.

      In the variables view, you will see the SY-SUBRC value equal to 4.


Save progress to your learning plan by logging in or creating an account