ABAP Internal Table:Define、Read、Append、Modify、Delete

  Define Data

It is necessary to understand the internal table in order to make and debug the ABAP program. Here’s what the internal table is all about.

What is an internal table?

Briefly, it is a database table that can be shared by multiple programs, saved and reused later, and an internal table that can be used by itself (while the program is running). There are few things that can be done with the internal table alone, and it will often be processed using the work area.

What is a work area?

The internal table is a definition for storing a plurality of data, and the work area is a definition for storing only one row of data. It is often used to read an internal table, store it in the work area, edit it in the work area, and reflect the result in the internal table.

Definition of internal table/work area

First, let’s introduce how to define internal tables and work areas.
The basic method is to use the TYPES command defined in the program as an internal table or work area, or to refer to a database table or structure.
As options for these definitions, there are various definition methods such as making the internal table a standard table, a sort table, a hash table, an internal table with a header, and defining a work area as a field symbol.

Internal table and work area using TYPES statement

Internal table/work area that refers to the database table

Standard table, sorted table, hash table

The usage and differences of these will be discussed separately, and this time I will introduce how to use the internal table.

How to use the internal table


Use “LOOP … END LOOP” or “READ TABLE” depending on whether “read” reads multiple rows from the internal table or only one row.

LOOP … ENDLOOP is often used when you want to read the entire internal table, or when you want to read under conditions that are not the primary key. If a primary key is specified as a condition, the same result as READ TABLE can be obtained, but there is no particular advantage. Personally, when you look at the program later, it is recommended that you use it so that you can instantly determine whether you want to acquire multiple lines or the logic you want to acquire only one line. On the other hand, READ TABLE is a command that can not acquire multiple rows but only one row. It is possible to use an optional TRANSPORT NO FIELD instead of INTO WA (work area) and perform only data check when SY-SUBRC is 0 (data existed) or other than 0 (data does not exist or error). it can.


The “update” instruction differs depending on whether a row is added or the value of an existing row is changed. Use APPEND and INSERT commands to add rows. If you want to use a sorted table for aggregation, use the COLLECT command.

It is also possible to add multiple lines at once using “INSERT LINES OF itab1 [FROM n1] [TO n2] INTO TABLE itab2”.
Use the MODIFY instruction to change the value of a row。

In the above, I am updating explicitly, but I personally think that it is simpler to use a field symbol if you just want to update.


If you want to delete unnecessary lines, specify a condition and use the DELETE command.

If you want to delete duplicate rows, use the DELETE statement with the ADJACENT DUPLICATES option. When deleting, it is judged whether the specified items before and after are the same, so please be sure to sort (SORT) immediately before the command.