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: 

ref_descr ?= cl_abap_typedescr=>describe_by_name explanation

Former Member
0 Kudos

Hello Everyone,

Can somebody explain what is happening

in this part of the code. Below the complete code.

-


ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).

it_details[] = ref_descr->components[].

-


One more request, what are these structures

abap_compdescr_tab, abap_compdescr, cl_abap_structdescr, lvc_s_fcat are these tables? Please kindly let me know

-


data : it_details type abap_compdescr_tab,

wa_details type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.

data: new_table type ref to data,

new_line type ref to data,

wa_it_fldcat type lvc_s_fcat.

ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).

it_details[] = ref_descr->components[].

loop at it_details into wa_details.

clear wa_it_fldcat.

if wa_details-name = 'TIMESTMP'.

wa_it_fldcat-fieldname = wa_details-name.

wa_it_fldcat-datatype = wa_details-type_kind.

wa_it_fldcat-inttype = wa_details-type_kind.

wa_it_fldcat-intlen = r.

wa_it_fldcat-decimals = wa_details-decimals.

append wa_it_fldcat to it_fldcat.

append wa_it_fldcat-fieldname to it1.

else.

wa_it_fldcat-fieldname = wa_details-name.

wa_it_fldcat-datatype = wa_details-type_kind.

wa_it_fldcat-inttype = wa_details-type_kind.

wa_it_fldcat-intlen = wa_details-length.

wa_it_fldcat-decimals = wa_details-decimals.

append wa_it_fldcat to it_fldcat.

append wa_it_fldcat-fieldname to it1.

endif.

endloop.

Thanks

Krishna

1 REPLY 1

uwe_schieferstein
Active Contributor

Hello Krishna

The static method cl_abap_typedescr=>describe_by_name returns an instance of type CL_ABAP_TYPEDESCR.

This class is a superclass of CL_ABAP_STRUCTDESCR (the inheritance hierarchy is:

CL_ABAP_TYPEDESCR -> CL_ABAP_DATADESCR -> CL_ABAP_COMPLEXDESCR -> CL_ABAP_STRUCTDESCR).

In the statement

ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].

we have a widening cast ('?=') from CL_ABAP_TYPEDESCR (returned value) to CL_ABAP_STRUCTDESCR (descr_ref variable).

Now <i>p_table</i> represents a structure (like 'SFLIGHT'). The components of this structure, i.e. the table fields, are found in the public attribute ref_descr->components.

Please note that it is unnecessary to write

ref_descr->components<b>[]</b>

because in ABAP-OO it is not allowed to use itabs with header lines but exclusively table types.

The other classes (like cl_abap_typedescr, cl_abap_compdescr) are used to get the runtime type information (RTTI) of different DDIC objects.

Regards

Uwe