cancel
Showing results for 
Search instead for 
Did you mean: 

get name of current method

joachim_gross
Product and Topic Expert
Product and Topic Expert
0 Kudos
2,557

I need to know a way to find out the name of the currently running method.

eg:

method abc.

data: m_name type abap_methname.

m_name = xxx->current_method( ).

endmethod.

m_name should be 'ABC'.

If course i know the name on design time but it is not my aim to use literals.

So does anyone know how to get the method name?

TIA Joachim

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

try this (I got it to work, but let me know if it works for you:

data: f1(100) type c.

get parameter id 'DBG_SOURCE_PROGRAM' field f1.

joachim_gross
Product and Topic Expert
Product and Topic Expert
0 Kudos

Sorry Paul,

this is nothing but the started program.

I need the methodname, so above mentioned function module or following snippet is useful:

types:

begin of t_abap_callstack_entry,

mainprogram type dbgsrepid,

include type dbgsrepid,

line type dbglinno,

eventtype type dbglevtype,

event type dbglevent,

flag_system type c length 1,

end of t_abap_callstack_entry,

t_abap_callstack type standard table of t_abap_callstack_entry with default key.

DATA: l_tab_aut_callstack TYPE lcl_abapunit_callstack=>t_abap_callstack,

l_str_aut_callstack TYPE lcl_abapunit_callstack=>t_abap_callstack_entry.

call 'ABAP_CALLSTACK'

id 'DEPTH' field -10

id 'CALLSTACK' field l_tab_aut_callstack.

Regards;

Joachim

Former Member
0 Kudos

Hi Joachim, would it be possible to share source code of class lcl_abapunit_callstack? Thanks&regards, Martin

joachim_gross
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Martin,

sorry for the typo, in the snippet the class lcl-abapunit_callstack is not needed.

Rememeber the function module but for those interested in the correct snippet:

types:

begin of t_abap_callstack_entry,

mainprogram type dbgsrepid,

include type dbgsrepid,

line type dbglinno,

eventtype type dbglevtype,

event type dbglevent,

flag_system type c length 1,

end of t_abap_callstack_entry,

t_abap_callstack type standard table of

t_abap_callstack_entry with default key.

DATA: l_tab_aut_callstack TYPE t_abap_callstack,

l_str_aut_callstack TYPE t_abap_callstack_entry.

call 'ABAP_CALLSTACK'

id 'DEPTH' field -10

id 'CALLSTACK' field l_tab_aut_callstack.

Regards;

Joachim

Postscriptum:

Classes lcl_abapunit* are not identical to ABAP Unit as part of ABA >=640

Former Member
0 Kudos

Hi,

and the second entry in the stack table have in the field event the method name...

Regards,

Gianpietro

Former Member
0 Kudos

shorly u will always no the name of the method or have a variable containing its name.. wont you?, otherwise how will you call it?

joachim_gross
Product and Topic Expert
Product and Topic Expert
0 Kudos

The method is called from the ABAPUnit-class.

So i cannot change the caller and i have to know the methodname on runtime.

Of course I could use a literal but that's no good. Best way is as already mentioned to use the fm system_callstack.

Regards;

Joachim

joachim_gross
Product and Topic Expert
Product and Topic Expert
0 Kudos

In the sap.devel.lang.abap i got the right hint.

Use the call stack via function module system_callstack.

ChristianFi
Active Participant
0 Kudos

Maybe you can use FM SYSTEM_CALLSTACK for that purpose.

Christian.