cancel
Showing results for 
Search instead for 
Did you mean: 

How to get object/instance name in method

Former Member
0 Kudos
1,282

Hi folks,

I have created a class and implemented a method within the class.

Now i would like get the name of instance/object calling this method ,within this method.

Is their any way to get this obj name within method?

Eg:

I hve class ZCL with method METH

Now in some program i used this method, by creating any obj

data obj type ref to ZCL

obj->METH

Now is there any way to get this obj name within the methodMETH by using some method like GET_OBJ_NAME(just making a guess)

Regards

PG

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

>

> Now is there any way to get this obj name within the methodMETH by using some method like GET_OBJ_NAME(just making a guess)

>

> Regards

> PG

Please check the below code snippet


  DATA:
    lref_obj TYPE REF TO cl_abap_typedescr.

  lref_obj ?= cl_abap_objectdescr=>describe_by_object_ref( me ).

raymond_giuseppi
Active Contributor
0 Kudos

Just use the self-reference ME in the method.

Regards,

Raymond

Former Member
0 Kudos

Hi Raymond

Thanks for reply.

Ho will i use ME to get the name OBJ?

Is their any method with some parameter returning the name of instance?

eg:

ME->get_instance_name( instance_name = lv_instance ) " Just a gues"

Regards

PG

raymond_giuseppi
Active Contributor
0 Kudos

Look at class CL_ABAP_CLASSDESCR, or use a systeme call

SYSTEM-CALL DESCRIBE CLASS XTYPE
    INTO DREF->ABSOLUTE_NAME

Regards,

Raymond