Three ways to achieve conditional break point in your ABAP program
- Approach1 – Source code breakpoint in ABAP debugger
- Approach2 – Watchpoint
- Approach3 – ABAP debugger script
Let’s use the simple program below.
Line 15 will be executed 1000 times. And we are only interested with a given iteration, for example we want to ONLY stop at line 15 with condition <data> = 22.
Approach1 – Source code breakpoint in ABAP debugger
Create a new breakpoint in debugger dynamically:
Maintain your condition as below:
And then you should see this new conditional break point set in line 15:
Then F8 to continue, the break point is triggered only once when <data> = 22.
Approach2 – Watchpoint
You should see your created watch point here:
Execute program, watch point is triggered:
Approach3 – ABAP debugger script
Create a new debugger script:
Click “Script Wizard”->”Variable Value(for Simple Variable)”:
The wizard will generate code automatically for you ( marked with red ). You can finish the left code to achieve conditional break( marked with blank ). Save your script with a name.
Now launch your program, load the saved Script:
Then click Start Script:
Break point is triggered only once:
nice information...
You could also set a "static" BP @15 and use the "Skip" option to jump directly to the 22nd row 🙂
Hello Suhas,
Thanks a lot for your comment. Yes that's also a simple but efficient solution 🙂 What I tried to demonstrate is a more generic approach. Suppose a use case if I would only like to make the loop on a string table stop at a certain condition like <DATA> = 'Jerry', then it is not easy to achieve it via SKIP option. Of course we can still manually find the index of row which contains 'Jerry' and then set this index as SKIP option. Anyway SKIP option is still another good alternative.
Best regards,
Jerry
Hi Jerry,
I just wanted to give an alternative and not contest the usefulness of your option(s) 😎
Skip only makes sense if you know the index of the iteration. Tbh, I have rarely used it and rely on watchpoints (which of course don't work with FIELD-SYMBOLS 😐 ).
But this is kind of inconsistent that one can use field-symbols for defining the "Free Condition Entry" in Approach 1 & not in Approach 2!
BR,
Suhas
Hello Suhas,
Thanks a lot for your useful complement. 🙂
Best regards,
Jerry
tq
Thanks for sharing the valuable info...
Thanks for showing by ABAP Debugger Script.
You are one of the most active participant in creating blogs in SCN. Really need to appreciate you on this...
Nice!!! Thank you for sharing 🙂
Hi Jerry, Its a very good document.
But in the second option of watch point if there are multiple loops in that include, I believe the breakpoint will stop for all the loops rather than the intended one. The other two options are good. Will try the script one.
Regards,
Vinay Mutt
Informative 🙂
Thanks for the idea!
Very nice blog, thank you a lot!
I like that you gave an easy-enough example on how to use debugger scripting - I have not tried it out yet, but believe it's a really powerful tool, so next time I need a conditional breakpoint, I'll probably use that!
Btw:
There's another way and I think there are not too few ("old" 😉 ) ABAPers that would just use that:
if <data> = 22.
break-point.
endif.
best
Joachim
Hello Joachim,
Thanks for your comment. Yes, your suggestion is also a solution, simple but effective, as long as we have the full ownership of the code to be debugged, usually in our dev system. If we have to debug in customer's test or productive system, we cannot change source code that way 🙂
Best regards,
Jerry
good infor for new abaper.
Nice one, especially with script