Application Development 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: 

Get the class attributes references dynamically?

Former Member
0 Kudos

Hi all,

I have to call a transformation and give it as result parameter an internal table with ABAP_TRANS_RESBIND_TAB type.

How can I get the name & the reference of the current class attributes ?

Thanks.

4 REPLIES 4

MarcinPciak
Active Contributor
0 Kudos

I am not sure what you want to need, but please check this class CL_ABAP_CLASSDESCR. It may help you.

Former Member
0 Kudos

hi,

You can get the reference to current class object threw 'ME'.

'ME' refer to current class object.

and threw it u can get access current object attribute.

If still you are facing any problem .

please let me know.

Regards .

Punit

Former Member
0 Kudos

Hi,

View: VSEOATTRIB. It contains the metadata regarding the Attributes of the Class.

0 Kudos

Here is the solution I wound, but it works with public attributes only!



  DATA: l_typedesc TYPE REF TO cl_abap_typedescr.
  data: l_classdesc TYPE REF TO cl_abap_classdescr.
  data: l_attribute TYPE abap_attrdescr.
  data : att_ref type ref to any.
  FIELD-SYMBOLS : <att> TYPE ANY . "abap_attrname.
  DATA : name TYPE string.

  CLEAR st_root_out.
  CALL METHOD cl_abap_classdescr=>describe_by_object_ref 
  EXPORTING
  p_object_ref = me
  RECEIVING
  p_descr_ref = l_typedesc.

  l_classdesc ?= l_typedesc.

  LOOP AT l_classdesc->attributes INTO l_attribute "-
  WHERE type_kind = cl_abap_classdescr=>typekind_string "-
  OR type_kind = cl_abap_classdescr=>typekind_num "-
  OR type_kind = cl_abap_classdescr=>typekind_date "-
  OR type_kind = cl_abap_classdescr=>typekind_packed "-
  OR type_kind = cl_abap_classdescr=>typekind_time "-
  OR type_kind = cl_abap_classdescr=>typekind_char "-
  OR type_kind = cl_abap_classdescr=>typekind_hex "-
  OR type_kind = cl_abap_classdescr=>typekind_float "-
  OR type_kind = cl_abap_classdescr=>typekind_int "-
  OR type_kind = cl_abap_classdescr=>typekind_table "-
  OR type_kind = cl_abap_classdescr=>typekind_struct2 "-
  OR type_kind = cl_abap_classdescr=>typekind_struct1 "-
  OR type_kind = cl_abap_classdescr=>typekind_oref
  OR type_kind = cl_abap_classdescr=>typekind_time. "-

    name = l_attribute-name .

    ASSIGN me->(name) TO <att>.

    CHECK sy-subrc = 0.

    GET REFERENCE OF <att> INTO att_ref. " here I get the reference



  
  ENDLOOP.