SAP ITAB KEY OPTIMIZATIONS SAP Info
Article ( Version: 0025)
Optimized Key Operations for Tables of Types SORTED and HASHED TABLE
Accessing single records using
If you use the
key specification in the form
with tables of the type
with tables of the type
If there is a partial key specification that is sufficient for the
above conditions, then the system initially uses this partial key to search for an entry. In the case of
Examples
The following
DATA: wa TYPE sflight,
SrtTab TYPE SORTED TABLE OF sflight
WITH NON-UNIQUE KEY carrid connid,
HshTab TYPE HASHED TABLE OF sflight
WITH NON-UNIQUE KEY carrid connid.
READ TABLE SrtTab INTO wa WITH KEY carrid = 'LH'.
READ TABLE SrtTab INTO wa WITH KEY carrid = 'LH'
connid = '0400'.
READ TABLE SrtTab INTO wa WITH KEY carrid = 'LH'
seatsmax = 100.
READ TABLE SrtTab INTO wa WITH KEY seatsmax = 100
carrid = 'LH'.
READ TABLE HshTab INTO wa WITH KEY carrid = 'LH'
connid = '0400'.
READ TABLE HshTab INTO wa WITH KEY carrid = 'LH'
connid = '0400'
seatsmax = 100.
Example ( Version: 0025)
Conversely, the following
because the specified key does not offer any optimization possibilities. Therefore, these tables result in a Full Table Scan (linear search of all table entries): READ TABLE SrtTab INTO wa WITH KEY connid = '0400'.
READ TABLE SrtTab INTO wa WITH KEY seatsmax = 100.
READ TABLE HshTab INTO wa WITH KEY carrid = 'LH'.
Example ( Version: 0025)
Partially Sequential Quantity Access Using the
The partially sequential access of a table segment of the type
all simple conditions are linked using
no parentheses are used
at least one simple condition is of the form
at least one initial part of the table key is covered by the conditions of the form
Similarly to the
loop is determined by a binary search with the simple conditions, which partly or even completely cover the table key. From the starting point onwards, the loop is processed only so long as these simple conditions are still met.
Examples
The following
LOOP AT SrtTab INTO wa WHERE carrid = 'LH'.
...
ENDLOOP.
LOOP AT SrtTab INTO wa WHERE carrid = 'LH' AND
connid = '0400'.
...
ENDLOOP.
LOOP AT SrtTab INTO wa WHERE carrid = 'LH' AND
seatsmax > 99 AND
seatsmax < 200.
...
ENDLOOP.
Example ( Version: 0025)
while the following
therefore result in a full table fsScan: LOOP AT SrtTab INTO wa WHERE connid = '0400'.
...
ENDLOOP.
LOOP AT SrtTab INTO wa WHERE carrid >= 'LH' AND
connid = '0400'.
...
ENDLOOP.
Notes As is the case with all key operations, it is always sensible for performance reasons to specify the keys in the same order as in the definition of the table key. If this is not the case, the key specifications have to be standardized against the table key, which can cause additional runtime costs (for example in the case of dynamic key specifications).
A key specification may contain neither duplicate nor overlapping partial keys. Otherwise a syntax or runtime error will occur.
Message text extract from SAP system. Copyright SAP SE.
Search for further information about these or an SAP related objects