In this exercise, you analyze ABAP code using the ABAP debugger.
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.