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: 

non-unique key

Former Member

Hello Gurus,

what does non-unique key do ? I think unique key can be used for selecting a unique row from a internal table object, and also used for sorting . but why is non-unique key there if I can only select row by index ( which is stadard table)?

thanks very much!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi bo zhang

As you know unique keys are used as primary indexes in the where clause of a select statement.

To have secondary indexes in the where clause, we've to make use of non-unique keys.

But in performance view, we should not use, since as it is a non-unique, we come across many duplicates, so generally we use it as the situation demands.

At max., we can make 16 secondary indexes.

Here i like to differentiate b/w index and keys to clear the confusion. At the creation of database table through se11, we've to position the unique key fields at top of the table fields to clarify the entries to be identified.

About Indexes, after activating the table in se11, the system implicitly creates indexes for the table based on primary keys and secondary indexes based on non-unique keys.

For further doubts feel free to contact me.

If it helpful to you, reward me plz.

Thanks

Suren

6 REPLIES 6

Former Member
0 Kudos

hi

well for unique key there is only one record in the table

where as for non unique key its is very much possible that thre is more than one record of that given key

plz reward points

thank u

snehi chouhan

0 Kudos

Hi Friend,

that is why I ask here. I want to know why we have to define non-unique key in the internal table type. for selecting or sorting ? is it necessary or optional?

thanks very much!

Former Member
0 Kudos

Hello,

To learn more about standard tables and non-unique keys, I suggest you to read the following [Special Features of Standard Tables|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3646358411d1829f0000e829fbfe/frameset.htm].

Regards,

0 Kudos

Hi friend,

in DB, there are unique key/primary key/foreign key. but there is no no-unique key. why there is suck key in table definition in ABAP?

thanks very much!

Former Member
0 Kudos

Hii!!

Read this if it helps..

You can specify the key key of an internal table as follows:

UNIQUE KEY col1 ... coln

In tables with a structured line type, all of the components col1 … coln belong to the key as long as they are not internal tables or references, and do not contain internal tables or references. Key fields can be nested structures. The substructures are expanded component by component when you access the table using the key. The system follows the sequence of the key fields.

UNIQUE KEY table_line

If a table has an elementary line type (c, d, f, i, n, p, t, x), you can define the entire line as the key. If you try this for a table whose line type is itself a table, a syntax error occurs. If a table has a structured line type, it is possible to specify the entire line as the key. However, you should remember that this is often not suitable.

UNIQUE DEFAULT KEY

This declares the fields of the default key as the key fields. If you have a structured line type, the standard key is build from all columns of the internal table that have a character-type type (c, d, t, n, x, string, xstring). Internal tables with a nested row structure have a standard key built by linearization of the row structure. At elementary row types, the standard key is the row itself. Elementary tables with an internal table as row type have an empty standard key.

Specifying a key is optional. If you do not specify a key, the system defines a table type with an arbitrary key. You can only use this to define the types of field symbols and the interface parameters of procedures . For exceptions, refer to Special Features of Standard Tables).

The optional additions UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can accept duplicate entries. If you do not specify UNIQUE or NON-UNIQUE for the key, the table type is generic in this respect. As such, it can only be used for specifying types. When you specify the table type simultaneously, you must note the following restrictions:

· You cannot use the UNIQUE addition for standard tables. The system always generates the NON-UNIQUE addition automatically.

· You must always specify the UNIQUE option when you create a hashed table.

Former Member
0 Kudos

Hi bo zhang

As you know unique keys are used as primary indexes in the where clause of a select statement.

To have secondary indexes in the where clause, we've to make use of non-unique keys.

But in performance view, we should not use, since as it is a non-unique, we come across many duplicates, so generally we use it as the situation demands.

At max., we can make 16 secondary indexes.

Here i like to differentiate b/w index and keys to clear the confusion. At the creation of database table through se11, we've to position the unique key fields at top of the table fields to clarify the entries to be identified.

About Indexes, after activating the table in se11, the system implicitly creates indexes for the table based on primary keys and secondary indexes based on non-unique keys.

For further doubts feel free to contact me.

If it helpful to you, reward me plz.

Thanks

Suren