10-18-2006 4:14 PM
Hi, EXPERTS:
I have an internal table ITAB and a transparent table ZTABLE, with exactly same fields. Before I insert ITAB into ZTABLE, I need to delete those records which are existing with same primary key in ZTABLE, and save these deleted records to another internal table. How to do that?
Thanks.
Tom
10-18-2006 4:17 PM
Sort the ITAB based on the key field.
Delete adjacent duplicates comparing <the key fields>.
Ex:
Sort itab by name1.
DELETE ADJACENT DUPLICATES FROM itab comparing name1.
Regards,
Prakash.
10-18-2006 4:17 PM
Sort the ITAB based on the key field.
Delete adjacent duplicates comparing <the key fields>.
Ex:
Sort itab by name1.
DELETE ADJACENT DUPLICATES FROM itab comparing name1.
Regards,
Prakash.
10-18-2006 4:17 PM
U can try the below.
SELECT fields into table idel
from ztable
for all enteries in itab
where f1 = itab-f1 and f2 = itab-f2.
delete ztable from table idel.
10-18-2006 4:19 PM
Hi,
Create new internal table itab_new where you can keep deleted records & proceed as below.
loop at internal table (ITAB).check data from ZTABLE using select with condition as ztable-field = itab-field.
if data is found then,
move ztable data to new internal table (ITAB_new).
append record .
delete record from ztable.
endif.
endloop.
Thanks.
10-18-2006 4:20 PM
Hi,
Assume your table is ZTABLE
IATB is where your complete data is stored
ITAB_DEL is the table where you are storing deleted recors
ITAB_ZTABLE is a temp table to check the records in the ZTABLE
DATA: BEGIN OF ITAB_ZTABLE OCCURS 0,
FIELD1 TYPE FIELD1,
FIELD2 TYPE FIELD2,
END OF ITAB_ZTABLE.
SELECT FIELD1 FIELD2 INTO TABLE ITAB_ZTABLE
FROM ZTABLE
FOR ALL ENTRIES IN ITAB
WHERE FIELD1 = ITAB-FIELD1.
LOOP AT ITAB.
READ TABLE ITAB_ZTABLE WITH KEY FIELD1 = ITAB-FIELD1.
IF SY-SUBRC = 0.
APPEND ITAB TO ITAB_DEL.
DELETE ITAB.
ENDIF.
ENDLOOP.
Thanks,
Ramakrishna
10-18-2006 4:23 PM
Hi,
Try this logic..
SORT ITAB BY KEY FIELDS.
DATA: V_INT TYPE INT4.
LOOP AT ITAB.
AT NEW OF THE LAST KEY FIELD..
CLEAR: V_INT.
ENDAT.
V_INT = V_INT + 1.
IF V_INT > 1.
MOVE ITAB TO ITAB_DUPLICATE.
ENDIF.
AT END OF THE LAST KEY FIELD..
CLEAR V_INT.
ENDAT.
ENDLOOP.
THanks,
Naren
10-18-2006 5:07 PM
Hi,
follow below logic
data itab like itab occus 0 with header line
if not itab[] ia initial.
select * from ztable into itab1
for all entries in itab
where fld = itab-fld.
if sy-subrc eq 0.
*Some duplicates exists
delete ztable from table itab1.
endif.
*no duplicates exists
insert ztable from table itab.
Regards
amole