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

Class name from object

Former Member
0 Likes
7,412

Hi All,

I have an object and I want to know th name of the class to which the object belongs. Can some body help me on this.

Regards,

Jenish.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
2,389

Hello Jenish

Since you need to know runtime information you should use the appropriate <b>RTTI </b>classes.

Either you use class <b>CL_ABAP_CLASSDESCR</b> or you could use the following sample coding:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_RUNTIME
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_runtime.


TYPE-POOLS: abap.

DATA:
  gd_class          TYPE abap_abstypename,
*  go_classdescr     type ref to cl_abap_classdescr,
  go_docking        TYPE REF TO cl_gui_docking_container.


START-OF-SELECTION.

  CREATE OBJECT go_docking.

  gd_class = cl_abap_classdescr=>get_class_name( go_docking ).

  WRITE: / 'Class', gd_class.


END-OF-SELECTION.

Regards

Uwe

5 REPLIES 5
Read only

h_senden2
Active Contributor
0 Likes
2,389

Double click on the object's name in the abap editor, and you will the data declaration of the object :

data: l_object type ref to zcl_class.

ZCL_CLASS is the requested class.

regards,

Hans

Please reward all helpful answers !!!!!

Read only

Former Member
0 Likes
2,389

I wand to get the class name at runtime. I have a variable which carries the reference of some object. From this object I want to find the name of the class to which the object refers.

Read only

Former Member
0 Likes
2,389

Hi Jenish,

Please check the static public method CF_ISSR_BASI_OBJECT=>GET_CLASSNAME.

You need to pass the object instance to this method to get the class name.

Hope this helps.

Thanks,

Rashmi.

Message was edited by:

Rashmi Joshi

Read only

uwe_schieferstein
Active Contributor
0 Likes
2,390

Hello Jenish

Since you need to know runtime information you should use the appropriate <b>RTTI </b>classes.

Either you use class <b>CL_ABAP_CLASSDESCR</b> or you could use the following sample coding:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_RUNTIME
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_runtime.


TYPE-POOLS: abap.

DATA:
  gd_class          TYPE abap_abstypename,
*  go_classdescr     type ref to cl_abap_classdescr,
  go_docking        TYPE REF TO cl_gui_docking_container.


START-OF-SELECTION.

  CREATE OBJECT go_docking.

  gd_class = cl_abap_classdescr=>get_class_name( go_docking ).

  WRITE: / 'Class', gd_class.


END-OF-SELECTION.

Regards

Uwe

Read only

Former Member
0 Likes
2,389

Hi,

That solves my problem. Thanks

Regards,

Jenish.