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

WITH UNIQUE KEY when using hash tables

Former Member
0 Likes
4,722

Hi,

Using the hash tables, what does the option WITH UNIQUE KEY do in simpler terms? Would that be similar to the WIH KEY when using the READ TABLE to perform a lookup from one table to another?What is the maximum number of fields can be followed by after the WITH UNIQUE KEY? Can these be exluded from the definition of the has table?

Thanks.

RT

4 REPLIES 4
Read only

Former Member
0 Likes
2,000

Rob,

What it does is makes sure that column that you are declaring as UNIQUE is not duplicated.

Its as good as a primary key in a database table. If its a combination of fields, it makes sure the combination is not duplicated.

I don't think there is a limit as such for declartion of no. of keys.

Yes, you can omit that while declaring.

REgards,

Ravi

Message was edited by: Ravikumar Allampallam

Read only

0 Likes
2,000

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.

1)A primary key is the "key" used to store a record in a database. Depending on how your DB is set-up, it can or can not be unique. It SHOULD BE, but it is not a requirement in all DBs.

A unique key is TRULY a unique (meaning no other records in the table will have the same key field values).

2)unique key allows

insertion of a NULL value

into the key field(s)

Where as primary key does not allow

Read only

Former Member
0 Likes
2,000

Hi

UNIQUE key in hash table would mean, the keys which would fetch you unique records. It will apply the hash algo according to the Keys specified. While using HASH Table, you need to pass all the keys, which you have made unique while processing that internal table....for instance, in SELECT, you need to mention it in where condition.

You can not exclude WITH UNIQUE KEY from the definition.

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.

Regards,

Navneet

Message was edited by: Navneeth Saraogi

Read only

abdul_hakim
Active Contributor
0 Likes
2,000

Hi Rob,

>>Using the hash tables, what does the option WITH UNIQUE KEY do in simpler terms? Would that be similar to the WIH KEY when using the READ TABLE to perform a lookup from one table to another?

Hashed table can contain only unique entries.

The WITH UNIQUE KEY addition ensures that your table cannot contain duplicate entires.I meant it will only contain Unique Records.

Itz not similar to WITH KEY addition in READ statement.

>>What is the maximum number of fields can be followed by after the WITH UNIQUE KEY?

Basically there are no limits..

>>Can these be exluded from the definition of the has table?

No you cannot..

Cheers,

Abdul Hakim

Mark all useful answers..