Debugging custom logic using ADT in SAP S/4Hana Cloud
I would hazard to say that a debugger is a developer’s best friend: we can always make due without one, but we would always prefer to have one close by. I have used the ABAP Development Tools (ADT) environment for years as a developer at SAP, so using that tool’s debugging feature is a common go-to for me.
With last year’s introduction of SAP S/4Hana Cloud’s 3-system landscape and Developer Extensibility, our familiar friend ADT can be used. So that in addition to all of the great functionality already available within SAP S/4Hana Cloud Fiori applications, developers can now also make use of the great capabilities provided through the ADT, such as debugging and tracing.
The purpose of this blog is to walk you through the use of the ADT’s debugging and tracing abilities on custom logic defined in key user extensibility. It assumes that the reader is already generally familiar with ABAP development and the use of the ADT, as well as a general understanding of how custom logic is defined in an SAP S/4Hana Cloud system.
Finding the Custom Logic
For my purposes here, I made use of an existing BAdI implementation that I created previously using the Custom Logic application available within the SAP Fiori Launchpad for my SAP S/4Hana Cloud instance. I entered a search text of ‘Order Operation’, which resulted in my implementation being displayed in the list. I was then able to hover over that entry so that the technical implementation name is displayed as a tooltip.
That identifier is very important, since without it I may have had much more difficulty identifying where my custom logic resides in the SAP S/4Hana Cloud system.
Another way that I could have found this information would have been to make use of the personalization available for this list, by clicking on the gear icon.
Within the popup that is opened, I selected the ‘Implementation ID’ entry so that it would also be included in the list.
Now that this value was displayed in the list, I was able to easily select and copy it to my clipboard.
Within my local ADT (which already had my SAP S/4Hana system displayed as a project in the Project Explorer and which was already connected), I then chose to perform a Search operation in order to find my implementation.
The search results were then displayed, which showed both the implementation as well as the implementing class.
By double-clicking on the object name, the implementation was then opened and displayed in my editor.
I was then able to click on the ‘Implementing Class’ link to have the class be opened in the editor.
Once I scrolled down a little, I was able to see where my custom logic was located (i.e. between the ‘payload’ comments).
Setting Up Debugging in the Custom Logic
After deciding the point in my custom logic where I wanted the debugger to stop, I double-clicked on left-hand-side of that line of code (within the blue-shaded area) in order to set a breakpoint, which is then indicated with the blue dot.
In my case, I knew that my breakpoint was going to fall within a loop, but I did not want to have it stop repeatedly. So I wanted to make this breakpoint be conditional, so that it would only stop when the condition that I provided was actually met. I right-clicked on the breakpoint in order to invoke its context menu, which gave me several options. The one that I needed was for the ‘Breakpoint Properties…’.
The condition that I wanted to put in place was to only stop for the first entry in the loop.
The conditional breakpoint was then saved and was visibly identifiable as a blue dot with a curly tail underneath.
Should you wish to explore more of the capabilities of the debugger, then the SAP Help portal provides all of the details that you will need, within SAP S/4HANA Cloud > SAP – ABAP Development User Guide > Tasks > Using Troubleshooting Tools > Debugging ABAP Code.
Debugging the Custom Logic
At this point, I only needed to productively make use of an SAP Fiori application that enabled the use of the custom logic (i.e. that called the BAdI implementation) on my SAP S/4Hana Cloud system. In my case, my custom logic was invoked by my opening an order for editing using the Change Production Order application. The SAP Fiori application will then be left in a waiting state until the breakpoint is handled in someway.
Generally speaking, if a breakpoint was encountered, then the ADT would be activated and come into focus (in my own case, the ADT was highlighted in my Windows Taskbar, so I opened that window).
Because I had the ABAP Perspective open, it prompted me to indicate how I wanted the ADT to proceed with respect to whether it should switch to the Debug Perspective. I chose to switch perspective.
The ADT then displayed the debugger and indicated the current line at which it had stopped the execution, and provided a list of all variables currently in memory, as well as the call/execution stack trace. I was interested to see what the values were for the MFGORDEROPERATIONS_CHANGED internal table, so I expanded that information within the Variables display.
Once I was ready to have the execution continue, I then clicked on the Resume button.
There was more than one entry to be processed in the loop within the custom logic, but because of my breakpoint’s condition, the debugger never again stopped, as expected. The processing within my SAP Fiori application resumed and completed successfully. The processing in the ADT then terminated.
Tracing the Custom Code
Trace information can be very useful for performance analysis. In my scenario, the benefit of tracing is limited due to the fact that my custom logic is very simple. However, if my custom logic had been much more complex or involved the use of SQL or external APIs, then it would be a great benefit to be able to adequately assess the performance using the details provided by the ADT Trace.
Since I wanted to keep the implementing class for future reference, I made use of the ‘Add to Favorite Objects’ feature available in ADT, but right-clicking on the object displayed in the Search results list.
The class was then displayed on the left-hand-side in the Project Explorer.
Because I wanted to make use of the ABAP Trace functionality in the ADT, I needed to switch to the ABAP Profiling Perspective to easily see the relevant views.
I switched to the ABAP Trace Requests view, and right-clicked on the tenant to open the context menu, so that I could choose the ‘Create Trace Request…’ option.
The trace request popup was then opened, which allowed me to define some of the general aspects required for the tracing, such as what request types are to be traced for what user and what title should be used for the trace files. I chose to trace all HTTP requests for my own user, and to use the title ‘MyFirstTraceFile’. I then clicked on the Next button in order to see the remaining configuration options available.
Although I had chosen to leave the default option in place, so that HTTP requests would be traced, there actually does exist more options than just that one.
The trace parameters were then displayed. I chose to leave most of them as they were, although I did choose to use the Custom Statements option so that I could select all of the areas that I was interested in seeing traced. By clicking on the Finish button, the tracing is started.
After I clicked on the Refresh icon, I could then see that my trace request had been created and that the tracing had started.
At this point, I switched to using my SAP Fiori application once again, and made the same type of change to a production order so that my custom logic would be triggered (and its execution captured in the running trace).
Back within ADT, I switched to the ABAP Traces view and clicked on the Refresh icon again, and the list of trace files was updated and showed the results.
I double-clicked on the latest entry and the Overview page was opened. Within it I was able to see some high-level information, as well as being able to navigate to more detailed information.
I chose to view the Hit List results and to filter them (using the prefix for my implementing class). This gave me some further details on the execution of my custom logic.
Details on the various areas of information provided within the trace files can be found within the SAP Help portal, within SAP S/4HANA Cloud > SAP – ABAP Development User Guide > Tasks > Using Troubleshooting Tools > Profiling ABAP Code > Using Analysis Tools
Wrapping It All Up
Hopefully, I was able to illustrate how straight-forward it is to make use of the ADT’s debugging and tracing abilities, and that it is possible to easily identify the underlying development objects pertaining to Key User Extensibility artifacts like Custom Logic.
In a way, as developers, we can now get the best of both worlds.
In the future, I hope to continue to post on extensibility capabilities, such as those for Key User or Developer, within the SAP S/4HANA Cloud Extensibility community blogs.
I would also encourage everyone to post any questions and/or answers within the SAP S/4HANA Cloud Extensibility community, which can be very useful resource for extensibility developers.
As always, please feel free to share your thoughts or to provide feedback in the comments.
Thanks for your time.
@Christina Adams Really well explained and an important blog for S/4HANA Cloud, Public Edition 3SL Customers & Partners.
Christina Adams Very nicely explained and would be very useful for the developers.
Great Post Christina. Very Well explained!