ABAP Debugger Demystified
Hi All, I am going to focus on the ABAP debugger here. The first time I looked at the code base which was running on the ABAP debugger I didn’t know how to proceed or make sense of what I was debugging. Initially the debugger itself seemed mysterious with so many controls and tabs and for a beginner the debugger can be quite intimidating. With the help of few good tutorials and helpful colleagues I have managed to befriend the intimidating debugger. I was recently involved in a performance improvement topic in my job. My task was to understand the existing code base and to replicate that existing behaviour using object oriented ABAP and the super fast SAP HANA. Understanding the existing code base improved my debugging skills and I am here to share that knowledge with you.
Starting the debugger
There are 5 ways in which the debugger can be launched
- Write the statement “BREAK-POINT” in the code. On execution the debugger will start and line of execution will start from this statement.
- From the object navigator, choose the program that you wish to debug and choose the context menu, select execute and then select debugging. This will start the debugger and line for execution will be the first executable line in the code.
- From the editor area of the program, Select the line which you want to debug and set the breakpoint( either a session breakpoint or external breakpoint) and execute the program. This will start the debugger and line for execution will be the selected line where the breakpoint was set.
- From the editor area of the program, choose menu path System, then utilities, then Debugging ABAP (screen). This will start the debugger and the line of execution will be the first executable line in the code.
- Enter “\h” in the command field and start executing. This will start the debugger from the first executable line in the code.
Line of execution: This will have a little golden arrow mark and from there we can execute line by line or jump a few statements forward or even jump backwards!
External / User breakpoint: In case we want to debug as a specific user, we can set the User breakpoint for that specific user in Utilities select tab debugging and giving the sy-uname of that user. This is usually done if you are debugging back end code and you have logged in as a specific user in the webdynpro screen in the front end.
Session breakpoint: this breakpoint will get hit for all users. We can toggle the breakpoints between session and user breakpoint.
There are two types of debuggers, the classical debugger and the new debugger.
The classical debugger just shows the code with the blue arrow showing which line is being executed. It doesn’t have the tabs. It has fields and we can see the contents of 8 variables. It is a simple looking debugger and it available for SAP Web AS releases less than 6.40. The classic debugger runs on the same roll area as the application that is analysed and hence doesn’t start a new session. This is how it looks.
There are four buttons on the top which defines how to execute code in the debugging mode. The single step button also executed with the help of “F5” function key will execute each line of code. The Execute button also executed with the help of “F6” function key executes a call and returns if is executing a form or method. The Return button also executed with “F7” function key returns from the current function call to the calling function in the call stack. The Continue button or “F8” function key continues the execution until it meets another breakpoint or till the end of the program. In order to jump a few lines of code either forward or backwards, click on the line that you want to execute and then say “Shift + F12”. In order to execute the current set of lines and then jump forward to a selected line use “Shift + F8”, this is to have the same behaviour as that of a breakpoint but without actually having one.
Releases after the SAP AS 6.40 the New debugger along with the Classic debugger is available. We can switch from the New debugger to Classic Debugger by choosing Goto, then Navigate to , then Switch to Classic Debugger.
The features of New debugger include having different desktop views with different ways to see code and the variables that we are viewing. We can set the step size to execute. The program name along with line number and the status of system variable like sy-subrc and sy-tabix is visible on the header of the debugger. It has different tabs and we can see the data in the variables in those tabs. The New debugger looks like this
We can display data contents of a variable by entering the name of the variable or by double clicking the variable and that can be seen in the variable tab. We can set a breakpoint with a single click before the line in the source code. The set breakpoints are valid till the current debugging session ends, to have some persistence for the next debugging session we can choose the Save button, then the breakpoints will persist for the duration of current entire SAP session. The New debugger opens in a separate session. We can create value comparison of strings, structures and internal tables in the New debugger. The New debugger has automated debugging-debugger scripting, enhanced web dynpro and table tool.
These are the tabs available in the New debugger.
There are 3 user specific desktops which are customizable and can be saved as favourite debugger environment. The standard tab shows the standard way of stepping through code. The Structures tab helps in viewing and comparing structures. Tables tab helps in viewing and comparing internal tables. Objects tab helps in viewing the object details. DetailDisplay is to compare strings, simple fields. Data Explorer tab helps in displaying variable contents and data objects in a tree structure, this enables hierarchical display of deep structures, tables and objects of an ABAP program in the Debugger. The Break./Watchpoints tab helps us view the breakpoints that are set and the watchpoints that are created. The Diff tab helps us compare two compatible objects by providing differences concerning type and value. The Script tab we can write debugger scripts.
Watchpoints are breakpoints that depend on field content. On setting a watchpoint on a variable, the debugger executes until the value of the variable has changed. We can set a relational operator and comparative value for the field and the debugger will execute until the comparative value is reached by the field. This is helpful when you are debugging for large data sets. We can set the watchpoint on sy-tabix value as say 1,50,000 and once that point has reached we can debug further. Watchpoints are like dynamic breakpoints and are user specific. It will not affect other users using the system.
Debugging can seem like a tedious task but like all things practice make perfect. Hope I have helped hone some of your debugging skills. See you next time…