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

Key column in an internal table?

Former Member
0 Likes
711

Hi all,

Can somebody tell me, if it is possible to create an internal table with a key-column?

I think it is, but I do not know how? So, How can I make it? Does this keys work exactly like DB table keys?

Thanks,

MPM

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
597

You can specify keys when defining your internal table.

data: imarc type sorted table of marc 
                  with unique key matnr werks.

You can also do this with a HASHED table

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
598

You can specify keys when defining your internal table.

data: imarc type sorted table of marc 
                  with unique key matnr werks.

You can also do this with a HASHED table

Regards,

Rich Heilman

Read only

Former Member
0 Likes
597

Why do you want such an internal table? It is in your control all the time, so can you not simply implement the logic to work like a database table with keys?

Here is one example from SAP help


TYPES: BEGIN OF STRUC, 
         NAME(10) TYPE C, 
         AGE      TYPE I, 
       END   OF STRUC. 

TYPES: TAB1 TYPE STANDARD TABLE OF STRUC WITH DEFAULT KEY, 
       TAB2 TYPE SORTED   TABLE OF STRUC 
                                WITH NON-UNIQUE KEY NAME, 
       TAB3 TYPE HASHED   TABLE OF STRUC WITH UNIQUE KEY NAME.

As you can see, you can only have unique key for hashed and sorted tables not for standard tables.

Srinivas

Read only

0 Likes
597

I'm not sure if it is correct that sorted tables can only have unique keys.

The table keys are important for access:

1. Every table with character fields have got a key by (SAP) definition. An unsorted standard table's key consists of all non-numeric fields. In this case the access will be sequential except for a binary search.

2. Sorted tables may have one unique or non-unique key consisting odf one or more fields. If the key is not unique, the entry with the lowest index is accessed.

3. Only Hash tables require a unique key

4. Only one key per internal table is allowed (no secondary keys as in other programming languages or database definitions).

5. See also:

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

regards,

Clemens