Tutorial: How to Debug an ABAP Managed Database Procedure
New AMDP Debugger available in ADT starting with release ABAP 7.5. Check how to use it here…
Remarks before you start
- All screenshots have been made in an AS ABAP System with SID “HANAABAP” installed in the HANA Database Schema “SAPHANAABAP”.
Please consider to adapt this based on the System ID (<SID>) and schema of your system.
- The screenshots have been created based on HANA Studio version 1.0.7000 and might differ with respect to other HANA releases.
What’s in this document
This document describes how to debug an ABAP Managed Database Procedure in SAP NetWeaver 7.4 SP5 and higher.
For a video tutorial please visit How to debug an ABAP Managed Database Procedure (AMDP) – YouTube.
In order to debug an ABAP Managed database procedure (AMDP) in AS ABAP 7.4 SP5, an ABAP user as well as a HANA user is required.
We assume that the AMDB is executed via an ABAP report and is subject to a debugging procedure initiated by the HANA user DEBUGUSER.
For the ABAP user the standard ABAP authorization to execute the corresponding report is required.
For the HANA user DEBUGUSER, the authorization to read the catalogue needs to be granted by the SYSTEM user:
grant catalog read to DEBUGUSER;
Additionally, debugging authorizations are required as described in SAP note 1942471 (http://service.sap.com/sap/support/notes/1942471). According to the note, for SAP HANA releases >= SPS7, three authorizations are required:
- Authorization to debug the procedure
- Authorization to execute the procedure
- Authorization to attach the debugger to a SAP<SID> user session
The corresponding grant statements to be executed in the SQL console of the SAP HANA studio (as SAP<SID> user) for the ABAP Managed DB procedure <AMDP_NAME> are:
grant debug on “SAPHANAABAP”.“<AMDP_NAME>” to DEBUGUSER;
grant execute on “SAPHANAABAP”.“<AMDP_NAME>” to DEBUGUSER;
grant attach debugger to DEBUGUSER;
Alternatively, the grant statements for the authorization to debug any ABAP Managed database procedure in the schema SAPHANAABAP are:
grant debug on schema SAPHANAABAP to DEBUGUSER;
grant select on schema SAPHANAABAP to DEBUGUSER;
grant attach debugger to DEBUGUSER;
Remark: For SAP HANA release SPS6, only the authorization to execute SYS.DEBUG is required.
Since ABAP Managed database procedures are created in the HANA catalogue at first execution – during ABAP class activation – you might need to generate the catalogue object before you can start the debugging. For this purpose you can execute the ABAP report RSDBGEN_AMDP.
Step-by-Step Guide: Debug an ABAP Managed DB procedure
Set a Breakpoint
Go to the SAP HANA Development perspective and open the ABAP Managed database procedure (AMDP) catalogue object you would like to debug:
- Set the breakpoint:
External Debugging: Attach the SQLScript debugger
- Go to the Debug perspective and create a debug configuration:
- Create a new SAP HANA Stored Procedure debug configuration and insert the information depicted in the screenshot:
For the debugging process described in this document, we use the option “Debug an External Session”. The debug user can be selected from the drop down list, in our case the DEBUGUSER. The filter attributes should be as specific as possible. We debug an external session of the “HANA User” SAPHANAABAP, i.e. the user assigned to the primary database connection when running the ABAP report. The user DEVELOPER executes the ABAP report, for this purpose we apply the optional filter on the “Application User”. Finally, click on Apply and start the debugging process via the Debug
- If everything worked fine you should now see in the debug view that the external debugging is running, and you should additionally see the active break point in the Breakpoints view:
Execution of the ABAP report
In this document, the ABAP report ZR_DEMO_AMDP is executed. In the report the call of the class method zcl_demo_amdp=>get_open_so_inv_for_customer leads to the call of the corresponding AMDP procedure. The coding for both, the ABAP report and the ABAP class, can be found in the attached files.
- Switch to the ABAP perspective and execute the ABAP report ZR_DEMO_AMDP (alternatively also the execution of the AMDP via transaction SE24 is possible).
- The debugger attaches to the running session and stops at the breakpoint. Switch to the Debug perspective to use all debugging features (this is not mandatory but might become handy):
You can now use the tools provided by the SQLScript debugger, e.g. you can investigate the values of variables in the Variables view or a data preview of tables et_so_inv_h via right-click on the table:
The data preview is displayed in a corresponding window:
You can proceed to the next breakpoint (if available) via F8 or just end the current debugging cycle of this procedure (via F8 if no other breakpoints are given).
- After this process, the debugger will be in the state described in paragraph “External Debugging: Attach the SQLScript debugger”, i.e. the debugger is in external debug mode. Therefore, you can repeat the debug procedure by re-execution of the ABAP report.
Remark: Please explicitely terminate the debugging process once you are finished. The debug procedure described attaches externally to a running session based on certain filter criteria (in our case “HANA user” SAPHANAABAP and “Application user” DEVELOPER) and if an active breakpoint is set. Therefore, you might accidentially/unintentionally debug a colleagues’ report execution if the criteria are matched – your colleague then either has to wait until you press F8 or until the debugger time out helps .
at which step does that happen? I have seen something similar when choosing "Procedure to debug" in the Debug Configuration but not with external session debugging.
I think the error raised is not generated by the ADT but rather by the SQLScript debugger in the debugger perspective. The issue arises since the debugger does not know where to find the procedure you'd like to debug. However, you have it open and you have an active breakpoint set, right?
Where exactly did you set the breakpoint? Meaning, you have the system connection, opened the procedure from the Catalog folder and set the breakpoint there, right? Or did you opened the procedure in a local project?
Yes, you're right, it is a mistake SQLScript Debugger in the debugger perspective. I did everything according to Tutorial, thank you for it. Of course the debugger is configured as an external.Procedure not in local project but all code in temporary package $TMP. Maybe this is the reason? Or problems in the ADT installation...
no, the $TMP package should not lead to an issue and same holds for the ADT installation. You could even do all steps without an ADT installation (except for executing the ABAP report of course 😉 ).
The error you described, is it raised at step 2 of "Execution of the ABAP report" and are you in the debugger perspective? If yes, in which view of the perspective is the described error raised?
You can also drop me a mail with a screenshot if you like.
I reinstalled HANA Studio + ADT
Everything worked, thank you, Jasmin!
Hello I am facing the same issue of "Source not found" with button "Edit source lookup path".
Any input on the issue shall be highly appreciated .
Thanks in advance. 🙂
I suspect some missing authorizations. Can you please check if all authorizations have been granted (e.g. via ADBC)?
I am also getting the same problem "Source not found" with button "Edit source lookup path".
I got all the authorizations which were mentioned above.
Can you please let us know what is missing here.
Thanks in Advance.
I have re-installed now i am able to see the code.
F5,F6,F7,F8 buttons are disable for me to debug.
Is there any special authorization is required for this.
Thanks & Regards,
the step-in (F5), single step (F6), and step-out (F7) functionality is currently not provided by the SQLScript Debugger.
What is a bit puzzling is the missing F8 functionality. Are you in the right perspective when debugging? Is the F8 "shortcut" working, i.e. can you resume the debugger using the F8 key and just the button seems to be inactive?
Thanks for your response.
Yaa F8 shortcut is working fine for me but the thread that is created in the debug configuration is working only one time per execution, i mean if i want to debug more times i need to terminate and relaunch the debug configuration for those many times.
Thanks & Regards,
I followed this excellent guide and the video on the subject of debugging.
I have performed all the steps and everything looks as described above except when I execute the ABAP report. Nothing happens. The report runs through successfully but there is no stop at the break-point.
What could be the reason for this?
System HANASP7 BW740SP5.
For bookkeeping: Issue solved :-).
I am unable to debug NESTED AMDPs , When i put a breakpoint in inner AMDP procedure and execute my abap transaction,it simply hangs, debugger hasn't stop anywhere either.
p.s : Non-NESTED AMDP debug works.
This can be avoided while setting debug configuration. Select Procedures with breakpints under advanced tab and it will hit the procedure where breakpoint is set. ( You need to set all the breakpoints in all the procedure where you want to to debug before starting debugging while working with this option. )
Hi Abhishek ,
You are correct, now the breakpoints are reached in the NESTED procedure.
However I have a strange behavior in one of the NESTED procedures,
The breakpoints are shows as crossed, not like normal ones, the debugger doesn't stop here either. but it does stop at other NESTED procedures where breakpoints are not crossed(pic attached), any idea why? I have activated the procedure, it also works and returns results but cannot be debugged
Your breakpoits got invalidated may be because of change in procedure or other issues which can be resolved by :
1. Resetting your breakpoits.
2. Restart your eclipse.
you may check that you granted all necessary authorizations, i.e. the authorization also for debugging the inner procedure?
More over, make sure that all required breakpoints are set once you start the desired breakpoints.
How to find HANA Database Schema name? I am working on system where SID is ERP, should i search in SAPERP schema? But i could not able to find SAPERP schema name in HANA database.
Thanks a lot for your guidance and support.
are you working on the "default" connection of the ABAP server to the database? If yes, please have a look at the "System -> Status" of your ABAP server, there you can see an information section on "Database data", the owner is the DB user, which is typically identical to the database schema name.
This is only true for the default connection. If you are using a dedicated secondary database connection, you can find the database user (and thus the name of the database schema) in the database connection (transaction DBCO).
SID is 3 character string, not sure why did we took HANAABAP as SID here?
the data element SYSID is used for the SID, which is a CHAR30. But you're right, I've been a bit unprecise in my documents. The SID is actually A4H but the HANA user is SAPHANAABAP. As the "typical standard" is to have an SAP<SID> user as database user for the ABAP to connect to the DB, I explained it like that. You can find the HANA DB user name corresponding to SAPHANAABAP in my explaination when you have a look (e.g. in the SAPGui) at System > Status. There you'll see the DB user as well as version information, ports, etc.
What will happen if I put a break point inside a method body in ABAP perspective instead of setting up break point in database procedure.
true AMDP debugging is much more comfortable, yet you need a high enough SAP_BASIS as well as HANA release. :-).
hi Jasmin, thanks a lot for you reply.
Till which release we need to create explicit debug configuration?
Or from which release AMDP debugging become simpler?
for AMDP debugging, you'll need at least ABAP 7.4 SP8 (so the SAP_BASIS 740 SP8) and a HANA running on SPS9.
Yet, even in this releases an explicit debuggin via the HANA console is still necessary for some cases, debugging of native HANA procedures (e.g. if it's called via ADBC or attached to a Database Procedure Proxy).
Just to confirm. So I have a system is running ABAP 7.4 SP11 and HANA SPS 8.
So I wont be able to debug AMDPs. Isn't it the case?
with your HANA version you cannot use the integrated AMDP debugging.
You can debug AMDPs only by the way described in this article here.
Thanks for the reply.
What do you mean by "integrated AMDP debugging"?
I thought the only way to debug AMPDs is the way described in this article. 🙂
the integrated AMDP debugging that Jasmin mention in this part of the comments is itegral part of the AMD-Editor. You just set a Breakpoint in your source code. No need for HANA stuio. But for this you need, (as mentioned) at least ABAP 7.4 SP8 and HANA SPS9.
we are on 7.4 SP14 combined with HANA SP11 and latest version of modelling tools. If I set a breakpoint in a procedure which is created via AMDP then I'm getting a dump and the error:
"transaction rolled back by an internal error: exception 70000000: The
attached Debugger compiled some procedures in debug mode on-the-fly. Please
restart your statement in order to debug them.#"
If I repeat it I'm getting the same result. Does anyone has an idea what the problem is?
to deal with your issue you can try to choose the setting "Compile a debug execution plan for:" - "Procedures with breakpoints" in the debug configuration of your HANA Studio.
Using the value "All procedures in the call stack" can cause the issue you mentioned with HDB SPS 10 and 11. To understand what the setting means you should also take a look at the section "Debug Mode" of this blog:
How to debug ABAP Managed Database Procedures using ADT - Details and Tips
Once you activated the new setting the procedures without breakpoints may be executed in optimized mode which can cause side effects during debugging. If you face side effects, e.g. debugger is not stopping at a breakpoint, try to create an additional breakpoint in the calling procedure (one level higher) in order to force it into debug mode.
Note that in the context of AMDP the top level procedure is the stub procedure. The stub is named like "<your_amdp_name>#stub...". If your debugger is not stopping at breakpoints try to create an additional BP directly in the stub.
Once you updated to HDB SPS12 you should be able to use the initial setting value again without issues. Or if you updated to NW 7.5 you can use the ADT AMDP Debugger (How to debug ABAP Managed Database Procedures using ADT - Basics) which is overall more convenient to debug AMDPs.
Thank you for your fast reply. I have changed the setting but now I have another strange behaviour. I have set breakpoints in several procedures now (to be on the save side in all 3 procedures which are created automatically). But allthough the debug configuration is running there is not stop at the breakpoints. Furthermore as soon as I switch to debug mode by running the configuration all breakpoint are changing the status to "catalog lookup failed":
Is this normal behaviour?
Currently we are running a sandbox but after that we will use SPS12 for HANA for system migration.
This behaviour seems to be connected to HANA Studio version. I have used an older version now (before I used the latest version) and with the older version debugging is basically working but not for every call. I see every step for the first call in the screenshot - which means HANA procedure debugging is working (the first call is simply for creating the procedure if it is not already created on HANA).
The second call is the one which creates planning data in a planning function on BW and this is skipped on HANA:
The second call is the important one and is skipped.
I have tried debugging now for own planning function type in BW and for characteristic derivation type exit - for both debugging is skipped.
I'm not completely sure about these issues but I would guess the following:
1) "Catalog lookup failed. procedure does not exist": Maybe this can be resolved by executing the AMDP / DB procedure once initially before you create breakpoints etc. You said it's depending on your Studio version but maybe it also worked in the older version simply because it was then executed for the second time (?). Personally I would retry it with the newer Studio version one more time to see if it works now.
2) Debugger is not stopping in the second call: Unfortunately the overall setup that you have (Combination of Studio/NW/HDB versions) is not ideal for debugging AMDPs. In your setup probably only the first creation of new debug session is reliable.
That means if you enter procedure debugging initially its reliable. Within this initial debug session all breakpoints should be respected. When you leave to ABAP your first debug session will end.
If you then try to re-enter procedures (the same or a different one) and reach a procedure breakpoint a second procedure debug session should be started in HANA Studio but this is not reliable and will not work most of the times.
So you have two options now:
1. Do not debug the call of MON_TO_DAY() so the second call becomes the first/only call and can be debugged reliable.
2. Start by debugging the first call. Once you left from procedure debugging to ABAP debugger, manually restart the procedure debugger in HANA Studio before you resume in ABAP Debugger.
1) No, it does not help to execute it several times. This is simply not working with my installation of HANA Studio. I have tried that more than 20 times now (the procedures are there). You can see that also on the screenshots. If the procedures do not exist they will not be shown in HANA Modeler
2) Ok, good to know. Now it is working. I thougt this is working like ABAP Debugger where it is no problem to stop when you have several calls. I have decided for the 2nd option which is not very convinient but working.
If there is another option to check if the procedure is created instead of calling it to be sure that it is created I don't know it. In my opinion this should be done by the planning framework if AMDPs are allowed but this is another topic.
Thank you for the help.
To debug AMDP in 7.4, we need above mentioned authorization to be granted by System SID user.
Normally we have lot of developers . To grant such authorization to each and every user, it needs to be done by system user SID.
Is there any way this privileges can be attached to a role and role can be assigned to HANA DB user ID.
Isn't it concern if for each and every DB user, this authorization has to be granted individually by System SID.
How can we call an Instance AMDP method inside another AMDP (Static/Instance) method? I checked the approach of calling the static AMDP method which works perfectly fine but want to check for instance AMDP method calling.
F5,F6,F7,F8 buttons are still disable for me to debug.
I'm using HANA Studio Version: 2.1.16
Is it available now any version HANA Studio?
I am facing issues during SAP HANA Debug - HANA Authorization error :
Can any one please advise.
Please check your HANA prospective logon.
It should be active.
I understand this is a very old post of yours. You have mentioned this feature is available from NW 7.4 and higher. But there are other posts in the internet which says this feature is only available from NW 7.5. When I tried to set a breakpoint in NW 7.4 I got the information message saying "AMDP Debugger is not available for the current system".
I hope this comment is useful for all other NW 7.4 users.
It was was a very nice blog and will help everyone in a lower SP level in SAP HANA to debug an AMDP.I have few questions if answered will help us in moving forward.
It is similar to the RFC debugging.
But in this case we need to debug the stored procedure created in run time by the AMDP method. Very good post.