Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

internal tables

Former Member
0 Kudos
80

what is the difference between hashed & sorted internal

tables?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
55

Hi,

Hashed table is useful when your have to work with very big internal table and to read it with

"READ TABLE WITH KEY ..."

The time access is constant !

Sorted tables store records in a "sorted" fashion at all times. It is faster to search through a sorted table vs a standard table. But performance is dictated by the amount of records in the internal table.

A hashed table's performance in reads is NOT dependent on the number of records. However, it is intended for reads that will return only and only one record. It uses a "side-table" with a hash algorithm to store off the physical location of the record in the actual internal table. It is not NECESSARILY sorted/organized in an meaningful order (like a sorted table is). Please note that changes to a hashed tables records must be managed carefully. Review SAP's on-help in SE38/80 about managing hashed tables.

Definition of a Hashed Table:

"Defines the table as one that is managed with an internal hash procedure. You can imagine a hashed table as a set, whose elements you can address using their unique key. Unlike standard and sorted tables, you cannot access hash tables using an index. All entries in the table must have a unique key.

Access time using the key is constant, regardless of the number of table entries.

You can only access a hashed table using the generic key operations or other generic operations (SORT, LOOP, and so on). Explicit or implicit index operations (such as LOOP ... FROM to INSERT itab within a LOOP) are not allowed."

As long as your records has unique key(s), using hash table will give you a huge performance gain when dealing with large dataset. assuming in your case, 10000 record , and if the key is unique, use hash table. The main use of hash tables is for looking up fixed information from a key. So if you have a report that has personnel number and you want to display their name, you could use a hash table.

Thus:

Code:

types: begin of typ_pernr,

pernr like pa0001-pernr,

ename like pa0001-ename,

end of typ_pernr.

data: ls_pernr type typ_pernr,

lt_pernr type hashed table of typ_pernr with unique key pernr.

...

select pernr ename into table lt_pernr from pa0001.

...

loop at itab.

read table lt_pernr with table key pernr = itab-pernr

into ls_pernr.

write: ls_pernr-ename, itab-data.

endloop.

Regards

3 REPLIES 3

Former Member
0 Kudos
56

Hi,

Hashed table is useful when your have to work with very big internal table and to read it with

"READ TABLE WITH KEY ..."

The time access is constant !

Sorted tables store records in a "sorted" fashion at all times. It is faster to search through a sorted table vs a standard table. But performance is dictated by the amount of records in the internal table.

A hashed table's performance in reads is NOT dependent on the number of records. However, it is intended for reads that will return only and only one record. It uses a "side-table" with a hash algorithm to store off the physical location of the record in the actual internal table. It is not NECESSARILY sorted/organized in an meaningful order (like a sorted table is). Please note that changes to a hashed tables records must be managed carefully. Review SAP's on-help in SE38/80 about managing hashed tables.

Definition of a Hashed Table:

"Defines the table as one that is managed with an internal hash procedure. You can imagine a hashed table as a set, whose elements you can address using their unique key. Unlike standard and sorted tables, you cannot access hash tables using an index. All entries in the table must have a unique key.

Access time using the key is constant, regardless of the number of table entries.

You can only access a hashed table using the generic key operations or other generic operations (SORT, LOOP, and so on). Explicit or implicit index operations (such as LOOP ... FROM to INSERT itab within a LOOP) are not allowed."

As long as your records has unique key(s), using hash table will give you a huge performance gain when dealing with large dataset. assuming in your case, 10000 record , and if the key is unique, use hash table. The main use of hash tables is for looking up fixed information from a key. So if you have a report that has personnel number and you want to display their name, you could use a hash table.

Thus:

Code:

types: begin of typ_pernr,

pernr like pa0001-pernr,

ename like pa0001-ename,

end of typ_pernr.

data: ls_pernr type typ_pernr,

lt_pernr type hashed table of typ_pernr with unique key pernr.

...

select pernr ename into table lt_pernr from pa0001.

...

loop at itab.

read table lt_pernr with table key pernr = itab-pernr

into ls_pernr.

write: ls_pernr-ename, itab-data.

endloop.

Regards

Former Member
0 Kudos
55

hi

good

Sorted internal table works on Binary Search and Hashed internal tables works on hashed alogorthim through indexes

thanks

mrutyun^

Former Member
0 Kudos
55

hi

thanks to all for responding to my query

regards

suri