Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Declaring Data Types →  TYPES 

TYPES - TABLE OF

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


TYPES table_type { {TYPE tabkind OF [REF TO] type} 
              | {LIKE tabkind OF dobj} }
          [tabkeys]
                 [INITIAL SIZE n].

Addition

... INITIAL SIZE n

Effect

This statement defines a table type table_type with a specific row type, a table category tabkind, and table keys tabkeys.

The row type is determined by entering the data type type after TYPE and data type dobj after LIKE:

  • type can be a non-generic data type from ABAP Dictionary, a non-generic public data type of a public data type or global class, a non-generic data type local to a program, or any ABAP type from the tables of predefined ABAP types. The generic ABAP types c, n, p, and x are implicitly extended to the standard length without decimal places from the tables of predefined ABAP types.

    If the addition REF TO is specified before type or dobj, then the row type is a reference type. The information specified in section reference types can then be entered for type and dobj.
  • The same applies to dobj as to TYPES ... LIKE.


Note

The use of the addition OCCURS for defining table types is obsolete.

Addition

... INITIAL SIZE n

Effect

The optional addition INITIAL SIZE has two meanings:

  • Note for the internal memory management of internal tables

    Internal tables are stored in the memory block by block. After the optional addition INITIAL SIZE, it is possible to specify a number of rows n directly as a positive number without sign or as a numeric constant to notify the system of the size of the initial block in the memory (reserved by the system for an internal table of the table type). By default, and if n is specified as 0, the system allocates a suitable initial memory area automatically.

    If the initial memory area is not large enough, further blocks are created using a duplicate strategy until a maximum size is reached. After this, all blocks are created with a constant size between eight and 16 KB.

    If the value of n causes the initial blocks to become too big, the size of the initial memory area is also defined by the system.
  • Size of Rankings

    To create a ranking in the internal table using the addition SORTED BY of the statement APPEND, specify a value greater than 0 after INITIAL SIZE and this determines the size of the ranking.

Programming Guideline

Modify the initial memory requirements only for nested tables


Notes

  • It is advisable to specify the initial memory requirements only when the number of entries in the table has already been specified and the initial main memory requirement has an adequate value. This can be especially important for internal tables that are components of table types and only contain a few rows.
  • Instead of APPEND SORTED BY, the statement SORT must be used so that the addition INITIAL SIZE is no longer required here.

Example

Defines a non-generic sorted table type. The row type corresponds to the structure of the database table SPFLI. Two key fields are defined for the primary table key.

TYPES spfli_sort TYPE SORTED TABLE OF spfli 
      WITH UNIQUE KEY carrid connid. 

Continue

TYPES - tabkind

TYPES - tabkeys

Internal Tables, Nested Tables - Example