5
votes

Up to now I get only an error message if something inside my SAP RFC function is wrong

pyrfc._exception.ABAPRuntimeError: RFC_ABAP_MESSAGE (rc=4): key=No authorization, 
message=No authorization [MSG: class=00, type=E, number=001, v1-4:=No authorization;;;]

It would increase the development speed a lot if I could get a stacktrace of ABAP function. Is there a way to get a stacktrace like for example in Python?

stacktrace-including-local-variables

Related: https://softwarerecs.stackexchange.com/questions/52350/sentry-event-from-exception-to-html

Sentry uses a particular JSON to represent a stacktrace and the content of the local variables. Above link contains an example.

2
I doubt it. At least not without the access to the SAP system itself. Show us your Python code and which function module you're calling. It'll be helpful. - Jagger
@Jagger I have access to the ABAP code and can modify it. - guettli
The message says "No authorization", so it looks like you do not have the authority to execute this particular RFC function module. If you use your dialog user to authenticate via RFC, then you can try the transaction SU53 to see which authorization check fails. - Jagger
The only way is to RFC-query the short dump from st22 after a "ABAPRuntimeError" occurs (you'll have to create RFC to read table SNAP and wrap the function module RS_ST22_GET_FT). Be careful to send only the call stack, not the rest of data which might be sensitive (like the contents of memory). - Sandra Rossi
@Jagger the "No auth" message comes from within the RFC FM. I am sure. - guettli

2 Answers

1
votes

Stack trace inside ABAP can be called with the class cl_abap_get_call_stack. Local variables are not included in the stack trace returned by the class cl_abap_get_call_stack. But you could use a log-point to monitor local variables and the stack trace. Log-points can be created, changed and viewed in transaction saab. A example code snippet:

DATA(formatted_stack) =  
cl_abap_get_call_stack=>format_call_stack_with_struct(   
  cl_abap_get_call_stack=>get_call_stack( ) ).
LOG-POINT ID my_log_point FIELDS formatted_stack 
  local_variable1 local_variable2.

For the authorization-error, please check transaction su53. When you see the red authorization-object S_RFC, it means you are not allowed to call the function module in any way!

1
votes

With ABAP 753 release there was introduced such structure as EPP - Extended Passport.

It seems to be doing something that you want, i.e. showing trace of the called system. I put "seems to be" because I have no 753+ system by my hands so I cannot check in practice.

From the description it should do what you want:

An Extended Passport (EPP) is a data structure that can be sent from a client to a server and is used to analyze call stacks

Extended Passport can be used by frameworks and analysis tools to track external call stacks in communication between clients and servers beyond system boundaries. The values of the EPP components can be saved to log files and used for monitoring. One example of this are short dumps, which all display the most important EPP components.

The DEMO_EPP gives the following usage pattern of EPP:

cl_demo_epp=>init( ).

"this program
cl_demo_epp=>append( ).

"Calling RFC to remote instance
CALL FUNCTION 'DEMO_RFM_EPP_1' DESTINATION instance.

"New SAP LUW
CALL FUNCTION 'DEMO_UPDATE_DELETE' IN UPDATE TASK
  EXPORTING
    values = VALUE demo_update_tab( ).
COMMIT WORK.

cl_demo_epp=>append( ).

cl_demo_output=>new(
  )->begin_section( `Extended Passport (EPP)`
  )->display( name = 'EPP Trace'
              data = cl_demo_epp=>get( ) ).