Definition of an internal table type

TYPES - Definition of an Internal Table Type

Variants:
1. TYPES itabtype {TYPE tabkind OF linetype|
LIKE tabkind OF lineobj}
[WITH [UNIQUE|NON-UNIQUE] keydef] [INITIAL SIZE n].

2. TYPES itabtype {TYPE linetype|LIKE lineobj} OCCURS n.

Effect

Defines a user-defined type (see

ABAP

type concept) for an internal table.

Variant 1

TYPES itabtype {TYPE tabkind OF linetype|
LIKE tabkind OF lineobj}
[WITH [UNIQUE|NON-UNIQUE] keydef] [INITIAL SIZE n].

Effect

Defines the type itabtype for internal tables without a header line, with the table type tabkind and the line type linetype (if you use a TYPE reference) or the line type of the object lineobj (if you use a LIKE reference). An internal table without header line consists f any number of table lines that all have the same line structure.

You can also define a table key (optional). If you do not, the system defines a generic table type with any key. You can use generic types to specify the type of a generic subroutine parameter.

The UNIQUE and NON-UNIQUE additions allow you to specify whether a table with type itabtype may only contain records with a unique key, or whether it may also contain duplicates. The following rules apply:

The optional INITIAL SIZE addition allows you to set the initial amount of memory allocated to the table. It corresponds to the OCCURS addition in variant 2 (see also performance notes for internal tables). The value n has no effect on the type check.

Example

The following type definitions defined tables with line type STRUC and the key field NAME:

TYPES: BEGIN OF STRUC, 
		 NAME(10) TYPE C, 
		 AGE	TYPE I, 
	 END   OF STRUC. 
 
TYPES: TAB1 TYPE STANDARD TABLE OF STRUC WITH DEFAULT KEY, 
	 TAB2 TYPE SORTED   TABLE OF STRUC 
								WITH NON-UNIQUE KEY NAME, 
	 TAB3 TYPE HASHED   TABLE OF STRUC WITH UNIQUE KEY NAME.

The following table types are generic. This means that you can use them to specify the types of generic subroutine parameters, but not to define a table object using the DATA statment:

TYPES: GEN_TAB1 TYPE STANDARD TABLE OF STRUC, 
	 GEN_TAB2 TYPE SORTED   TABLE OF STRUC WITH KEY NAME, 
	 GEN_TAB3 TYPE HASHED   TABLE OF STRUC.

The following example shows how to define a sorted table using a LIKE reference to the Dictionary structure SFLIGHT:

TYPES: FLTAB LIKE SORTED TABLE OF SFLIGHT 
				WITH NON-UNIQUE KEY CARRID CONNID FLDATE.

Variant 2

TYPES itabtype {TYPE linetype|LIKE lineobj} OCCURS n.

Effect

Defines the type itabtype as a standard table without header line. The der standard key for internal tables is used as a key.

This variant corresponds to a type definition with:

TYPES itabtype {TYPE STANDARD TABLE OF linetype| 
				LIKE STANDARD TABLE OF lineobj} 
			 WITH DEFAULT KEY INITIAL SIZE n.

Note

Type names

A type name may be up to 30 characters long. Apart from the special characters '(', ')', '+', '.', ',', ':', '-', '<', '>', you may use all other characters, including digits. However, a type name may not consist entirely of digits.

Recommendations for type names: