2007 Apr 17 1:27 PM
Hye ,
Can anyone tel me how to find or how one can knw which field is a primary key of an INTERNAL table.
Thanks in advance.
Sunny
2007 Apr 17 1:30 PM
Hi..,
The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness depends on the table access method.
If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves internal tables. If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember this, for example, if you intend to sort the table according to the key.
regards,
sai ramesh
2007 Apr 17 1:30 PM
hi Sunny,
Primary Keys will not be for internal tables ... they are for database table ... for knowing which field in DB table ... check whether the column primary key is ticked for that particular field ... hope you are clear now ..
Regards,
Santosh
2007 Apr 17 1:31 PM
Hi Sunny,
The uniqueness of the record in an internal table purely depends upon the table form which the data is selected into it.
So, it is basically the database table that determines the key fields of the iternal table also.
If you select the data from mara, obviuosly matnr will act like a primary key.
If you get the data from a EKPO table, EBELN and EBELP will act as primary keys.
If you use any other field in read statement, you will get the first match for that value.
Regards,
Ravi
2007 Apr 18 8:32 AM
Hi,
The primary key identifies a unique record of a table.They ar enot for internal table, but they are for standard database tables.
If you create your own table, you can set the priamry key by selecting the "Key" checkbox.
The same goes for a database table.If the key checkbox is selected, it implies that the field is a primary key.
Thanks and regards,
Prerna
2007 Apr 18 9:41 AM
hi Sunny,
Primary Keys is only for database(Transparent) tables
not for internal tables....
Regards,
Purshoth
2007 Apr 20 8:47 AM
2007 Apr 20 1:45 PM
Hai SUNNY VASWANI,
<b>Primary Key Uniquly identifies the each row in the table.</b>
<b>For Sorted and Hashed internal tables you have to specify the Key.
But for Standard tables it is optional.</b>
Read about these three table below which helps you.
There are 3 Types of Internal tables
<b>Standard Internal Tables</b>
Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command). The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to
the number of table entries.
<b>Sorted Internal Tables</b>
Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition. Standard tables and sorted tables both belong to the generic group index tables.
This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of
table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.
<b>Hashed Internal Tables</b>
Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.
This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
using internal tables that are similar to database tables.
<b>So Analyze the field values in each record idenity which fields uniquely identifies the all rows.</b>
<b>Reward points if it helps you.</b>
Regds,
Rama chary.Pammi