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

System Variable which stores Method name

Former Member
1,515

Hi;

Is there any system variable like SY-REPID or CPROG which I can use inside a method to know the Class and the Method name?

SG.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
991

Hello

Sample report ZUS_SDN_LOCAL_CALL_SYSTEMSTACK shows you how to solve your problem:


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_LOCAL_CALL_SYSTEMSTACK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_local_call_systemstack.


*----------------------------------------------------------------------*
*       CLASS lcl_myclass DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass DEFINITION.

  PUBLIC SECTION.
    CLASS-METHODS:
      method_one,
      method_two,
      get_system_stack
        RETURNING value(rd_method)  TYPE string.

ENDCLASS.                    "lcl_myclass DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_myclass IMPLEMENTATION
*----------------------------------------------------------------------*
* Thread: System Variable which stores Method name
* <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1294681"></a>
*----------------------------------------------------------------------*
CLASS lcl_myclass IMPLEMENTATION.


  METHOD get_system_stack.
* define local data
    DATA: ld_next         TYPE i,
          lt_callstack    TYPE abap_callstack,
          ls_call         TYPE abap_callstack_line.

    CALL FUNCTION 'SYSTEM_CALLSTACK'
        EXPORTING
          MAX_LEVEL          = 2
      IMPORTING
        callstack          = lt_callstack
*         ET_CALLSTACK       =
              .

    LOOP AT lt_callstack TRANSPORTING NO FIELDS
            WHERE ( blocktype = 'METHOD'
            AND     blockname = 'GET_SYSTEM_STACK' ).
      ld_next = syst-tabix + 1.
      EXIT.
    ENDLOOP.

    READ TABLE lt_callstack INTO ls_call INDEX ld_next.
    rd_method = ls_call-blockname.

  ENDMETHOD.                    "get_system_stack

  METHOD method_one.
    DATA: ld_string  TYPE string.

    ld_string = lcl_myclass=>get_system_stack( ).
    MESSAGE ld_string TYPE 'I'.

  ENDMETHOD.                    "method_one

  METHOD method_two.
    DATA: ld_string  TYPE string.

    ld_string = lcl_myclass=>get_system_stack( ).
    MESSAGE ld_string TYPE 'I'.


  ENDMETHOD.                    "method_two
ENDCLASS.                    "lcl_myclass IMPLEMENTATION


START-OF-SELECTION.

  BREAK-POINT.

  lcl_myclass=>method_one( ).
  lcl_myclass=>method_two( ).

Regards

Uwe

3 REPLIES 3
Read only

uwe_schieferstein
Active Contributor
0 Likes
992

Hello

Sample report ZUS_SDN_LOCAL_CALL_SYSTEMSTACK shows you how to solve your problem:


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_LOCAL_CALL_SYSTEMSTACK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_local_call_systemstack.


*----------------------------------------------------------------------*
*       CLASS lcl_myclass DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass DEFINITION.

  PUBLIC SECTION.
    CLASS-METHODS:
      method_one,
      method_two,
      get_system_stack
        RETURNING value(rd_method)  TYPE string.

ENDCLASS.                    "lcl_myclass DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_myclass IMPLEMENTATION
*----------------------------------------------------------------------*
* Thread: System Variable which stores Method name
* <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1294681"></a>
*----------------------------------------------------------------------*
CLASS lcl_myclass IMPLEMENTATION.


  METHOD get_system_stack.
* define local data
    DATA: ld_next         TYPE i,
          lt_callstack    TYPE abap_callstack,
          ls_call         TYPE abap_callstack_line.

    CALL FUNCTION 'SYSTEM_CALLSTACK'
        EXPORTING
          MAX_LEVEL          = 2
      IMPORTING
        callstack          = lt_callstack
*         ET_CALLSTACK       =
              .

    LOOP AT lt_callstack TRANSPORTING NO FIELDS
            WHERE ( blocktype = 'METHOD'
            AND     blockname = 'GET_SYSTEM_STACK' ).
      ld_next = syst-tabix + 1.
      EXIT.
    ENDLOOP.

    READ TABLE lt_callstack INTO ls_call INDEX ld_next.
    rd_method = ls_call-blockname.

  ENDMETHOD.                    "get_system_stack

  METHOD method_one.
    DATA: ld_string  TYPE string.

    ld_string = lcl_myclass=>get_system_stack( ).
    MESSAGE ld_string TYPE 'I'.

  ENDMETHOD.                    "method_one

  METHOD method_two.
    DATA: ld_string  TYPE string.

    ld_string = lcl_myclass=>get_system_stack( ).
    MESSAGE ld_string TYPE 'I'.


  ENDMETHOD.                    "method_two
ENDCLASS.                    "lcl_myclass IMPLEMENTATION


START-OF-SELECTION.

  BREAK-POINT.

  lcl_myclass=>method_one( ).
  lcl_myclass=>method_two( ).

Regards

Uwe

Read only

0 Likes
991

Uwe:

Basically I wanted to check the method name inside a Class of a PROXY. The FM which you have used gives me all the details I need. Thanks a Lot!!

Read only

0 Likes
991

Uwe:

Basically I wanted to check the method name inside a Class of a PROXY. The FM which you have used gives me all the details I need. Thanks a Lot!!