7 Debugging an ABAP Program

Learning

/Browse/Courses/Learning Basic ABAP Programming/Debugging an ABAP Program

Debugging an ABAP Program

Objectives

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.

Note

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

Demo

Start Demo

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!

Terminate

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.

Watchpoints

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

Demo

Start Demo

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

Demo

Start Demo

Debug ABAP Code

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

Template:

/LRN/CL_S4D400_BTT_DEBUG (global Class)

Solution:

None, the class remains unchanged.

Task 1: Preparation

Copy the class that you want to debug.

Steps

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

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

Enter /LRN/CL_S4D400_BTT as search string.

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

Link the Project Explorer view with the editor.

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.

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

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

From the context menu, choose Duplicate ....

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.

Confirm the transport request and choose Finish.

Activate and test the class.

Press Ctrl + F3 to activate the class.

Press F9 to run the class.

Check the output in the Console view.

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

If the Console view is not visible, open it by choosing Window→Show view→Other. 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.

Steps

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

Hint

TYPES defines a data type, CONSTANTS declares a constant data object, DATA declares a variable data object.

Double-click the left-hand margin of the editor next to the line loan_remaining = loan_total.to set a break point.

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

Press F9 to run the class.

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

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

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

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.

Steps

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

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

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

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.

In the next code line, double-click spec_repay_mode.

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

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

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

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

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.

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

Note

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.

Double-click on repayment_plan at the end of the APPEND statement.

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

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.

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

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.

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

Press F8 to resume program execution.

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

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

Navigate to the Breakpoints view.

Hint

You find the Breakpoints view next to the Variables view.

In the toolbar of the Breakpoints view, expand the dropdown button on the very left and choose Add Statement Breakpoint ....

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

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

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

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.

Press F8 to resume program execution.

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

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

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.

Note

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.

Press F6 several times until you reach the end of the application.

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

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

Choose ABAP on the very right of the Eclipse toolbar.

Log in to track your progress & complete quizzes

Log in

Register

Was this lesson helpful?

Yes

No

Continue to quiz

Learning

Quick links

Learning Support

About SAP

Site Information

Learning /Browse/Courses/Learning Basic ABAP Programming/Debugging an ABAP Program Debugging an ABAP Program Objectives 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

Debugging is a crucial process in software development for identifying and resolving errors (bugs) in code. In ABAP, the debugging mode allows developers to execute a program step-by-step, inspect the values of variables, and observe the program's flow at runtime. This helps in understanding the program's behavior, tracking down causes of unexpected output, or verifying logic. 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. Note 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. Key views often include:

  • Variables View: Displays the current values of all local and global variables.

  • Breakpoints View: Manages all active and inactive breakpoints.

  • Editor View: Shows the source code with the currently executing line highlighted.

  • Debug Stacks View: Provides the call stack, showing the sequence of method calls that led to the current execution point.

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

How To Start The Debugger Demo Start Demo

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!

  • Terminate 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.

Watchpoints

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 Demo Start Demo

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

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 Demo Start Demo

Debug ABAP Code

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

Template: /LRN/CL\S4D400\BTT\_DEBUG (global Class)

Solution: None, the class remains unchanged.

Task 1: Preparation

Copy the class that you want to debug.

Steps

  1. Open the source code of global class /LRN/CL\S4D400\BTT\DEBUG in the ABAP editor. In the Eclipse toolbar, choose Open ABAP Development Object. Alternatively, press Ctrl + Shift + A. Enter /LRN/CL\S4D400\BTT as search string. From the list of development objects choose /LRN/CL\S4D400\BTT\DEBUG, then choose Ok.

  2. Link the Project Explorer view with the editor. 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). In the Project Explorer view, right-click class /LRN/CL\S4D400\BTT\DEBUG to open the content menu. From the context menu, choose Duplicate …. 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. Confirm the transport request and choose Finish.

  4. Activate and test the class. Press Ctrl + F3 to activate the class. Press F9 to run the class. Check the output in the Console view. Check the Console view that should have opened as a new tab below the editor view. If the Console view is not visible, open it by choosing Window→Show view→Other. 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.

Steps

  1. Set a breakpoint at the first statement that does not define a type or declare a data object. Hint TYPES defines a data type, CONSTANTS declares a constant data object, DATA declares a variable data object. Double-click the left-hand margin of the editor next to the line loan\remaining = loan\total.to set a break point.

  2. Run the class as a console app and enter the debugger. Press F9 to run the class. 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. In the current code line (the one with a green background) double-click loan\remaining. 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.

Steps

  1. Execute a single step to debug the value assignment in the current line. In the toolbar, choose Step Into (F5) or press F5. 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. In the next code line, double-click spec\repay\mode. 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? In the Variables view, right-click on LOAN\REMAINING and choose Set Watchpoint. In the toolbar, choose Resume (F8) or press F8. 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. Note 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. Double-click on repayment\plan at the end of the APPEND statement. 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. 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. In the Variables view, right-click on REPAYMENT\PLAN and choose Set Watchpoint. Press F8 to resume program execution. 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. Navigate to the Breakpoints view. Hint You find the Breakpoints view next to the Variables view. In the toolbar of the Breakpoints view, expand the dropdown button on the very left and choose Add Statement Breakpoint …. On the dialog window that appears, enter EXIT as search string, click on the value EXIT in the hitlist, and choose OK. In the Breakpoints view, right-click the watch point LOAN\REMAINING and choose Remove. 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. Press F8 to resume program execution. Switch to the Breakpoints view and deselect the line that says EXIT [Statement]. Press F5 until you reach the first code line that starts with out->write(. 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. Note 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. Press F6 several times until you reach the end of the application. Analyze the addition output on the Console view and compare it to the string template in the previous code line. When the application is terminated, do not forget to switch back to the ABAP perspective. Choose ABAP on

Learning /Browse/Courses/Learning Basic ABAP Programming/Debugging an ABAP Program Debugging an ABAP Program Objectives 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

Debugging is a crucial process in software development for identifying and resolving errors (bugs) in code. In ABAP, the debugging mode allows developers to execute a program step-by-step, inspect the values of variables, and observe the program's flow at runtime. This helps in understanding the program's behavior, tracking down causes of unexpected output, verifying logic, and even analyzing performance bottlenecks. 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. Strategic breakpoint placement, such as before critical data modifications, after input validations, or at the entry points of complex function modules, is key to efficient debugging. 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. Note 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. Key views often include:

  • Variables View: Displays the current values of all local and global variables, allowing you to monitor data changes.

  • Breakpoints View: Manages all active and inactive breakpoints, providing a central place to control where the program execution pauses.

  • Editor View: Shows the source code with the currently executing line highlighted, offering immediate context.

  • Debug Stacks View: Provides the call stack, showing the sequence of method calls that led to the current execution point, which is crucial for understanding program flow in complex applications.

Users can also customize the layout of these views to suit different debugging scenarios. Let's look at some important elements of the debugger perspective.

How To Start The Debugger Demo Start Demo

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, particularly beneficial when you want to dive deep into a method call or a function to inspect its internal logic.

  • Step Over (F6) Choose Step Over or press F6 to execute a single step, stepping over method calls or function executions without entering them. This is useful for skipping known-good code blocks or library functions that you don't need to debug in detail.

  • Step Return (F7) Choose Step Return or press F7 to execute the rest of the current method or function and stop at the statement immediately after the call to that method/function. This is a quick way to exit a function you've stepped into and return to the caller's context.

  • 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. Use this to quickly advance through large sections of code until a critical point is reached.

  • 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, especially when you know exactly where you want the execution to stop next within the current scope.

  • 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, to re-execute a section of code to observe a different outcome, 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!

  • Terminate 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. This is extremely useful for finding all occurrences or usages of a particular ABAP command across an entire application without needing to set individual line breakpoints. 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. This is invaluable for developing robust error handling, as it allows you to catch and analyze the root cause of any exception immediately, even if a TRY...CATCH block is missing or incorrectly implemented. 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. This is particularly powerful for debugging loops or processing internal tables where you only want to stop when a specific data condition is met, for example, sy-index > 20 to debug after the 20th iteration, or when a variable holds a specific value. 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.

Watchpoints

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. Unlike conditional breakpoints which halt execution at a specific line if a condition is true, watchpoints pause execution anytime a specified variable's value changes, regardless of the program line. This is ideal for pinpointing exactly where and when an undesirable change to a critical data object occurs, which is especially useful in complex programs with many data modifications. Watch this video to see how. How To Control The Execution Of Code Demo Start Demo

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

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. This functionality is extremely powerful for testing different scenarios without having to restart the program, such as simulating various user inputs, bypassing certain authorization checks for testing specific logic, or forcing error conditions to test the application's error handling. 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 Demo Start Demo

Debug ABAP Code

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

Template: /LRN/CL_S4D400_BTT_DEBUG (global Class)

Solution: None, the class remains unchanged.

Task 1: Preparation

Copy the class that you want to debug.

Steps

  1. Open the source code of global class /LRN/CL_S4D400_BTT_DEBUG in the ABAP editor. In the Eclipse toolbar, choose Open ABAP Development Object. Alternatively, press Ctrl + Shift + A. Enter /LRN/CL_S4D400_BTT as search string. From the list of development objects choose /LRN/CL_S4D400_BTT_DEBUG, then choose Ok.

  2. Link the Project Explorer view with the editor. 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). In the Project Explorer view, right-click class /LRN/CL_S4D400_BTT_DEBUG to open the content menu. From the context menu, choose Duplicate …. 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. Confirm the transport request and choose Finish.

  4. Activate and test the class. Press Ctrl + F3 to activate the class. Press F9 to run the class. Check the output in the Console view. Check the Console view that should have opened as a new tab below the editor view. If the Console view is not visible, open it by choosing Window→Show view→Other. 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.

Steps

  1. Set a breakpoint at the first statement that does not define a type or declare a data object. Hint TYPES defines a data type, CONSTANTS declares a constant data object, DATA declares a variable data object. Double-click the left-hand margin of the editor next to the line loan_remaining = loan_total.to set a break point.

  2. Run the class as a console app and enter the debugger. Press F9 to run the class. 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. In the current code line (the one with a green background) double-click loan_remaining. 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.

Steps

  1. Execute a single step to debug the value assignment in the current line. In the toolbar, choose Step Into (F5) or press F5. 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. In the next code line, double-click spec_repay_mode. 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? In the Variables view, right-click on LOAN_REMAINING and choose Set Watchpoint. In the toolbar, choose Resume (F8) or press F8. 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. Note 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. Double-click on repayment_plan at the end of the APPEND statement. 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. 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. In the Variables view, right-click on REPAYMENT_PLAN and choose Set Watchpoint. Press F8 to resume program execution. 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. Navigate to the Breakpoints view. Hint You find the Breakpoints view next to the Variables view. In the toolbar of the Breakpoints view, expand the dropdown button on the very left and choose Add Statement Breakpoint …. On the dialog window that appears, enter EXIT as search string, click on the value EXIT in the hitlist, and choose OK. In the Breakpoints view, right-click the watch point LOAN_REMAINING and choose Remove. 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. Press F8 to resume program execution. Switch to the Breakpoints view and deselect the line that says EXIT [Statement]. Press F5 until you reach the first code line that starts with out->write(. 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. Note 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. Press F6 several times until you reach the end of the application. Analyze the addition output on the Console view and compare it to the string template in the previous code line. When the application is terminated