Monday, 6 January 2014

Debugging SAP ABAP Programs

Debugging SAP ABAP Programs

This chapter will introduce the ABAP debugger, and will introduce some of the tools which can be used to ensure that the programs you create function as intended. It will also show ways to highlight logic bugs in programs that cannot be identified by the syntax checker.

The first step here is to load a program which has been used previously, and which ac-cesses the database table which has been created regarding employee records. If you have been following along with instructions, load program “Z_Employee_List_01” into the ABAP Editor .
The program contains a number of SELECT loops, which in turn write the contents of the table being read to the output screen in several ways, separated by ULINE statements
           
Debugging SAP ABAP Programs

Firstly, on this screen you will notice there is a ‘Debugging’ button in the toolbar (also ac-cessible with SHIFT+F5).
           
Debugging SAP ABAP Programs
Click this with the program name in the program input text box to start a new debugging session. When this opens, a blue arrow should be visible, pointing at the first line of code in the program
Debugging SAP ABAP Programs


An alternative way of starting a debugging session is to display the code itself from the initial screen, select a line of code and set a breakpoint. This is done by, having selected a line, clicking the Stop icon
Debugging SAP ABAP Programs

This sets a breakpoint for that line. When the program is then executed the execution will pause highlighting the line that has the Breakpoint set entering the debugging session. Usually, this is the easiest method to use, as one will often have a good idea of where the
issues in a program are allowing you to focus on specific areas of code straight away, rather than starting from the very beginning of a program as the previous method does
Debugging SAP ABAP Programs

Debugging SAP ABAP Programs

There are two types of breakpoint which can be set in a program. Static (which will be ex-amined later) and dynamic. A dynamic breakpoint is the kind which was used above, and these are only valid for the current session. If one leaves the SAP GUI and returns later, any dynamic breakpoints set will no longer exist. A breakpoint can also be set by double-clicking any statement within the debugging session itself. To then remove these in the session, simple double-click the stop icon appearing adjacent to them
Debugging SAP ABAP Programs

These buttons allow for different modes of the ABAP debugger to be entered. The default mode here is Fields.
The ‘Single step’ button, the first on the left in the row above the modes, also accessible with F5, allows one to go through the code within the debugger line-by-line, or indeed as its name would suggest, single steps. As one presses the button, the blue arrow on the left of the code will move down one line at a time.
The next button along is the ‘Execute’ button, with a shortcut of F6. This allows for inde-pendent sections of code to be executed, such as function modules or forms. This can be very useful. If a program includes existing sections of code already created in an SAP system which are known to be correct, there is no need to debug them. These can then be executed independently, while other parts are debugged to find specific problems.
The next button is the ‘Return’ function (F7). This can be very useful if one forgets to use the ‘Execute’ function. If one goes through the lines of a program step-by-step, using the F5 key to step into a working function module, which may contain many lines of code, it is likely the case that it does not need to be debugged (because you know this function module already exists). Pressing the F5 key endlessly to go through the lines of code here is unnecessary when one wants to step out of this function module and access the parts which require debugging. Using the ‘Return’ button, all of the code within a specific func-tion can be executed, returning to the line of code which calls that function.
The fourth in the row is the ‘Continue’ option (F8). This allows one to continue the pro-gram without going through step-by-step, line-by-line. When this button is pressed, the program executes and the output screen is shown. This button can also be used to just access a selected line of code, where the cursor is positioned. If one positions the cursor in a line of code and presses continue, the blue arrow in the debugger will appear directly next to that line. If you then press continue again, the program will be executed.
The next option in this row of the toolbar is ‘Display list’, accessible with CTRL+F12. This takes you to the output screen as it currently stands within the debug session. Here, the code has been executed to output the result of the first SELECT statement in the program
Debugging SAP ABAP Programs

This function allows you to see the results of the reports whilst the program is in mid-flow.

The last option here is ‘Create watchpoint’ (SHIFT + F8). Watchpoints will be returned to soon.

No comments:

Post a Comment