Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Current method name (method meta data)

former_member185943
Participant
0 Likes
877

Hello!

Is it possible to get meta data about current method being executed? For example:

CLASS lcl_some_class IMPLEMENTATION.
  METHOD some_method.
    DATA: l_method_name TYPE char50.
*   (do something to get method name)
    WRITE 'Current method is: ', l_method_name.
  ENDMETHOD.
ENDCLASS.

And the result would be something like:

LCL_SOME_CLASS->SOME_METHOD

Thanks!

Regards,

Igor

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
455

Hi Igor, this may not be fool proof, but it does work in my case.




report zrich_0003 .

*---------------------------------------------------------------------*
*       CLASS lcl_some_class DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_some_class definition.

  public section.
    class-methods: some_method.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_some_class IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_some_class implementation.
  method some_method.
    data: l_method_name type char50.
    data: icallstack type sys_callst.
    data: xcallstack like line of icallstack.

    call function 'SYSTEM_CALLSTACK'
         importing
              et_callstack = icallstack.


    read table icallstack into xcallstack index 1.
    if sy-subrc  = 0 and xcallstack-eventtype = 'METH'.
      l_method_name = xcallstack-eventname.
    endif.

*   (do something to get method name)
    write:/ 'Current method is: ', l_method_name.
  endmethod.
endclass.


start-of-selection.

  call method lcl_some_class=>some_method.

Regards,

Rich Heilman

2 REPLIES 2
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
456

Hi Igor, this may not be fool proof, but it does work in my case.




report zrich_0003 .

*---------------------------------------------------------------------*
*       CLASS lcl_some_class DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_some_class definition.

  public section.
    class-methods: some_method.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_some_class IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_some_class implementation.
  method some_method.
    data: l_method_name type char50.
    data: icallstack type sys_callst.
    data: xcallstack like line of icallstack.

    call function 'SYSTEM_CALLSTACK'
         importing
              et_callstack = icallstack.


    read table icallstack into xcallstack index 1.
    if sy-subrc  = 0 and xcallstack-eventtype = 'METH'.
      l_method_name = xcallstack-eventname.
    endif.

*   (do something to get method name)
    write:/ 'Current method is: ', l_method_name.
  endmethod.
endclass.


start-of-selection.

  call method lcl_some_class=>some_method.

Regards,

Rich Heilman

Read only

0 Likes
455

Thanks, Rich!

Good enough for me. I can get the class name using RTTI, so I guess I have it all.

Regards,

Igor