Show TOC

Using Header Lines as Work AreasLocate this document in the navigation structure

It is not allowed to work with header lines in internal tables in classes. This statement is obsolete and is only available to ensure compatibility with Releases prior to 4.6 and 6.10. The addition may appear in the statements listed below in older programs but should no longer be used.

When you create an internal table you can also declare a header line with the same name. You can use the header line as a work area when you process the internal table. The ABAP statements that you use with internal tables have short forms that you can use if your internal table has a header line. These statements automatically assume the header line as an implicit work area. The following table shows the statements that you must use for internal tables without a header line, and the equivalent statements that you can use for internal tables with a header line:

Operations without header line

Operations with header line

Operations for all Table Types

INSERT wa INTO TABLE itab.

INSERT TABLE ITAB.

COLLECT wa INTO itab.

COLLECT itab.

READ TABLE itab... INTO wa.

READ TABLE itab...

MODIFY TABLE itab FROM wa...

MODIFY TABLE itab...

MODIFY itab FROM wa...WHERE...

MODIFY itab... WHERE...

DELETE TABLE itab FROM wa.

DELETE TABLE itab.

LOOP AT ITAB INTO wa...

LOOP AT ITAB...

Operations for Index Tables

APPEND wa TO itab.

APPEND itab.

INSERT wa INTO itab...

INSERT itab...

MODIFY itab FROM wa...

MODIFY itab...

Using the header line as a work area means that you can use shorter statements; however, they are not necessarily easier to understand, since you cannot immediately recognize the origin and target of the assignment. Furthermore, the fact that the table and its header line have the same name can cause confusion in operations with entire internal tables . To avoid confusion, you should use internal tables with differently-named work areas.

Tip

The following example shows two programs with the same function. One uses a header line, the other does not.

With header line:

TYPES: BEGIN OF line,         col1 TYPE i,         col2 TYPE i,       END OF line.

DATA itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1               WITH HEADER LINE.

DO 4 TIMES.  itab-col1 = sy-index.  itab-col2 = sy-index ** 2.  INSERT TABLE itab.ENDDO.

itab-col1 = 2.READ TABLE itab FROM itab.

itab-col2 = 100.MODIFY TABLE itab.

itab-col1 = 4.DELETE TABLE itab.

LOOP AT itab.  WRITE: / itab-col1, itab-col2.ENDLOOP.

Bearbeitung ohne Kopfzeile:

TYPES: BEGIN OF line,         col1 TYPE i,         col2 TYPE i,       END OF line.

DATA: itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1,      wa LIKE LINE OF itab.

DO 4 TIMES.  wa-col1 = sy-index.  wa-col2 = sy-index ** 2.  INSERT wa INTO TABLE itab.ENDDO.

wa-col1 = 2.READ TABLE itab FROM wa INTO wa.

wa-col2 = 100.MODIFY TABLE itab FROM wa.

wa-col1 = 4.DELETE TABLE itab FROM wa.

LOOP AT itab INTO wa.  WRITE: / wa-col1, wa-col2.ENDLOOP.

In both cases, the list appears as follows:

1         1

2       100

3         9

The statements in the program that does not use a header line are easier to understand. As a further measure, you could have a further work area just to specify the key of the internal table, but to which no other values from the table are assigned.