Application Development and Automation 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: 
Read only

How Hash Algorithm Works

Former Member
0 Likes
6,412

How Hash Algorithm and Logarithmic Algorithm works to fetch the data ?

What the basic things we have to keep in mined when we select the Internal table ?

Any rule for selecting the internal table which should be followed ?

1 ACCEPTED SOLUTION
Read only

Peter_Inotai
Active Contributor
0 Likes
2,425

> How Hash Algorithm and Logarithmic Algorithm works

> to fetch the data ?

Fetching part is the same as standard internal table, only when you work with the internal table, than it's different.

> What the basic things we have to keep in mined when

> we select the Internal table ?

Eg Performance.

> Any rule for selecting the internal table which

> should be followed ?

Standard table is quite easy to use, but you might loose performance with it. Most of the time hash table is the fastest.

Using standard table and sort it is a good choice, when you access in READ TABLE via BINARY SEARCH.

Check 'ABAP for Power Users' SAP tutorial in SDN, it very good explains this topic in detail.

Peter

9 REPLIES 9
Read only

athavanraja
Active Contributor
0 Likes
2,425

if you want a internal table which allows faster reading then you should go for hashed table , but the disadvantage is that you cannot use index to read the hashed itab.

you have to use keys.

sample declratin of hashed table.

data:cc_text TYPE HASHED TABLE OF /bi0/tcostcenter WITH UNIQUE KEY co_area costcenter langu .

to read entries from the hashed table.

READ TABLE cc_text INTO wa_cc_text WITH KEY

co_area = coarea

costcenter = cctr

langu = sy-langu .

Hash table access time dosent increase based on the number of records, its constant.

check out the ABAP key work documentation for different types of internal table and their usages. its well explained there.

Regards

Raja

Read only

0 Likes
2,425

One piece I have experienced myself and somone didn't bring up is:

If you use only partial key to search in a hash table, this would take as long as standard table (based on my experience). You must specify all key fields in your <b>READ</b> statement get the benefit of hash table. In case you only had first few fields of a key that you want to search by, you should use SORTED table instead of a HASH table.

Example:

data:cc_text TYPE HASHED TABLE OF /bi0/tcostcenter WITH UNIQUE KEY co_area costcenter langu.

If you performed your <b>READ</b> the following way, the performance would be constant.

READ TABLE cc_text INTO wa_cc_text WITH KEY
co_area = coarea
costcenter = cctr
langu = sy-langu .

If you performed your <b>READ</b> the following way, the performance would be much slower.

READ TABLE cc_text INTO wa_cc_text <b>WITH KEY
co_area = coarea.</b>

Read only

Former Member
0 Likes
2,425

Hi Garg,

Raja has described it very well.

Her 2 additional infos.

1.) Your internal table should provide a unique key!

(onw field or more of them doen't matter)

2.) Use it, if your internal table becomes big!

(Lets say > 1000 lines)

BR

Michael

Read only

Peter_Inotai
Active Contributor
0 Likes
2,426

> How Hash Algorithm and Logarithmic Algorithm works

> to fetch the data ?

Fetching part is the same as standard internal table, only when you work with the internal table, than it's different.

> What the basic things we have to keep in mined when

> we select the Internal table ?

Eg Performance.

> Any rule for selecting the internal table which

> should be followed ?

Standard table is quite easy to use, but you might loose performance with it. Most of the time hash table is the fastest.

Using standard table and sort it is a good choice, when you access in READ TABLE via BINARY SEARCH.

Check 'ABAP for Power Users' SAP tutorial in SDN, it very good explains this topic in detail.

Peter

Read only

0 Likes
2,425

Sir.. what is Eg Performance ?

It is said that Hash table use Hash Algo... What that Hash Algo is ??

Message was edited by: Saurabh Garg

Read only

0 Likes
2,425

Hi Saurabh,

Hashing is a technique in Computer Science that's primarily used for storing voluminous structured information - in this context an internal table.

The hash table supports a READ operation the best. The hash function (implemented internally in this case) takes as input the Key for the internal table and obtains an integer. This integer is then used as an index to access the internal table directly.

In case of a hashed internal table, the data is not stored at the same physical location. It is stored in chunks at different physical memory locations. For this reason, the SORT operation on a hashed table is very very expensive and should be avoided at all costs.

Hashing is a really big topic in Computer Science and cannot possibly discussed in a single Forum Post. But I hope you got a rough idea of what it does. Get back if you have further doubts.

Regards,

Anand Mandalika.

Read only

0 Likes
2,425

Hi,

You might also find the following post to be relvant -

Regards,

Anand Mandalika.

Read only

Former Member
0 Likes
2,425

Hi Saurabh,

You might want to also check out this link where the current issue has been discussed.

http://www.sap.info/public/en/category.php4/Category-28943c61b1e60d84b/page/0/article/Article-119884...

Regards,

Anand Mandalika.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
2,425

Hi,

Just read the following.

HASHED table:

Defines the table as one that is managed with an internal hash procedure

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 oe INSERT itab within a LOOP) are not allowed.

Reading internal tables:

READ TABLE itab WITH TABLE KEY k1 = v1 k2 = v2 [additions]

Note: In case of more than one match, it is the first match that is selected.

STANDARD TABLE: The system searches from the start of the table. The response time is in linear relation to the number of table entries.

SORTED TABLE: The response time is in logarithmic relation to the number of table entries.

HASHED TABLE: The response time is constant

READ TABLE itab WITH KEY k1 = v1 k2 = v2 [BINARY SEARCH] [additions]

Note: In case of more than one match, it is the first match that is selected.

STANDARD TABLE: If you use the ... BINARY SEARCH addition, the system uses a binary search. Otherwise, the search is sequential. This assumes that the internal table is sorted in ascending order in the sequence of the specified key fields.

SORTED TABLE: If the specified key fields form a left-justified extract of the table key, the search is binary, otherwise sequential.

HASHED TABLE: Sequential search.

Hope this helps.

Regards,

J.Jayanthi