Reputation: 3738
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.
Upvotes: 9
Views: 44739
Reputation: 518
Standard table
This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.
Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.manu
Upvotes: 7
Reputation: 3687
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.
Upvotes: 19