Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Creating Objects →  CREATE DATA →  CREATE DATA - TYPE, LIKE 

Creating Structured Data Objects

The example demonstrates the creation of structured data objects

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA dref TYPE REF TO data.

    FIELD-SYMBOLS: <wa>   TYPE any,
                   <comp> TYPE any.

    demo=>check_existence_and_authority( ).

    TRY.
        CREATE DATA dref TYPE (dbtab).
        ASSIGN dref->* TO <wa>.
        SELECT *
               FROM (dbtab) UP TO rows ROWS
               INTO <wa>.
          DO.
            ASSIGN COMPONENT sy-index
                   OF STRUCTURE <wa> TO <comp>.
            IF sy-subrc = 0.
              WRITE / <comp>.
            ELSE.
              EXIT.
            ENDIF.
          ENDDO.
          ULINE.
        ENDSELECT.
      CATCH cx_sy_create_data_error.
        WRITE 'Error in data creation'.
    ENDTRY.

Description

Creating a work area that matches any database table and reading the first rows (rows) of the database table into this work area using a SELECT loop. Since the dref data reference is dynamically typed, access to the work area can only take place using the <wa> field symbol. A further field symbol, <comp>, is required for dynamic access to individual components.