READ on a unique sorted table
* Entries: 1000
* Line width: 100, key width: 20
* STAB is a unique sorted table, 250 entries are read
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE STAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
" ...
ENDIF.
ENDDO.
READ on a unique hashed table
* Entries: 1000
* Line width: 100, key width: 20
* HTAB is a hased table, 250 entries are read
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
" ...
ENDIF.
ENDDO.
Documentation
Entries in a sorted table are located by binary search.
The costs depend on the number of entries in the table (O (log n)).
Entries in a hashed table are located by an internal hash-algorithm
The costs are constant (O (1)), i.e. they do not depend on the table
size.
Hashed tables are optimized for single entry access, whereas sorted
tables are optimized for partial sequential loop operations (see the
separate example).