Definition of an internal table

DATA - Defining an Internal Table

Variants:
1. DATA itab TYPE itabtype [WITH HEADER LINE].

2. DATA itab {TYPE tabkind OF linetype|LIKE tabkind OF lineobj}
WITH [UNIQUE|NON-UNIQUE] keydef
[INITIAL SIZE n] [WITH HEADER LINE].

3. DATA itab {TYPE TABLE OF linetype|LIKE TABLE OF lineobj}.

4. DATA itab [TYPE linetype|LIKE lineobj] OCCURS n
[WITH HEADER LINE].

5. DATA: BEGIN OF itab OCCURS n,
...
END OF itab [VALID BETWEEN f1 AND f2].


You fill and edit internal tables using the following statements: INSERT, APPEND, READ TABLE, LOOP, SORT.

The OCCURS and INITIAL SIZE additions (hereafter called the OCCURS value), determine the initial number of table lines created. The table is enlarged by the system when necessary. For more details about this, see performance notes for internal tables. The OCCURS occurs value has no semantic meaning apart from an exception with APPEND SORTED BY . If you do not specif the INITIAL SIZE, the system sets the OCCURS value to 0 by default.

If you specify WITH HEADER LINE , the table is created with a header line - a field with the same name as the table. Its type is the same as the line type of the internal table.

Effect

itabtype must be an internal table type, defined using TYPES. The system creates an internal table with the specified type.

Example

Creating a hashed table by referring to an existing table type.

TYPES: BEGIN OF STRUC, NAME(10), AGE TYPE I, END OF STRUC, 
	 HTAB TYPE HASHED TABLE OF STRUC WITH UNIQUE KEY NAME. 
DATA : PERSONS TYPE HTAB.

Variant 2

DATA itab {TYPE tabkind OF linetype|LIKE tabkind OF lineobj}
WITH [UNIQUE|NON-UNIQUE] keydef
[INITIAL SIZE n] [WITH HEADER LINE].

Effect

The system creates an internal table with table type tabkind . Since there is no generic field definition, you cannot use the table types ANY TABLE or SORTED TABLE.

The construction of the table lines is defined by linetype (if you are using a TYPE reference) or by the type of the referred object lineobj (if you are using a LIKE reference).

The same rules apply to UNIQUE and NON-UNIQUE as apply to the TYPES definition. You may only omit this specification with standard tables.

If you do not specify an INITIAL SIZE , the system assumes a default value of INITIAL SIZE 0.

Variant 3

DATA itab {TYPE TABLE OF linetype|LIKE TABLE OF lineobj}.

Effect

This variant is a shortened form of the internal table definition. It corresponds to

DATA itab {TYPE STANDARD TABLE OF linetype|
LIKE STANDARD TABLE OF lineobj} WITH DEFAULT KEY.

or th eold definition (see variant 4) with

DATA itab {TYPE linetype|LIKE lineobj} OCCURS 0.

Variant 4

DATA itab [TYPE linetype|LIKE lineobj] OCCURS n
[WITH HEADER LINE].

Effect

This variant exists for the sake of compatibility with Release 3.x. If you do not specify a line type, the system uses a default of type C with length 1. This variant is synonymous with

DATA itab {TYPE STANDARD TABLE OF linetype|
LIKE STANDARD TABLE OF lineobj}
INITIAL SIZE n [WITH HEADER LINE].

Example

TYPES: BEGIN OF LINE_TYPE, 
		 NAME(20) TYPE C, 
		 AGE	TYPE I, 
	 END   OF LINE_TYPE. 
DATA:  PERSONS	TYPE LINE_TYPE OCCURS 20, 
	 PERSONS_WA TYPE LINE_TYPE. 
 
PERSONS_WA-NAME = 'Michael'.  PERSONS_WA-AGE  = 25. 
APPEND PERSONS_WA TO PERSONS. 
PERSONS_WA-NAME = 'Gabriela'. PERSONS_WA-AGE  = 22. 
APPEND PERSONS_WA TO PERSONS.

The internal table PERSONS now contains two entries:

Variant 5

DATA: BEGIN OF itab OCCURS n,
...
END OF itab [VALID BETWEEN f1 AND f2].

Effect

Defines an internal table itab with table type STANDARD and a header line. The line type consists of the fields between " BEGIN OF itab OCCURS n" and "END OF itab".

You can use the addition VALID BETWEEN f1 AND f2 to specify that subfields f1 and f2 of the internal table itab contain the validity range. This addition is only relevant in conjunction with the PROVIDE statement.

Example

DATA: BEGIN OF PERSONS OCCURS 20, 
		NAME(20), 
		AGE TYPE I, 
	END   OF PERSONS. 
PERSONS-NAME = 'Michael'. 
PERSONS-AGE  = 25. 
APPEND PERSONS. 
PERSONS-NAME = 'Gabriela'. 
PERSONS-AGE  = 22. 
APPEND PERSONS.

The internal table now has two entries. It also has a header line (work area), which you use to work with the table itself.