Debugging an ABAP Program


After completing this lesson, you will be able to:

  • Enter debugging mode
  • Control the execution of code
  • Analyze the content of data objects

The Debugging Mode

Watch this video to understand the need for debugging.

Starting the Debugger

To debug an ABAP program, you set a breakpoint then run the program normally. When the program reaches the breakpoint, the system interrupts it and opens the ABAP Debug perspective in ADT. You can then execute each subsequent statement individually to see what effect it has on the program. You can also inspect the contents of all of the variables in the program to see if any of the values are unexpected.

To set or remove a breakpoint, right-click the left margin of the editor and choose Toggle Breakpoint. As an alternative you can double-click the left margin. Note that the program has to be activated before you can set breakpoints.

Breakpoints are user-specific and are persistent - they remain active even after you have logged off from ADT and back on again. To prevent the debugger from starting at a breakpoint you must either delete the breakpoint (using the Toggle Breakpoint function) or deactivate it using the corresponding function in the context menu.

Depending on your personalization settings, ADT will ask for confirmation, first, before automatically opening the debug perspective.

The Debug Perspective in ADT

When you debug an ABAP program using ABAP Development Tools, 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.

Let's look at some important elements of the debugger perspective.

How To Start The Debugger

Control of Code Execution

Some Navigation Functions

Once you started debugging, use the navigation functions to control the execution of the code.

Some important navigation functions are as follows:

Step Into (F5)

Choose Step Into or press F5 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 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 Shift+F8 to execute the program up to the current cursor position. Clicking on 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 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 analysis the first time. Keep in mind that this is actually jumping, not executing coding. When you jump backwards, changes to data objects are not reverted!


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

Special Breakpoints

You learned that you can create and manage breakpoints by clicking on the left margin of the ABAP editor view. This also works with the ABAP editor view in the Debug perspective.

In addition, you can switch to the Breakpoints view and manage your breakpoints there.

In the Breakpoints view you can also create special breakpoints:

Statement Breakpoint

A statement breakpoint is not attached to a specific line of code but to a specific ABAP statement. A statement breakpoint on statement CLEAR, for example, causes the program to stop in the debugger whenever a CLEAR statement is executed - no matter where this statement is located.

To create a statement breakpoint, open the dropdown list from the toolbar of the Breakpoints view and choose Add Statement Breakpoint …

Exception Breakpoint

An exception breakpoint is attached to a specific exception. It causes the program to stop in the debugger whenever this particular exception is raised - no matter if this exception is handled by the program or causes a runtime error. To create an exception breakpoint, open the dropdown list from the toolbar of the Breakpoints view and choose Add Exception Breakpoint … .

Conditional Breakpoint

You turn a breakpoint into a conditional breakpoint by adding a condition. If program execution hits a conditional breakpoint, the program only stops in the debugger, if the condition is fulfilled. If, for example, a breakpoint is located between DO and ENDDO it will cause the program to stop in the debugger in every iteration. But if you add a condition sy-index > 20 the debugger will ignore this breakpoint during the first 20 iterations and only stop in the following iterations.

To add a condition to a breakpoint, choose it in the list of breakpoints and enter the condition in field Condition. Press Enter to save the breakpoint with the condition.


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

Watch this video to see how.

How To Control The Execution Of Code

Analysis of Data Objects

Display Content of Data Objects

Watch this video to learn how to display the content of data objects in the debugger.

Display Content of Internal Tables

Watch this video to learn how to display the content of internal tables.

Changing the Values of Variable

Depending on your authorizations, you can change the value of variables during debugging.

For simple variables, locate the variable in the Variables view, right-click on it and choose Change Value ….

To change the content of an internal table, we have to distinguish between changing the value of an existing row and adding or deleting of a rows.

As shown in the figure, the following functions are available when you right-click in the ABAP internal table view:

Change Value …
Choose Change Value …. to change the content of an existing row.
Insert Row …
Choose Insert Row …. to add a new row. You can decide whether you want to append the new row or insert it at the chose position.
Delete Selected Rows …
Choose Delete Selected Rows … to remove the rows you selected before you right-clicked. To select a row, left-click it. To select more than one row, hold down the Ctrl key or the Shift key when you left-click additional rows.
Delete Rows …
Choose Delete Rows …to remove a larger range of rows, or even all rows. You are asked for the number of the start row and the end row you want to delete.

How To Analyze The Contents Of Data Objects

Debug ABAP Code

In this exercise, you analyze ABAP code using the ABAP debugger.


  • /LRN/CL_S4D400_BTT_DEBUG (global Class)


  • None, the class remains unchanged.

Task 1: Preparation

Copy the class that you want to debug.


  1. Open the source code of global class /LRN/CL_S4D400_BTT_DEBUG in the ABAP editor.

    1. In the Eclipse toolbar, choose Open ABAP Development Object. Alternatively, press Ctrl + Shift + A.

    2. Enter /LRN/CL_S4D400_BTT as search string.

    3. From the list of development objects choose /LRN/CL_S4D400_BTT_DEBUG, then choose Ok.

  2. Link the Project Explorer view with the editor.

    1. In the Project Explorer toolbar, find the Link with Editor button. If it is not yet pressed, choose it. As a result, the development object, that is open in the editor, should be highlighted in the Project Explorer.

  3. Copy class /LRN/CL_S4D400_BTT_DEBUG to a class in your own package (suggested name: ZCL_##_DEBUG, where ## stands for your group number).

    1. In the Project Explorer view, right-click class /LRN/CL_S4D400_BTT_DEBUG to open the content menu.

    2. From the context menu, choose Duplicate ....

    3. Enter the name of your package (ZS4D400_##, where ## stands for your group number) and the name for the new class (ZCL_##_DEBUG), then choose Next.

    4. Confirm the transport request and choose Finish.

  4. Activate and test the class.

    1. Press Ctrl + F3 to activate the class.

    2. Press F9 to run the class.

  5. Check the output in the Console view.

    1. Check the Console view that should have opened as a new tab below the editor view.

    2. If the Console view is not visible, open it by choosing WindowShow viewOther. Double-click Console in the hit list.

Task 2: Analyze the Starting Values

Enter the debugger at the first executable statement in method if_oo_adt_classrun~main( ) and analyze the values of some variable and constant data objects.


  1. Set a breakpoint at the first statement that does not define a type or declare a data object.

    TYPES defines a data type, CONSTANTS declares a constant data object, DATA declares a variable data object.
    1. Double-click the left-hand margin of the editor next to the line  loan_remaining = set a break point.

  2. Run the class as a console app and enter the debugger.

    1. Press F9 to run the class.

    2. If you are asked whether you want to switch to the Debug perspective, mark Remember my decision and choose OK.

  3. Display the value of data object loan_remaining and loan_total in the Variables view.

    1. In the current code line (the one with a green background) double-click loan_remaining.

    2. In the same code line, double-click loan_total.

Task 3: Control Program Execution

Set break points and watch points. Execute single steps or resume execution until the next break point or watch point is reached. Supervise the value changes of the data objects.


  1. Execute a single step to debug the value assignment in the current line.

    1. In the toolbar, choose Step Into (F5) or press F5.

    2. Check that the value of loan_remaining changed from 0..00 to 5000.00.

  2. Display the content of data object spec_repay_mode. Then execute another single step to see which WHEN branch of the CASE - control structure is executed.

    1. In the next code line, double-click spec_repay_mode.

    2. Press F5 to see that the program jumps to code line WHEN 'Q'..

  3. Set a watch point for variable loan_remaining and resume program execution. Where does the program execution stop again?

    1. In the Variables view, right-click on LOAN_REMAINING and choose Set Watchpoint.

    2. In the toolbar, choose Resume (F8) or press F8.

    3. Program execution stops immediately after code line loan_remaining = loan_remaining - repayment_month., also to be precise, in the next code line with executable code.

  4. Display the content of data object repayment_plan. Then execute another single step to see how it is filled with the APPEND statement.

    Because repayment_plan is an internal table, it not only displays in the Variables view but also in the ABAP Internal Table (Debugger) view below the editor.
    1. Double-click on repayment_plan at the end of the APPEND statement.

    2. Press F5 to see how repayment_plan is filled with a first row.

  5. Inspect the string template in the APPEND statement and relate it to the resulting first row in internal table repayment_plan. Display the content of the data objects that appear in the embedded expressions.

    1. Double-click the data objects that appear between the curly brackets to display their contents.

  6. Set another watch point for variable repayment_plan and resume program execution for a few times. Whenever execution reaches one of the watch points, analyze the value of loan_remaining and new rows are added to repayment_plan.

    1. In the Variables view, right-click on REPAYMENT_PLAN and choose Set Watchpoint.

    2. Press F8 to resume program execution.

    3. Analyze the data objects in the Variables view and the ABAP Internal Table (Debugger) view.

  7. After a while, set a statement break point for all EXIT statements and delete the two watch points.

    1. Navigate to the Breakpoints view.

      You find the Breakpoints view next to the Variables view.
    2. In the toolbar of the Breakpoints view, expand the dropdown button on the very left and choose Add Statement Breakpoint ....

    3. On the dialog window that appears, enter EXIT as search string, click on the value EXIT in the hitlist, and choose OK.

    4. In the Breakpoints view, right-click the watch point LOAN_REMAINING and choose Remove.

    5. In the Breakpoints view, right-click the watch point REPAYMENT_PLAN and choose Remove.

  8. Resume program execution until you reach the first EXIT statement. Deactivate the statement breakpoint for the EXIT statement. Then execute single steps until you reach the output part of the program.

    1. Press F8 to resume program execution.

    2. Switch to the Breakpoints view and deselect the line that says EXIT [Statement].

    3. Press F5 until you reach the first code line that starts with out->write(.

  9. Open the Console view. Execute the remaining program and pursue the output on the console view.

    Do not press F5 to debug the output. Use F6 instead.
    As you will learn later in the course out->write( ... ) is not an ABAP statement but a reusable code block that consists of many ABAP statements. By pressing F5 you Step Into this code to analyze it in detail. With F6 you Step Over the code block, treating it like a single statement.
    1. Press F6 several times until you reach the end of the application.

    2. Analyze the addition output on the Console view and compare it to the string template in the previous code line.

  10. When the application is terminated, do not forget to switch back to the ABAP perspective.

    1. Choose ABAP on the very right of the Eclipse toolbar.

Log in to track your progress & complete quizzes