Entering content frame

Operations on Individual Lines Locate the document in its SAP Library structure

Influence of the Table Type

When working with single table lines, we must distinguish between the operators that are possible for all table types, and those that are only possible with index tables. Index tables (standard and sorted tables) have an internal index, making index access possible. Hashed tables have no linear index. Consequently, only key access is possible. The operations that are permitted for all table types do not use indexes. They can also be used in procedures or with field symbols, where the internal table type is not defined with a certain type. These operations are known as generic operations.

The statements used to access lines of any type of table differ from those used to access index tables (with few exceptions) mainly through the TABLE addition following the corresponding keyword. For example, you would use MODIFY TABLE to change lines in any table, but MODIFY to change lines in index tables only.

Index Access and Key Access

Key access addresses lines through the table key and is possible for all table types. Index access addresses lines through the internal index and is therefore only possible for standard tables and sorted tables. After accessing an index table, the system field sy-tabix is always filled with the index of the addressed line. As with all successful accesses to lines of internal tables, the system field sy-subrc is filled with the value zero; otherwise, it is filled with a value not equal to zero. The following table provides a summary of the access options for individual tables types::



Standard Table

Sorted Table

Hash Table

Index Access




Key Access




Key Values

Not unique

Unique or
not unique


Preferred Access





In the last line of the table, a preferred access type for the different table types is specified. This recommendation results from the fact that working with internal table mostly means working with large data quantities. One of the standard applications of internal tables is to load large data quantities from the database into the main memory in order to process the data there more quickly and more efficiently. In such cases, it is imperative that you view the time required for each individual access type.

The index access is usually the quickest access type for an internal table line since there is a direct internal reference. However, it is often not the most suitable access type for working with data from database tables.  In the case of index access, the program must know the assignment between the index and the content of the table line while, with key access, the content of the table line itself is evaluated. Key access is therefore more suitable for many applications, but it is also slower.

Access Type

The time required for key access strongly depends on the table type.

With standard tables, all the lines are searched – at each key access – in a linear fashion for the key value. The average search effort is therefore directly proportional to the number of lines.

In the case of sorted tables, the runtime environment automatically executes – for a key access – a binary search (interval search) for the key value. The average search effort is proportional to log2 of the number of lines.

In the case of hashed tables, the runtime environment calculates the position of the line using a hash function from the key value. The search effort is independent of the number of lines.

Runtime Measurement

The following figure shows a typical measurement for the average runtime for key accesses to different table types, depending on the number of lines. The times were measured for each of the three table types on the basis of a key access to all the lines. The average value was determined. From approximately 50 lines onwards, the curves go upwards as predicted. Note the logarithmic measure for the display. At 10,000 lines, access to a hashed table is twice as fast as access to a sorted table, and the latter is 170 times faster than access to a standard table.

This graphic is explained in the accompanying text

Depending on the use of an internal table in the program (number of lines, access frequency), you should by all means use the suitable table types. In the case of small tables up to approximately 100 lines or tables where there are no or only few key accesses, standard tables can be used. Large tables that do not have duplicate entries and are not accessed through the key should always be created as hashed tables. Sorted tables are always appropriate if a table must be available in sorted form during the entire runtime.

Operations for all Table Types

You should use these operations only if they are the only possibility for the table type, or when the table type is not known when you write the program (for example, generic formal parameters in procedures).

If you know the table type, you should, for performance reasons, use the corresponding specific operation. For example, you should use the APPEND … TO statement to fill index tables, but INSERT … INTO TABLE to fill hashed or generic tables.

Operations for Index Tables

Some operations are only permitted for index tables (sorted and standard tables). Some of them are restricted to standard tables. Since it is quicker to access a table by index than by key, you should always use specific index operations when you know that a particular internal table is an index table.

In particular, the quickest way to fill a table line by line is to append lines to a standard table, since a standard table cannot have a unique key and therefore appends the lines without having to check the existing lines in the table. If you can either accommodate duplicate entries in a table or exclude them in a different way, it can be quicker to fill a standard table first and then sort it or assign it to a sorted table – provided the data does not have to be inserted into the table in the correct sort sequence.

Furthermore, the performance of operations that change the internal linear index has been improved in Release 4.5A. Previously, index manipulation costs for inserting and deleting liens in standard tables and sorted tables increased in linear relation to the number of lines. From Release 4.5A, the index manipulation costs only increase logarithmically with the number of lines, since the table indexes are now maintained as a tree structure. This makes insertion and deletion operations efficient, even in very large standard and sorted tables.


For more information, refer to the following chapters:

Access Methods for Individual Table Entries

Filling Internal Tables Line by Line

Reading Table Lines

Processing Table Lines in Loops

Changing Table Lines

Deleting Table Lines

Searching Through Internal Tables Line by Line

Obsolete Statements for Internal Tables


Leaving content frame