SAP ABAP Debugger Scripting

SAP ABAP Debugger Scripting is a new tool added in SAP Netweaver 7.0 EHP2. It is a feature available in the new ABAP debugger. However, just like some of the other debugger options, you need to check whether the security team has provided access for the debugger script tool.

Most of ABAP programmers regularly use Break-Points & Watch-Points for debugging. These are necessary in an ABAP programmers role to find the bugs in custom developments, analyze the Standard SAP program or find a BADi for that matter. So where does this Debugger scripting come into play?

Designed To Make Debugging ABAP Code Easy

The debugger scripting is a tool is designed to make debugging easy. Sometimes debugging can be very tiresome, especially when debugging SAP standard code is involved. The debugger scripting tool can sometimes come to the rescue of ABAP programmers, as it helps automate the process of debugging.

Some of the benefits of Debugger Scripting are:

  1. Automation of repeatedly changing the value of some variable in debugging – You can write a script to do all the changes required.
  2. Perform any custom trace possible – Even track the call to the ABAP stack. It can be used to trace when new programs are called, as the ABAP stack is updated every time a new program is called.
  3. Create custom (conditional) watch-points and break-points. script watch-points & break-point are different from the normal debugger watch-points or break-points. Scripts can be implemented for these to work only when required.
  4. Program Tools for standard tasks like checking data consistency, test error handling, etc.
  5. It can help make the debugging to be user interactive (pop-up based) where one can enter the value, rather can each time double clicking on the variable to change the value. Since the script can be saved and loaded again, this makes the task for programmer easier to use.

A Debugger script is simply a local Object Oriented ABAP program that is run by the New ABAP Debugger. The script uses the ADI (ABAP Debugger Interface) to automate actions and to add capabilities that otherwise would not be available.

So Let’s Take A Look At The Debugger Scripting Tool.

In the new ABAP debugger there is a separate TAB “Script” after the TAB “Diff”(Diff-Tool).

Fig 1 – Tool View

In this TAB, are various options for creating and executing an ABAP script. Let us explore these options.

There is a standard create Create_Button button, to create a new script, as per our debugging requirement. Each new script that is created has four methods that can be implemented. These methods are triggered at specific moments and thus it defines their purpose. Also as you can see in Fig 1, all this code is generated automatically whenever a script is created.

A class “LCL_DEBUGGER_SCRIPT” is implemented, which has:

  1. Method PROLOGUE
    After the script is started, the Debugger framework first calls the PROLOGUE method of the script. The default implementation registers the ABAP_SOURCE instance to the DEBUG_STEP event so that the source code information you get from the ABAP_SOURCE instance is always up-to-date.
  2. Method INIT
    INIT method is called only once, directly after the PROLOGUE method. You use this method for initialization. It is also a place to add user interaction, for example, a dialog box, where you ask the user for input, which you need for the script.
  3. Method SCRIPT
    SCRIPT method is where we write the Object Oriented ABAP code that executes. This method is called each time the debugger script executes. It has an importing parameter p_trigger, which holds the trigger type that caused this script to execute (Breakpoint, Watchpoint, Single Step, Single Run).
  4. Method END
    When the script stops, END method is called.

Besides these custom methods, the Script Super class also includes two already implemented methods :

  1. break
    This returns the control to the user. You can stop the script or continue here.
  2. raise_error
    This method is used to exit a script, with respective message displayed to the user.

Like the standard ABAP Editor, in Debugging Script Tool also there are buttons for syntax check, include patterns & pretty printer. Besides these there is a button for the Script Wizard, that can used to generate the code automatically so that the programmer doesn’t have to write the entire code, you can just modify the generated code, based on your specific requirement.

The triggering of debugger script can be done in a number of ways.

  • It can be Triggered directly.
  • It can be triggered when a Breakpoint is encountered while executing the code.
  • It can be triggered when a Watchpoint is encountered while executing the code.
  • It can be triggered after each debugger step.

Since the debugger script is a local OOPs program that is executed in the new ABAP debugger, it can be easily saved  for later use and loaded whenever required. Which removes the task (and hassle) of doing same things again and again as in a normal debugger.

As tracing is a strong component of this tool, a button is specifically provided on the screen to display a trace. This inherently triggers a Transaction code SAS, used for viewing a debugger trace.

Let’S Have A Practical Example Of The Use Of Debugger Scripting Tool.

Normally watch-points are used to stop the execution of a program whenever the value of some variable changes or is different from the set value.

Suppose there is a scenario where an internal table should have 100 records, however because of some bug in code, some records get deleted. According to the traditional approach you would normally have to put a watch-point over the table and execute the code loop each time until you manually find where the record gets deleted. However using this Debugger script tool you can customize your watch-point, to stop only where a record is removed from the internal table. Let’s see how.

Consider the following code for populating the internal table and displaying the number of records it holds.

Fig 2 - Code for ITAB

Fig 2 – Code for ITAB


However when executed it displays only 99 records as opposed to the 100 records that was expected.


Fig 3 - Output of Demo Program

Fig 3 – Output of Demo Program

To find out where the issue is, you can write a script to find the bug, instead of executing you programs loop again & again one loop at a time.

  • Execute the program in debugging mode and go to Script Tab to create a script.
  • Choose a triggering mode as watch-point reached.

    Fig 4 - Option for Triggering Script

    g 4 – Option for Triggering Script

  • Now select the Edit button to add a watch-point. Choose the internal table. (Note : A script watch-point is different from the normal debugger watch-point)
  • Fig 5 - Add Watch-Point in a Script

    Fig 5 – Add Watch-Point in a Script

  • Fetch the description of the internal table in a factory description holder.
  • Extract the line count from it & compare it with the Saved_Count (holding loop count).
  • Fig 6 - Script Code for Customized Watch-Point

    Fig 6 – Script Code for Customized Watch-Point

So if both the counts are not equal, the  program will stop otherwise it will continue processing our code.

Pretty Damn Easy!

This is how a customized watch-point can be implemented through Debugger scripting.

The debugger scripting tool is quite a new tool for most ABAP programmers and it becomes very handy once you get the hang of it. It requires the knowledge of Object Oriented ABAP as a prerequisite, which in itself is something all ABAP programmers should learn. It can make the life of an ABAP programmer that little bit easier when faced with a difficult bug to solve, so give the tool a go. You might start to like it 🙂


About the Author:

Pete has been working with SAP technologies for over 10 years. He started out as an ABAP consultant and then moved on to BW where he has worked many different clients covering a wide variety of industries. "I love introducing SAP technology (especially BI) to new clients and showing them how they can go from zero to hero within their business in super fast time". Contact me on twitter @PeterMoxon

  1. SAP Program Manager

    Debugger scripting is a very powerful and efficient. Our teams used to leverage break points (local & session) and watchpoints to debug complex programs that used to take longer especially in environments where classes and programs were invoked dynamically. The scipting reduces this effort and makes debugging much faster.

  2. Angelia (Angie)

    I agree it is amazing. Problem is what does the security team need to give my ID so that I can use the new Debugger Scripting Tools. My SAP client says there is no tcode of SAS. I am wanting to give a demo on this next week for Accenture Federal LLC in San Antonio, TX. Please provide SAP ROLE needed or PROFILE or ??