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 to define a hashed table?

Former Member
10,669

Hi..

I want to know that how we can define a hash table in ABAB.

And what are the advantages of that table?

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,125

Hi Subhash,

Syntax for creation of Hashed Table is

DATA: <tab_name> type hashed table of <line_type> [with <key>] [initial size <n>].

An eg: as given in SAP help

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.

Hashed Tables

Here the access is through keys and not using index.The response time for key access remains constant, regardless of the number of table entries.

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 ur query is answered.

Regards,

Sylendra.

6 REPLIES 6
Read only

Former Member
0 Likes
5,125

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.

pls reward the points.

Thanks

eswar

Read only

Former Member
0 Likes
5,126

Hi Subhash,

Syntax for creation of Hashed Table is

DATA: <tab_name> type hashed table of <line_type> [with <key>] [initial size <n>].

An eg: as given in SAP help

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.

Hashed Tables

Here the access is through keys and not using index.The response time for key access remains constant, regardless of the number of table entries.

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 ur query is answered.

Regards,

Sylendra.

Read only

0 Likes
5,125

once you have data in your internal table, there is not much of a performance issue...unless of course it contains a huge number of entries...

i m not aware of such a possibility that an internal table can behave as both sorted and hashed...

if you go for a hashed table, the response time for your search will always be constant, regardless of the number of table entries....this is because the search uses a hash algorithm...u must specify the UNIQUE key for hashed tables.

just go thru this link for some more information...

http://www.sap-img.com/abap/what-are-different-types-of-internal-tables-and-their-usage.htm

read this...

Standard tables are managed system-internally by a logical index. New rows are either attached to the table or added at certain positions. The table key or the index identify individual rows.

Sorted tables are managed by a logical index (like standard tables). The entries are listed in ascending order according to table key.

Hashed tables are managed by a hash algorithm. There is no logical index. The entries are not ordered in the memory. The position of a row is calculated by specifying a key using a hash function.

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.

TYPES: BEGIN OF TY_ITAB,

FIELD1 TYPE I,

FIELD2 TYPE I,

END OF TY_ITAB.

TYPES ITAB TYPE SORTED TABLE OF TY_ITAB WITH UNIQUE KEY FIELD1.....

FOR PROPER SYNTEX F1 HELP....

Read only

0 Likes
5,125

Hi Subash,

example is

TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE LINE.

Sorry that I have given the example of SORTED TABLE.

Regards,

Sylendra.

Read only

Former Member
0 Likes
5,125

Hi,

Processing of a Hash table is independent of the number of records in the table. It is because of the unique Hash algorithm that is associated with Hash type of internal tables.

So if you want to process a huge data, Hash tables can come handy.

for more details and how to create visit following link

http://help.sap.com/saphelp_470/helpdata/en/fc/eb3660358411d1829f0000e829fbfe/frameset.htm

Regards,

Shashank

Read only

Former Member
0 Likes
5,125

Hi,

i hope the following link is helpful

<a href="http://help.sap.com/saphelp_erp2004/helpdata/en/fc/eb362c358411d1829f0000e829fbfe/frameset.htm">operations for all types of tables</a>

thanks and regards,

kinshuk saxena