Difference Between Internal Table and Work Area

What is the difference between internal table and a work area and how do they work?

Internal table is a temporary two dimensional memory structure similar to database table.  We can store multiple records in the internal table and also using record pointers we can do the activities such as reading, appending, deleting, modifying etc.

Whereas work area is a variable declared with the TYPE of an internal table or a database table.  It can store only one record at a time.  It is like a structure declaration in C.  You can refer individual columns in the work area with the names.

If you declare an internal table with "WITH HEADER LINE" clause the internal table itself acts as a work area.  For example, your ITAB is a work area and ITAB[] is the internal table.

If you are familiar with ORACLE PLSQL, work area is similar to %ROW_TYPE and internal is similar to TABLE TYPE.

More info on using Internal table with and without header line:

When you create an internal table object 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.

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.

Without 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, 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.

The list, in both cases, 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.

Read Also
An Example of a ListBox Program

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.