Properties of SAP ABAP Development Objects

Similar to reflection in JAVA we have RTTS in SAP. RTTS stands for Runtime Type Services. It provides you with ways to retrieve the definitions of variables and lets you create a new variable during program execution. RTTS comprises of two sub-components ?

  • RTTI ? Run Time Type Identification
  • RTTC ? Run Time Type Creation

As the name suggests, RTTI is responsible for retrieving the definitions of variables and types whereas RTTC is responsible for the creation of new variables with provided definition at run-time.

RTTI ? Run Time Type Identification

RTTI allows you to inspect type information at runtime. It provides methods to examine the properties of data types, structures, and objects during program execution. This is useful for dynamic programming scenarios where type information needs to be determined at runtime.

Example

Here's how to use RTTI to get type information ?

DATA: lv_string TYPE string,
      lo_type_desc TYPE REF TO cl_abap_typedescr.

lo_type_desc = cl_abap_typedescr=>describe_by_data( lv_string ).

WRITE: 'Type kind:', lo_type_desc->type_kind,
       'Length:', lo_type_desc->length.

RTTC ? Run Time Type Creation

RTTC enables dynamic creation of new data types and variables at runtime. This powerful feature allows you to create structures, tables, and other complex data types based on runtime conditions or requirements.

Example

Creating a dynamic internal table using RTTC ?

DATA: lo_struct_type TYPE REF TO cl_abap_structdescr,
      lo_table_type  TYPE REF TO cl_abap_tabledescr,
      lr_data        TYPE REF TO data.

" Create table type dynamically
lo_table_type = cl_abap_tabledescr=>create( 
  p_line_type = cl_abap_typedescr=>describe_by_name( 'MARA' ) ).

" Create data object
CREATE DATA lr_data TYPE HANDLE lo_table_type.

Conclusion

RTTS provides powerful runtime capabilities in SAP ABAP, enabling dynamic type inspection through RTTI and dynamic type creation through RTTC, making applications more flexible and adaptable to changing requirements.

Updated on: 2026-03-13T18:04:56+05:30

303 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements