Entering content frame

Self-Defined Table Types Locate the document in its SAP Library structure

You can start a screen sequence from an ABAP program using

TYPES dtype TYPE|LIKE tabkind OF linetype [WITH key] ... .

This defines an internal table type with access type tabkind, line type linetype and key key. The line type linetype can be any known data type. Specifying the key is optional. Internal tables can thus be generic.

Internal Tables

The syntax for declaring an internal table directly as a data type of a variable is the same as you would use to define one using the TYPES statement:

DATA itab TYPE|LIKE tabkind OF linetype [WITH key] ... .

The variable itabis declared as an internal table with access type tabkind, line type linetype, and key key. The line type linetype can be any known data type.

For more information, refer to Internal Tables.

Range Tables

Using the statements:

TYPES dtype {TYPE RANGE OF type}|{LIKE RANGE OF dobj} ... .
DATA rtab {TYPE RANGE OF type}|{LIKE RANGE OF dobj} ... .

you can define a special table type as a separate data type for Range tables, or as an attribute of the data object rtab of the type standard table, with a standard key and a specially structured line type.

For more information on Range Tables see the keyword documentation.

Example

PROGRAM demo_internal_table.

TYPES: BEGIN OF mytext,
         number TYPE i,
         name   TYPE c
LENGTH 10,
       END OF mytext.

TYPES mytab TYPE STANDARD TABLE OF mytext WITH DEFAULT KEY.

DATA text TYPE mytext.
DATA itab TYPE mytab.

text-number = 1. text-name = 'John'.
APPEND text TO itab.

text-number = 2. text-name = 'Paul'.
APPEND text TO itab.

text-number = 3. text-name = 'Ringo'.
APPEND text TO itab.

text-number = 4. text-name = 'George'.
APPEND text TO itab.

LOOP AT itab INTO text.
  WRITE: / text-number, text-name.
ENDLOOP.

This program produces the following output on the screen:

1  John

2  Paul

3  Ringo

4  George

In this example, first a data type mytext is defined as a structure. Then, a data type mytab is defined as an internal table with the line type mytext. The data objects text and itab  are declared with reference to the internal data types mytext und mytab. This lines of the internal table itab are generated dynamically with the APPEND statement. The contents of the internal table itab are written to the list using the structure text. See also: Internal Tables

 

Leaving content frame