‎2007 Jul 27 12:52 PM
how to delete a record from a hashed table.
i know tht we can do with table key.Buti m having some 4 keys.
so i cant delete with table key.
if two key values are satisfied i want to delete tht record how to implement where condition in hashed table.
Thanks in advance
‎2007 Jul 27 1:00 PM
Hi
Check out this code.
&----
*& Report ZHASHED *
*& *
&----
*& *
*& *
&----
REPORT ZHASHED .
TYPES : BEGIN OF EMP,
ID(3),
NAME(10),
SAL TYPE I,
END OF EMP.
DATA : TAB TYPE HASHED TABLE OF EMP WITH UNIQUE KEY ID.
DATA: WA LIKE LINE OF TAB.
WA-ID = 1.
WA-NAME = 'A'.
WA-SAL = 10000.
INSERT WA INTO TABLE TAB.
WA-ID = 2.
WA-NAME = 'A'.
WA-SAL = 10000.
INSERT WA INTO TABLE TAB.
WA-ID = 3.
WA-NAME = 'A'.
WA-SAL = 10000.
INSERT WA INTO TABLE TAB.
DELETE TAB WHERE ID = 2.
WRITE:/ SY-SUBRC.
LOOP AT TAB INTO WA.
WRITE:/ WA-ID, WA-NAME, WA-SAL.
ENDLOOP.
<b>Reward if Helpful</b>
‎2007 Jul 27 1:04 PM
thanks .
But i cant give the value statically since mine is field symbol.
How to delete a record from hashed table dynamically with where condition.
Thanks in advance.
‎2007 Jul 27 1:12 PM
you can delete the rows in the hashed table by using the table key. Kindly refer to the code sample given below,
DATA: BEGIN OF itab_line,
col1 TYPE i,
col2 TYPE i,
END OF itab_line.
DATA itab LIKE HASHED TABLE OF itab_line WITH UNIQUE KEY col1.
DO 5 TIMES.
itab_line-col1 = sy-index.
itab_line-col2 = sy-index * 2.
INSERT itab_line INTO TABLE itab.
ENDDO.
DELETE
DELETE itab WHERE col1 = 3.
LOOP AT itab INTO itab_line.
WRITE: / itab_line-col1, itab_line-col2.
ENDLOOP.
<b>If it helps kindly assign the points...</b>
Regards
‎2007 Jul 27 1:02 PM
Hi,
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.
Thus:
Code:
types: begin of typ_pernr,
pernr like pa0001-pernr,
ename like pa0001-ename,
end of typ_pernr.
data: ls_pernr type typ_pernr,
lt_pernr type hashed table of typ_pernr with unique key pernr.
...
select pernr ename into table lt_pernr from pa0001.
...
loop at itab.
read table lt_pernr with table key pernr = itab-pernr
into ls_pernr.
write: ls_pernr-ename, itab-data.
endloop.
Regards