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

primary key in internal table

Former Member
0 Likes
3,083

hi experts,

psl tell me how to assign a primary key to an intarenal table field while using hashed table.

thanks

mani

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,221

Hi,

you have to use INSERT INTO TABLE..



TYPES: BEGIN OF TYPE_MATERIAL,
                MATNR TYPE MATNR,
                WERKS TYPE WERKS_D,
                MENGE TYPE EKPO-MENGE,
             END OF TYPE_MATERIAL.
 
 
* Internal table with MATNR as the key..
DATA: T_HASHED TYPE HASHED TABLE OF TYPE_MATERIAL
                            WITH UNIQUE KEY MATNR.

* Work area
DATA: WA TYPE TYPE_MATERIAL.

WA-MATNR = 'TEST'.
WA-WERKS = 'TEST'.

* Insert the values..
INSERT WA INTO TABLE T_HASHED.


Thanks

Naren

Hi,

Check this code..



TYPES: BEGIN OF TYPE_MATERIAL,
                MATNR TYPE MATNR,
                WERKS TYPE WERKS_D,
                MENGE TYPE EKPO-MENGE,
             END OF TYPE_MATERIAL.


* Internal table with MATNR as the key..
DATA: T_HASHED TYPE HASHED TABLE OF TYPE_MATERIAL
                            WITH UNIQUE KEY MATNR.


Thanks

Naren

6 REPLIES 6
Read only

Former Member
0 Likes
1,221

Hi,

Check this code..



TYPES: BEGIN OF TYPE_MATERIAL,
                MATNR TYPE MATNR,
                WERKS TYPE WERKS_D,
                MENGE TYPE EKPO-MENGE,
             END OF TYPE_MATERIAL.


* Internal table with MATNR as the key..
DATA: T_HASHED TYPE HASHED TABLE OF TYPE_MATERIAL
                            WITH UNIQUE KEY MATNR.


Thanks

Naren

Read only

Former Member
0 Likes
1,221

Hi Manikandan,

These many options are available.

For Primary key or without it.

TYPES <Internal Table Name> TYPE (Hashed/Sorted) OF [REF TO] type

<b>[UNIQUE | NON-UNIQUE] { {KEY comp1 comp2 ...}

| {DEFAULT KEY} }</b> INITIAL SIZE n

Reward if useful.

Read only

0 Likes
1,221

hi narendran thanxxxx for ur reply...i am gettting error when appending data into this itab.how to append data here ...i have used occurs 0 and header line in that itab .is there anything abt it ....why u have not used that...

Read only

Former Member
0 Likes
1,222

Hi,

you have to use INSERT INTO TABLE..



TYPES: BEGIN OF TYPE_MATERIAL,
                MATNR TYPE MATNR,
                WERKS TYPE WERKS_D,
                MENGE TYPE EKPO-MENGE,
             END OF TYPE_MATERIAL.
 
 
* Internal table with MATNR as the key..
DATA: T_HASHED TYPE HASHED TABLE OF TYPE_MATERIAL
                            WITH UNIQUE KEY MATNR.

* Work area
DATA: WA TYPE TYPE_MATERIAL.

WA-MATNR = 'TEST'.
WA-WERKS = 'TEST'.

* Insert the values..
INSERT WA INTO TABLE T_HASHED.


Thanks

Naren

Read only

0 Likes
1,221

THANXX FOR UR REPLY...WHEN WE WILL BE USING HASHED TABLES...IS THERE ANY PARTICULAR REASON FOR IT??

Read only

Former Member
0 Likes
1,221

hi,

hashed tables are used if you want to use UNIQUE keys as your search field, unlike in SORTED and STANDARD table where we use indexes. Access time using the key is constant, regardless of the number of table entries. so HASHED tables are best in storing records especially large ones.