Explain standard, sorted and hashed internal tables. When would you add a secondary key?
Say your answer out loud first.
Practise another way
A standard table is accessed by index, and a lookup by field is a linear search. A sorted table is always ordered by its key and uses binary search for key access.
A hashed table has a unique key and gives constant-time lookups, but no index access. I choose by access pattern: index and append for standard, ordered or partial-key reads for sorted, many exact reads for hashed.
If I need a second fast access path, I add a secondary key.
The table kind decides how the system finds a line.
| Kind | Key | Typical access |
|---|---|---|
| STANDARD | non-unique, not enforced | index, APPEND, loop; key lookup is linear |
| SORTED | unique or non-unique | key lookup uses binary search, leading key fields allowed |
| HASHED | unique only | exact full-key lookup in constant time, no index |
Hashed tables reject index operations such as INSERT ... INDEX or APPEND. A sorted table keeps itself ordered, so inserting is slower than appending to a standard table.
Secondary keys give a table more than one access path. They are sorted or hashed and are always specified by name in the access.
TYPES: BEGIN OF ty_item,
order_id TYPE i, item TYPE i, material TYPE string, qty TYPE i,
END OF ty_item.
DATA items TYPE SORTED TABLE OF ty_item
WITH UNIQUE KEY order_id item
WITH NON-UNIQUE SORTED KEY by_mat COMPONENTS material.
DATA(line) = items[ KEY by_mat material = `PEN` ].
LOOP AT items ASSIGNING FIELD-SYMBOL(<i>) USING KEY by_mat
WHERE material = `PEN`.
ENDLOOP.
If you do not name the key, the primary key is used, so a secondary key is never picked by accident.
Trade-off: every secondary key uses memory and costs work when the table changes. Add one only for a proven repeated lookup on a big table, not as a habit.
Rules of thumb (Clean ABAP also asks for the right table type): a standard table for small tables or when you only loop; sorted when the data must stay ordered or you read by key prefix; hashed for large lookup tables read many times by the full key.
Release note: from release 7.87, an index operation on a hashed key raises the runtime error ITAB_ILLEGAL_INDEX_OP; before that the behaviour was not defined. Alias names for secondary keys were added later too.
Ties each table kind to an access pattern, mentions that hashed has no index access, and says a secondary key costs maintenance.
Recites 'standard is unsorted, sorted is sorted, hashed uses hash' with no access pattern and no cost.
Using a hashed table everywhere because it is 'fastest'. It cannot be read by index and needs a unique full key.
- Can you append to a sorted table?
- What is a secondary key and how do you use it?
- Why does a standard table with BINARY SEARCH need a SORT first?
- Which table type for a lookup table with a million lines read often?
3 official pages and 4 prep guides. Confidence: medium. Checked 21 Nov 2026.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Prep guide Gives the question.