ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Attributes of Data Objects
RTTS - Runtime Type Services
The RTTS are implemented using a hierarchy of type description classes that contain the methods for Runtime Type Creation (RTTC) and Runtime Type Identification (RTTI). Using these system classes it is possible to
- determine type information of existing instances and type names in the ABAP type system at runtime.
- define new data types at runtime.
Other versions: 7.31 | 7.40 | 7.54
Concept
The properties of the types are represented by the attributes of type description objects. For each type there is exactly one type description object. The attributes of the type description object contain information about the properties of the type. For each category of type (elementary type, table, class, and so on), there is a type description class with special attributes for the special type properties. The class hierarchy of the type description classes corresponds to the hierarchy of the type categories in the ABAP type system.
In addition, type description classes for complex types, references, classes, and interfaces have special methods for specifying references to partial types. These methods can be used can navigate to all partial types using a composite type.
Type description objects can only be created using the methods of type description classes. To get a reference to a type description object of a type, the static methods of the class CL_ABAP_TYPEDESCR can be used or call methods of the special type description classes.
Note
In the statement CREATE DATA
,
type description objects can be specified after the addition HANDLE
to create data objects with dynamically created data types.
Hierarchy of Type Description Classes
CL_ABAP_TYPEDESCR
|
|--CL_ABAP_DATADESCR
| |
| |--CL_ABAP_ELEMDESCR
| | |
| | |--CL_ABAP_ENUMDESCR
| |
| |--CL_ABAP_REFDESCR
| |--CL_ABAP_COMPLEXDESCR
| |
| |--CL_ABAP_STRUCTDESCR
| |--CL_ABAP_TABLEDESCR
|
|--CL_ABAP_OBJECTDESCR
|
|--CL_ABAP_CLASSDESCR
|--CL_ABAP_INTFDESCR
Example
Reading the type attributes of an elementary type from a type object generated with the method DESCRIBE_BY_DATA.
TYPES my_type TYPE p LENGTH 16 DECIMALS 6.
DATA my_data TYPE my_type.
DATA(descr) = cl_abap_typedescr=>describe_by_data( my_data ).
cl_demo_output=>display(
|Typename: { descr->absolute_name }\n| &&
|Kind: { descr->type_kind }\n| &&
|Length: { descr->length }\n| &&
|Decimals: { descr->decimals }\n| ).
Example
Reading the attributes of the components of a structure. The reference to the type object is assigned using a down cast to a reference variable of type CL_ABAP_STRUCT_DESCR.
cl_demo_output=>display( CAST cl_abap_structdescr(
cl_abap_typedescr=>describe_by_name( 'SYST' ) )->components ).