Classes for Determining Type Properties at Runtime
(Run-Time Type Identification RTTI)

You can use the following system classes to determine type information for all types in the ABAP type system at runtime. To do this, you can use data objects, objects, and type names.

Concept

For each type, there is exactly one description object. The attributes of the description object contain information about the properties of the type. For each type category (for example, elementary type, table, class, ...), there is one description class with special attributes for the specific type properties. The class hierarchy of the description classes corresponds to the hierarchy of the type categories of the ABAP type system.

The description classes for complex types, references, classes, and interfaces have special methods to determine references to partial types. Using these methods, you can navigate to all partial types through a composite type.

To get a reference to a description object of a type, you must use the static methods of the class CL_ABAP_TYPEDESCR or call navigation methods of the specific description classes. Description objects can only be created with these methods.

Class Hierarchy

O CL_ABAP_TYPEDESCR
  |
  |-- O CL_ABAP_DATADESCR
  |   |
  |   |-- O CL_ABAP_ELEMDESCR
  |   |-- O CL_ABAP_REFDESCR
  |   |-- O CL_ABAP_COMPLEXDESCR
  |       |
  |       |-- O CL_ABAP_STRUCTDESCR
  |       |-- O CL_ABAP_TABLEDESCR
  |
  |-- O CL_ABAP_OBJECTDESCR
     |
     |-- O CL_ABAP_CLASSDESCR
     |-- O CL_ABAP_INTFDESCR

Example

REPORT typedescr_test.

TYPES:
  my_type TYPE i.

DATA:
  my_data   TYPE my_type,
  descr_ref TYPE ref to cl_abap_typedescr.

START-OF-SELECTION.
  descr_ref = cl_abap_typedescr=>describe_by_data( my_data ).

  WRITE: / 'Typename:', descr_ref-> absolute_name.
  WRITE: / 'Kind    :', descr_ref->type_kind.
  WRITE: / 'Length  :', descr_ref->length.
  WRITE: / 'Decimals:', descr_ref->decimals.