Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Creating Objects →  CREATE DATA →  CREATE DATA - TABLE OF 

Creating Tabular Data Objects

The example demonstrates the creation of tabular data objects

Other versions: 7.31 | 7.40 | 7.54

Source Code

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

    demo=>check_existence_and_authority( ).

    TRY.
        CREATE DATA dref TYPE STANDARD TABLE OF (dbtab)
                              WITH NON-UNIQUE DEFAULT KEY.
        ASSIGN dref->* TO <table>.
        SELECT *
               FROM (dbtab) UP TO rows ROWS
               INTO TABLE <table>.
        LOOP AT <table> ASSIGNING <wa>.
          DO.
            ASSIGN COMPONENT sy-index
                   OF STRUCTURE <wa> TO <comp>.
            IF sy-subrc = 0.
              WRITE / <comp>.
            ELSE.
              EXIT.
            ENDIF.
          ENDDO.
          ULINE.
        ENDLOOP.
      CATCH cx_sy_create_data_error.
        WRITE 'Error in data creation'.
    ENDTRY.

Description

Creating an internal table that matches any database table and reading the first rows (rows) of the database into the internal table. Since the dref data reference is dynamically typed, access to the internal table can only take place using the <tab> field symbol. The field symbols <wa> and <comp> are required for dynamic access to the individual rows and components.

The method CHECK_TABLE_NAME_STR of the class CL_ABAP_DYN_PRG checks whether the database table specified exists and can be used.