How to Set a Watchpoint for a Variable in the ABAP Editor?

Explanation of the Question


While debugging ABAP programs, you might encounter a situation where a variable takes on many values, but you want the debugger to stop only when the variable reaches a specific value of interest. That may sound a bit tautological, but hopefully, the idea is clear.

To put it more briefly and to the point: during the runtime of an ABAP program, a variable takes on n number of values. You want to pause debugging at the moment when the variable value n equals "the value of interest." I think that makes it a bit clearer. For example, you have a program with the following source code:

REPORT zwatch_point_demo.
DATA: lt_pa0001 TYPE STANDARD TABLE OF pa0001,
      ls_pa0001 TYPE pa0001.
 
SELECT * FROM pa0001 INTO TABLE lt_pa0001.
 
IF sy-subrc EQ 0.
  LOOP AT lt_pa0001 INTO ls_pa0001.
    IF ls_pa0001-pernr = '330002'.
*   do smth
    ENDIF.
 
  ENDLOOP.
ENDIF. 

After the first debugging run of this program, you notice that a large number of records are retrieved into the lt_pa0001 table, and stepping through them in the debugger becomes quite inconvenient, since the value you're looking for will be pulled from that very table.

So how can you make the debugger stop when a certain variable (e.g., the employee number in ls_pa0001-pernr) reaches a specific value?

Solution

To solve the above problem, you need to set a watchpoint for the variable ls_pa0001-pernr, defining the value you are interested in. Click the Watchpoint button after starting the debugger.

Specify the variable name and the value you want to monitor.

Then continue running the program, making sure to remove any existing breakpoints. When the tracked variable is assigned the value you've specified, the debugger will notify you with an informational message like:

Below is a short video demonstrating how the watchpoint mechanism works.

0:00
/0:41
See: Working with Watchpoints