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

How can I get the function name from within a function?

Former Member
0 Likes
3,649

Hi all,

I would like to dynamically get the name of the function module within which my INCLUDED code is sitting - i.e. I do not want the includes name or the calling programs name, but the function name within which the include is sitting...

Just like SY-CPROG returns the ABAP program name within which the function is being called, I wish to know what the actual functions name is? Is this possible?

Thanks for any help!

N

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,055

Hi nk,

1. use the FM SYSTEM_CALLSTACK

(inside the FM code)

2. It will return an internal table

3. just read the first row (index 1)

and u will get the current FM (which is being called)

regards,

amit m.

5 REPLIES 5
Read only

Former Member
0 Likes
2,056

Hi nk,

1. use the FM SYSTEM_CALLSTACK

(inside the FM code)

2. It will return an internal table

3. just read the first row (index 1)

and u will get the current FM (which is being called)

regards,

amit m.

Read only

Former Member
0 Likes
2,055

You can do that using

CALL FUNCTION 'SYSTEM_CALLSTACK'

BR, JAcek

Read only

Former Member
0 Likes
2,055

Hi,

call the FM <b>SYSTEM_CALLSTACK</b>, this will give you the stack table here you can see all the calls.

Regards

vijay

Read only

0 Likes
2,055

Excellent! Thanks guys! Will reward points...

Read only

ray_mannion
Participant
0 Likes
2,055

Consider where in the callstack you expect to be since the callstack may contain several function calls.

This logic returns the most recently called function.

    LOOP AT cl_abap_get_call_stack=>format_call_stack_with_struct(
        stack = cl_abap_get_call_stack=>get_call_stack( )
      )
      ASSIGNING FIELD-SYMBOL(<stack_line>).
      IF <stack_line>-kind = 'FUNCTION'.
        function_name = <stack_line>-event.
        EXIT.
      ENDIF.
    ENDLOOP.