ABAP Debugger scripting – my first real use
Do you know about ABAP Debugger scripting? And if so, have you made use of it, yet?
I knew about it for quite some time already (I think it’s been around for ~10 Years), but only recently mad use of it.
This is the experience I want to share here.
I had to redesign some old Z-functionality and chose the following strategy: I didn’t want to tear to much on that 15+year old coding, being afraid to accidentally kill the functionality of it. That’s why I decided to keep make a copy of it for me to boldly refactor, while keeping the original intact as a working reference. (When done, it’s a very good idea to decommission (that’s: delete) that old, then unneeded code).
So first thing I did with my copy (and that’s a good idea to always do) is: verify it indeed behaves exactly like the original. Guess what: it didn’t!
The functionality is some z-report being called from ME57, it then calling BAPI_PO_CREATE to create a purchase order (PO). The original report would create the PO, my copy would not (Message being ME155 “Requisition & & not selectable”).
Here you can make guesses on what might be the cause 🙂
Have a few guesses? Ok, let’s continue.
When copying the report and it’s includes, I got a message “enhancements will not be copied”, so I already suspected something missing.
Unfortunately there is now way if comparing to reports with each other, at least not expanding all includes and including enhancements. (Or is there? If so, please do let me know!) There’s SE39 of course, but it doesn’t do the expansion of includes…
Intermediate try: SE37 test data
Next try was, that I captured the both the calls to BAPI_PO_CREATE as SE37-test data. A very nice function:
… then I tried comparing them, as I assumed different outcome results from different input; This test data is stored in table EUFUNC but it’s not easily comparable – it could be read with FM RS_TESTDATA_GET, but then?! So I compared it manually and didn’t see any differences. An when I tested them in SE37, both cases failed. So that was a dead end. (or a hint?! 😉 )
Complete trace via Debugger Script RSTPDA_SCRIPT_STATEMENT_TRACE
So now I wanted to see where the two path’s differ. I went searching SAPCommunity for the topic and (again, as a comment of mine from 2016 proves) found https://blogs.sap.com/2010/12/14/abap-debugger-scripting-basics/ .
This taught me how to use RSTPDA_SCRIPT_STATEMENT_TRACE and that’s what I show now:
creating the trace
- Set a breakpoint at from where you want to start tracing. …and also one where you want to stop again. In my case it’s the call of BAPI_PO_CREATE.
Run your application and watch the debugger open on your first breakpoint.
- Switch to the scripting tab
- Now load the script RSTPDA_SCRIPT_STATEMENT_TRACE from database (ignor the button in the Popup saying “save script” ,when it should say “load”).
- Click “Start Script”
-> The debugger will continue to run, tracing every single line of code it comes by, until it reaches the next breakpoint.
- When this is the case, stop the script.
looking at the trace
- you can evaluate the trace directly from the debugger (in the current or a new session).
…or you can use standalone transaction SAS.
Note: it’s a lot of data, about 300.000 Lines, so it took a while to load. If that’s done, it can be downloaded to a local file:
Comparing text files with the tool of your choice.
I wanted to see the difference between the “working” and the “not working” part, so I traced them both as described above and got the tracefiles to my local machine.
Comparing two text files is easy, I used the ‘compare’-plugin to Notepad++ but your favourite tool should work as well.
The two files are well in sync, until at one point, the start to differ:
So, now that I knew I where, I only had to look up what, so I opened include MM06EFBA_BAT_AUFBAUEN and navigate to line 38 (in AdT with ctrl+l, in SE80 with ctrl+o) and there we have our explanation:
if sy-cprog ne ...
So, this is how I gained insight and answers using ABAP Debugger Scripting.
What are your use cases? And do you even still use the ABAP Standard Debugger, or are you hooked on the AdT debugger already?
As always, your input is most welcome!
perhaps, as an alternative, we can possibly consider the program flow analysis as explained here
and it may be worthwhile to explore the ‘Compare Call Hierarchies’ option if manual comparison of
‘Call Hierarchy’ /’Processing Blocks’ from the actual trace is tedious, i haven’t tried this myself though.
A nice new to me - way of doing things. I seem to use trace as a backup for my ABAP debugging. Script would probably give me less rows to look at?
I'm going to have to give this a try. Time, if only I had more of it.
But if it works nicely, it would give me more time. 🙂
Nice to see you back and blogging!
Nice blog aboout how you used ABAP debugger scripting to get a full trace and find a difference in the program flow! Thanks Joachim!