Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Creating Objects and Values →  CREATE DATA →  CREATE DATA dref 

Creating Data Objects with Implicit Type

This example demonstrates how data objects are created with an implicit type.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    TYPES t_itab TYPE TABLE OF i WITH NON-UNIQUE KEY table_line.

    DATA: tab_ref TYPE REF TO t_itab,
          i_ref   TYPE REF TO i.

    IF tab_ref IS INITIAL.
      CREATE DATA tab_ref.
    ENDIF.

    tab_ref->* = VALUE #( FOR j = 1 UNTIL j > 10 ( j ) ).

    IF tab_ref IS NOT INITIAL.
      IF i_ref IS INITIAL.
        CREATE DATA i_ref.
      ENDIF.
      LOOP AT tab_ref->* INTO i_ref->*.
        cl_demo_output=>write( |{ i_ref->* }| ).
      ENDLOOP.
    ENDIF.
    cl_demo_output=>display( ).

    CLEAR: tab_ref, i_ref.

Description

Creates an internal table and a data object of type i. The data types of the objects in question are the static types of the reference variables tab_ref and i_ref. The data objects are created directly before they are used and are then initialized by the reference variables and passed to the garbage collector. The data objects are accessed by dereferencing the data references.