5

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.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
guettli
  • 25,042
  • 81
  • 346
  • 663
  • 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 Dec 03 '18 at 14:29
  • @Jagger I have access to the ABAP code and can modify it. – guettli Dec 03 '18 at 14:34
  • 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 Dec 03 '18 at 15:41
  • 1
    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 Dec 03 '18 at 15:44
  • @Jagger the "No auth" message comes from within the RFC FM. I am sure. – guettli Dec 03 '18 at 16:07
  • Which RFC is it then? The message class 00 shows that this is probably an SAP standard function module, isn't it? Anyway, even if it comes from RFC, then still one could assume that this is done right after an authority check, which will should be visible also in `SU53`. – Jagger Dec 03 '18 at 16:11
  • The message class, type, number and parameters 1-4 describe the error message itself. In ABAP the system would construct the localized full message text in the user's language from this data. You may have a look into table T100 for further details. – Trixx Dec 03 '18 at 16:57
  • @Trixx I am afraid this message is defined as `&` or `& &`, – Jagger Dec 03 '18 at 17:17
  • @Jagger: '&' or '&1' are the placeholders where to fill in the parameter texts from the variables 1-4. If nothing else is there, it means that there are no language specific texts, so the full message text would simply be "No authorization" in this case then. In theory, everyone could use any message class. But yes, you are right, usually this is used by SAP standard functionality. – Trixx Dec 03 '18 at 17:37
  • @guettli Meanwhile I have checked it in the system and the message is defined as `&1&2&3&4&5&6&7&8` which is awkward because technically there can be only 4 placeholders. Would you tell us the name of this function module or not? Help us to help yourself. – Jagger Dec 04 '18 at 06:55
  • @Jagger I don't think the name of this function module makes sense. The error message of this question is just one example. I care for the general goal. I want a stacktrace like python has. – guettli Dec 04 '18 at 09:05
  • @guettli If it is just a regular error message (without a short dump) you won't get any stacktrace by definition. Not even if your are only inside SAP (well, unless you are there in debug mode). – Jagger Dec 04 '18 at 13:10
  • @Jagger even HANA can't do this? – guettli Dec 04 '18 at 14:12
  • @guettli No, unless you are working with SAP HANA Studio. From the question I understand however that you use a function module, this means you are using the layer of SAP Application Server. HANA is then just an underlying database for it, nothing more, The stack is kept in the application server and it does not care whether the underlying database is Oracle, IBM DB2 or S/4 HANA. – Jagger Dec 05 '18 at 09:48
  • @Jagger can SAP HANA Studio be used for developing with SAP 7.4? – guettli Dec 05 '18 at 10:19
  • @guettli Well, not if you speak about ABAP. S/4 HANA has its own language as far as I know and this language can be used in SAP HANA Studio. There is however a possibility to develop in ABAP using Eclipse. – Jagger Dec 05 '18 at 10:21
  • @Jagger can Eclipse show me a stacktrace if my ABAP code fails? – guettli Dec 05 '18 at 11:44

2 Answers2

1

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!

J.Gerbershagen
  • 316
  • 1
  • 3
1

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( ) ).
Suncatcher
  • 10,355
  • 10
  • 52
  • 90