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

What is HASH Table?

Former Member
0 Likes
4,994

Hi all,

Can anyone explain me what is HASH table?

Thanks in Advance.......

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,593

Hi,

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.

Hope it is useful.

Thanks,

Sandeep.

Hi all,

Can anyone explain me what is HASH table?

Thanks in Advance.......

9 REPLIES 9
Read only

Former Member
0 Likes
2,593

A hased table is the kind of an internal table which is closest to a database table.

The fundamental difference is that the entries in a hashed table cannot be accessed through an index.

For example, the following statement is not applicable to a hashed table -

READ TABLE ITAB INDEX <n>.

If you notice, even in case of a database table, let us say, SPFLI, we cannot say, "get me the 10th record of the table SPFLI". The entries can only be retrieved by specifying a "key". So you would have something like -

READ TABLE ITAB WITH KEY....

This is similar to a SELECT statement that we use for a database table. We specify the key fields in the WHERE condition.

Obviously, a hashed table has to have a KEY, and cannot have duplicate entries for the key fields. Which is again just like in case of a database table.

And finally, even though it is only used rarely, in some cases using a hashed table can improve the performance significantly - the reason being that the time required to fetch any record from a hashed internal table is constant.

Read only

Former Member
0 Likes
2,594

Hi,

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.

Hope it is useful.

Thanks,

Sandeep.

Read only

0 Likes
2,593

thanks for ur help....

But can you tell me when to use this HASH Table?

Thanks in advance...........

Read only

0 Likes
2,593

Hi,

Hashed tables are better as comapred to other 2 type of tables . they basically work on the principal of Hash Key .

The prerequsit for an hashed table is that we need to specify the Key for that table , which is unique for each record in the table.

Now based on this key the system based on a hashing algorithm automatically generates a hask key which is used to access the records in the table.

It would be helpful , but as i said about the prerequsit , go for it if in your internal table there are fields which can ast as key , so as to uniquely identify each record.

Regard

Regards

Read only

0 Likes
2,593

As a thumb rule , you have to use it if the data is Very huge.

Regards,

ravi

Read only

Former Member
0 Likes
2,593

Hi,

http://sapmaterial.com/internaltable_types.html

Reward points if helpful

Srikanta Gope

Read only

Former Member
0 Likes
2,593

Hi,

Just go thro' this.

1. Types of internal tables

1.1 STANDARD table

Key access to a standard table uses a linear search. This means that the time required for a search is in linear relation to the number of table entries.

You should use index operations to access standard tables.

1.2 SORTED table

Defines the table as one that is always saved correctly sorted.

Key access to a sorted table uses a binary key. If the key is not unique, the system takes the entry with the lowest index. The runtime required for key access is logarithmically related to the number of table entries.

1.3 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.

1.4 INDEX table

A table that can be accessed using an index.

Index table is only used to specify the type of generic parameters in a FORM or FUNCTION. That means that you can't create a table of type INDEX.

Standard tables and sorted tables are index tables.

1.5 ANY table

Any table is only used to specify the type of generic parameters in a FORM or FUNCTION. That means that you can't create a table of type ANY.

Standard, sorted and hashed tables belongs to ANY tables

<b>reward points</b>

Regards

Read only

Former Member
0 Likes
2,593

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 !

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.

also refer

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm

regards,

srinivas

<b>*reward for useful answers*</b>

Read only

Former Member
0 Likes
2,593

An internal table of type HASHED can be used to improve performance. Hashed tables have no linear index. You can only access hashed tables by specifying

the key. The system has its own hash algorithm for managing the table.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.A restriction for hashed tables is that they may not contain more than 2 million entries.

You can also chk the links

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2fcc358411d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_47x200/helpdata/en/90/8d7328b1af11d194f600a0c929b3c3/frameset.htm

If you have an internal table in your program which is used solely for lookup, it is good programming practice to use a hash table. The example below shows this, in combination with a method for buffering SELECT SINGLE results.

Code

&----


*& Form select_dispo

&----


  • Get MRP controller and in-house production time from material

  • and plant

----


  • --> MATNR Material

  • --> RESWK Plant

  • <-- DISPO MRP controller

  • <-- DZEIT In-house production time

----


form select_from_marc using matnr werks dispo dzeit.

types: begin of mrp_lookup_type,

matnr like marc-matnr,

werks like marc-werks,

dispo like marc-dispo,

dzeit like marc-dzeit,

end of mrp_lookup_type.

  • Define static hashed table to hold results

statics: st_mrp type hashed table of mrp_lookup_type

with unique key matnr werks.

data: l_wa_mrp type mrp_lookup_type.

clear dzeit.

  • See if data is in the table

read table st_mrp into l_wa_mrp with table key matnr = matnr

werks = werks.

  • If not in table, get it from the database

if not sy-subrc is initial.

select single dispo dzeit from marc

into corresponding fields of l_wa_mrp-dispo

where matnr eq matnr

and werks eq werks.

  • Insert into table

l_wa_mrp-matnr = matnr.

l_wa_mrp-werks = werks.

insert l_wa_mrp into table st_mrp.

endif.

dispo = l_wa_mrp-dispo. " MRP Controller

dzeit = l_wa_mrp-dzeit. " Inhouse production time

endform. " select_from_marc

reward points if helpful