Difference between Standard table and Hashed table Abap

abap

Can you please give me a clear explanation on the difference between using "standard table of", "Hashed table of", or simply "table of". Also what is the meaning of "initial size 0"?

For reference please have a look in to below code..

it_c01_d006_raw TYPE STANDARD TABLE OF /bic/ac01_d00600
                       INITIAL SIZE 0,
it_c01_d006     TYPE HASHED TABLE OF /bic/ac01_d00600
                       WITH UNIQUE KEY /bic/cemployee /bic/cdatetype,
it_c01_d002     TYPE TABLE OF /bic/ac01_d00200.

Best Solution

The meaning of TYPE STANDARD TABLE OF and TYPE TABLE OF is exactly the same, STANDARD is implied if nothing else is specified. However, in the OO-context you are now expected to declare internal tables fully and you would not be able to leave out the STANDARD addition. In this case it is just a stock-standard internal table that can be accessed by reading per the table index, or by key if you have sorted the table manually.

A table of TYPE HASHED TABLE creates an internal table that is represented using an internal HASH algorithm, allowing reads to the table where the cost is (by approximation) independent from the size of the table. Using this type of table is good when you have large data-sets with a lot of reads, but comparatively few writes. When declaring a hash table you have to also declare a UNIQUE KEY, as the HASH algorithm is dependent on this.

INITIAL SIZE 0 is also a redundant use of code - it means that memory allocation will occur in set blocks. (I'm not sure if this size is predefined, or configurable by BASIS), but INITIAL SIZE 0 is the default. If you wanted memory allocation to happen in sets of 10 times the number of lines in your internal table, you would have used 'INITIAL SIZE 10', but in most cases leaving the default memory allocation is better than trying to force it.

In addition

A table of TYPE SORTED TABLE can be declared with either an UNIQUE or a NON-UNIQUE key. The cost to read a record is less than that of a STANDARD table, as it allows a BINARY SEARCH, but more than that of a HASHED table. The cost to write is slightly more expensive than a STANDARD table, but less than that of a HASHED table.

Related Question