Assume a big query on MARA table with non-primary key value which returns a large volume of data in an internal table.
If the design permits that the read can be done with a unique key, then the best approach is to define the internal table as a Hash Table which uses Hash algorithm to fetch values. In this case, the search time is independent of the position of entry. Unique key use with Hash algorithm ensures that each fetch takes the same amount of time and usually in terms of performance, the search is quicker.
When is Hash Table used? One requirement is data can be defined by a unique key. It is usually used when the size of the internal table is too large.
DATA : lt_mara TYPE HASH TABLE OF mara WITH UNIQUE KEY matnr .
The ‘read’, in this case, is needed on the key ‘matnr’.
READ TABLE lt_mara INTO lw_mara WITH TABLE KEY mara = <material_number> .
- Time needed to access a record in a hash table doesn’t change with increase or decrease of records.
- Using Hash Table give significant performance advantage for a large dataset when compared to Standard or Sorted tables.
- Internally, the data fetch is done by using a hash function.