SAP: ABAP debugger guide

posted in: SAP ABAP 0
ABAP debugger guide
ABAP debugger guide

ABAP debugger : Introduction

I know what you are going to say. Generally speaking, the word "ABAP debugger" can be scary. In fact, what is this barbaric word? In reality, why ABAP debugger and how is it useful?

Actually, it comes from the English "To debug". Well, that doesn't help you much, I bet... OK.

To begin with, which consultant has never been faced with this:

Dump
Dump

Indeed, no doubt that the first time it happens to us, we are a little lost...

When a developer creates a program, despite all the help available, whether it be syntax checks or software checks during compilation, it regularly happens that everything is not perfect, and that certain problems have not been considered.

Thus, it is undeniable that the ABAP debugger is primarily a tool for developers, to help them avoid this kind of messages, which are called "Dump" . Indeed, it is a very important tool that allows to analyze ABAP programs to correct errors.

Nevertheless, we will see together how useful this tool can be for any SAP consultant and especially, we will see how to use it. Effectively, the ABAP debugger can also be used to analyze but especially to understand the already existing programs.

Moreover, it should be noted that SAP offers 2 debuggers: the classic one and its new version. Besides, we will only deal with this new version, available since SAP NetWeaver 2004.

First, let's go to the ABAP debugger interface. There are several ways to access it:

ABAP debugger : Access

Repository Browser
Repository Browser

In order to access it, you have to go to the transaction SE80: Repository Browser. Here you can select a program for example, then do :

  • First of all, right click on the name of the program
  • Then go to the "Run" menu
  • Finally, click on "Debugging".
Job
Job

By going to the SM37 transaction (Job overview), you can search for a job to simulate its execution in debug mode. To do this:

  • The job must be finished
  • Select the job using the check box
  • Enter the command "jdbg" in the transaction bar
  • Press "Enter".
Programs
Programs

Concerning the different programs, methods, module functions, ... it is possible to launch the ABAP debugger by placing a Breakpoint. We will come back to this term a little later but simply, this point will launch the debugger when the program is executed

  • Go to a program of your choice (via repository)
  • Click on the beige column next to the code
  • A small "STOP" sign appears
  • Your Breakpoint is set

The next time the program is run, the debugger will open.

Transactions
Transactions

When you are in a transaction, specify /h and press "Enter".

SAP will then show you the following message:

Debugging switch on
Debugging switch on

ABAP debugger : Layout

So, here we are in our ABAP debugger. It looks like this:

ABAP debugger
ABAP debugger

1. Running the program

In fact, when the program is in "run" mode, a small yellow arrow indicates the current position you are in. It is important to know that at this line, the operation has not yet been executed.

Current position
Current position

Then, to move through the code, there are several ways:

Single Step

The next operation will be executed, then SAP will stop.
Keyboard Shortcut: F5

Execute

The next operation will be executed. Be careful, if the cursor is in front of a block (such as a routine, a module function, etc.), it will be fully executed. SAP will then stop.
Keyboard shortcut: F6

Return

The current block (such as a routine, module function, etc.) will be fully executed. SAP will then return to the code that called the executable block.
Keyboard shortcut: F7

Continue

Process the code until the next Break point / Watchpoint. If there is none / no more, the program will be executed in full and the debugger will close.
Keyboard shortcut: F8

Go to statement

It is possible to move to a specific location in the code. To move the cursor to the desired location, right click on the appropriate operation and choose: Goto Statement. Your cursor will then move to that location.

Goto Statement
Goto Statement

2. The different presentations / desktop

First of all, let's note that SAP offers the user several choices of presentation of the debugger. Indeed, we can distinguish 3 different Desktop, as well as a standard presentation. In fact, SAP will simply arrange the menus in a different way, depending on your choice. Here are 2 examples:

Desktop 1

Desktop 1
Desktop 1

Desktop 3

Desktop 3
Desktop 3

3. Variables area

In order to access the different variables present in the program, SAP offers this work area. Let's take a look at the different menus together:

To begin with, variables can be added to these 2 tables "Variables 1 and 2". Indeed, you just have to double click on the chosen variable and it will appear:

Tab Variable 1
Tab Variable 1

Therefore, its value is displayed, to the right of its name. It is also possible to display it by writing its name in the appropriate field.

Then, it is possible to display only the variables that we will call "Local" Variables.

Actually, SAP distinguishes 2 types of variables. The first is the local variable. This one is only available in the code when you access its block.

To give a simple example, when a program calls a Routine, the variables present in the routine will be "Local" variables. They will only be available during the execution of the routine.

Finally, on the other hand, global variables are accessible everywhere in the program. SAP allocates an array for them, in which you can find them all.

4. The source code

To finish the presentation of the layout, let's quickly talk about the source code present in the debugger.

There is no doubt that this part is extremely important since it will always tell you where SAP is, what it intends to do next, which steps were skipped during the execution of the program, etc.

Thus, it is of primary importance for you to understand this area, and especially, to know how to move in it.

Based on this fact, SAP provides you with several tools. Let's see them together.

ABAP debugger: Breakpoint and Watchpoint

From now on, we will use these tools to force the debugger to stop at specific points. Let's start by defining these 2 notions:

Breakpoint

First, a Breakpoint is defined so that the program stops at that specific location. In fact, there are several ways to place a Breakpoint, but whichever way is used, SAP will stop at it when it runs.

Watchpoint

Second, unlike a Breakpoint used to stop at a specific point, a Watchpoint is used to monitor a variable. Thus, when the value of the variable changes, the debugger stops.

1. Breakpoint

In fact, there are several types of break points. Indeed, they can have several uses and several life spans.

  • Persistent Breakpoint
  • Session Breakpoint
  • External Breakpoint
  • Debugger Breakpoint

Now let's see how to set a Breakpoint in order to stop the debugger.

Start by placing your cursor on the column to the left of the program line for which you want to insert a breakpoint and left-click.

Session Breakpoint
Session Breakpoint

In second place, still with your cursor, right click and choose the type of Breakpoint you want.

Breakpoint
Breakpoint

Third, while debugging, go to the menu for breakpoints.

Breakpoint at
Breakpoint at

This way you can choose where you want to place other Breakpoints.

  • To a particular statement, such as "IF" to control a condition
  • In specific cases, to a routine,
  • Or to an error message, to analyze the source

2. Watchpoint

As seen earlier, a Watchpoint is used to scan for changes in a very specific variable.

Note that a Watchpoint can only be set during a debug session.

So, to create a Watchpoint, follow these steps:

Create Watchpoint
Create Watchpoint

Then a dialog box appears.

Create Watchpoint
Create Watchpoint

Afterwards, you must enter the variable to be analyzed. Once set, by using the keyboard shortcut F8 or the "Continue" button, SAP will run the program until the value of this variable changes, or until the program is terminated if it does not change.

ABAP debugger : Conclusion

By the end of this article, you will have had an overview of the possibilities offered by this extremely useful tool, the debugger.

Whether you are an ABAP developer or a functional consultant, it is essential that you have a thorough understanding of this tool.

In truth, we've only skimmed the surface of its features. In fact, it's one of the most complete programs on the market, and can be used for a whole host of other tasks.

Would you like unlimited access to our entire SAP training library? Test our training platform free of charge for a 7-day trial period.

Leave a Reply

Your email address will not be published. Required fields are marked *