Sunday, 9 February 2014

Six kinds of debugging tips to find the source code where the message is raised (Jerry Wang)

I would like to share with you my debugging tip in my daily life, which makes my life much easier. In case you found your own tip are not listed here, please kindly comment it so that it could benefit more people here
 
I will use a simple example to demonstrate. Input an invalid name in SE38 and click display button. An message is displayed in the bottom. I will show you how to find the exact line of code which raises this information.
 
clipboard1.png
 
note: some of the approaches listed here might not be efficient for this very case, I just list all of my tips here for completeness. I do believe each tip could be useful in certain case.
 

Approach1 - Use "Where Used List" function in ABAP workbench

 
click on the green icon and we can find message class ID: DS, number 017
 
clipboard2.png
 
SE91, use where use list:
 
clipboard3.png
 
OOPS, so many hits...
 
clipboard5.png
 
Then I have to manually fitler them one by one to find the correct one. Double click one by one. I ignore all entries with type MESSAGE E since in my case the message type is not E, but S. After one minute I confirm the following one is the one I try to find.
 
clipboard6.png
 
yes it is confirmed by debugging:
 
clipboard7.png
Summary: the drawback of A1 is that as you see, if there are many where used list results say a hundred, it still takes you some time to manually find the correct one.
 

Approach2 - Use Watchpoint to observe sy-msgid in ABAP debugger

 
type /h in command area, and click display button to trigger debugger.
 
clipboard8.png
Create a watch point with below two conditions. After that click F8, the debugger will stop automatically at the correct line you want. This approach just took me 20 seconds to finish the job.
 
clipboard9.png
For detailed screenshot about how to create a watch point in Debugger, see picture provided by Jim Tasker:
 
http://scn.sap.com/servlet/JiveServlet/downloadImage/105-449508-371869/616-399/watchpoing.jpg
 
 

How to switch into debugging mode for a modal( pop up ) window

Since the command line is not available if there is a modal( pop up window) involved, in this case please refer to SAP Note 118184 about how to switch into debugging mode or refer to this wiki.
 

Approach3 - Leverage the breakpoint type "ABAP Commands" to debug more efficiently

 
Launch the debugger just the same as A2, create a dynamic breakpoint with ABAO command = MESSAGE. The debugger will again stops at the correct line.
With this approach again I only spent 20 seconds.
 
clipboard10.png
Or you can use menu via Breakpoints->Breakpoint at->Breakpoint at messages to achieve the same result.
another.png
Summary: if the scenario you want to debug is quite complex, for example deep callstack with several components involved, the debugger might stops at the ABAP code with MESSAGE keyword frequently. You must still manually check whether the code is just the one you are looking for at each stop. However it is still much more efficient than you debug manually one by one.
 

Approach4 - source code scan

 
Tcode SE93, find the package name of SE38:
 
clipboard11.png
Then use report RS_ABAP_SOURCE_SCAN and maintain the search criteria below. The reason why I do not use program name RSABAPPROGRAM is that it is just a wrapper report. The actual implementation of SE38 is not put within it.
 
clipboard12.png
We only have 4 results.
 
clipboard13.png
You can use an alternative tcode CODE_SCANNER which can achieve the same result:
 
clipboard14.png
clipboard15.png
From my point of view, I do like this A4. I can not remember how many times it has helped with my debugging life. What's more, it would be used not only as a debugging tip, but also one way of studying other people's code. Suppose you are curious of how a certain function is implemented by a software component, it is a good starting point to think of a meaningful search keyword and specify the package of that software component and go deep into the result code.
 

Approach5 - ABAP Runtime Analysis Tool SAT shows its power

 
tcode SAT, create a new variant, ensure the radio box item "Aggregation - None" is selected.
 
clipboard16.png
 
Then launch the SE38 within SAT by clicking "Execute" button.
 
clipboard17.png
 
repeat your steps as usual - input an non-exist report and click display button to see the message. After that click back or quit button in SE38. SAT will automatically be opened to show you all runtime trace information. It will take some time - you can see the progress information in the bottom:
clipboard18.png
click tab "Call Hierarchy", click find button. Input Statement = MESSAGE and go. You will see two search results.
 
clipboard19.png
double click on the hit list row and then you can see the source code.
 
Summary: if the scenario you are tracing with SAT is complex, you will get a huge trace file.  Although you can specify an extremely big size in trace file, according to my real experience, you will fail to open the result trace file when it exceeds 1 G, at least in my application server.
 
clipboard20.png

Approach6 - Have you used ST05 like this way

 
First you open SE38, type and invalid program name.
Open a second session, switch on your ST05 with default settings.
Go back to your SE38 window, click display button.
Go back to your ST05 trace, deactivate and display trace result:
 
We know that the PROGDIR table stores the header information of report. It makes sences for ABAP editor to check whether the program name is valid by search it in that table, doesn't it? So the undoubted next step would be the raise of a message if database search fails. Click the "Display ABAP call location" button to go to the source code:
 
clipboard21.png
We see the logic is that first try to search in DB with inactive version, if failed, try with active version.
 
clipboard22.png
So hopefully the code we are trying to find is just in the very neighborhood of the SQL statement in line 774 and 779. Fortunately in this case, yes it is in line 813.
 
clipboard23.png

 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.