Deleting Duplicate entries from Internal tbale
Hi All,
I have used this code to delete duplicate entries from an internal table.
DELETE ADJACENT DUPLICATES FROM IT_KOSTL COMPARING KOSTL hours.
After this statment, still the internal table will remain with a duplicate row.
Earlier table content before the delete statement:
Lno KOSTL PRCTR hours hours1
1 2081010205 0000208101 5525.000 1574.500
2 2081010105 0000208101 105162.000 73854.750
3 2081010105 0000208101 105162.000 73854.750
4 2081010205 0000208101 5525.000 1574.500
The Table gets modified after execution of DELETE statement as follows.
Lno KOSTL PRCTR hours hours1
1 2081010205 0000208101 5525.000 1574.500
2 2081010105 0000208101 105162.000 73854.750
3 2081010205 0000208101 5525.000 1574.500
Why the line 3 is still present in the table?
I hope as per that syntax, this line too should get delete.... Is it right?
Basically i would like to delete both line 3 and line 4 from....
How to resolve this issue?
Please help me out....
Regards
Pavan
What might be the reason?
>
Pavan Sanganal wrote:
> DELETE ADJACENT DUPLICATES FROM IT_KOSTL COMPARING KOSTL hours.
> Why the line 3 is still present in the table?
>
> I hope as per that syntax, this line too should get delete.... Is it right?
>
Let me answer you all doubts.
Why the line 3 is still present in the table?
Actually it's not 3rd line, it's 2nd line.3rd line were deleted.
when delete adjecent duplicates trigger than it would delete lower line(3rd in your case) not upper line.
I hope as per that syntax, this line too should get delete.... Is it right?
NO.
Similar Messages
-
To delete duplicate records from internal table
hi friends,
i have to delete records from internal table based on following criterion.
total fields are 7.
out of which if 4 fields are same and 5th field is different,then both records must be deleted.
in case all five fields are same,the program should do nothing.
for example.
if there are 3 records as follows
a1 b1 c1 d1 e1 f g
a1 b1 c1 d1 e2 w r
a1 b1 c1 d1 e1 j l
then first two records should be deleted as four fields are same but fifth(e) field differs.
but third record should remain as it is evenif first five fields are same for first and third record.
values of last two fields need not to be consider for deleting the records.LOOP AT ITAB.
V_FILED5 = ITAB-F5. "to compare later
V_TABIX = SY-TABIX. "used to delete if condition not matches
READ TABLE ITAB WITH KEY F1 = ITAB-F1
F2 = ITAB-F2
F3 = ITAB-F3
F4 = ITAB-F4.
IF SY-SUBRC = 0.
IF ITAB-F5 <> V_FIELD5.
*--both the records to be deleted,as Field5 is different.
DELETE ITAB INDEX SY-TABIX. "deletes that record
DELETE ITAB INDEX V_TABIX. "deletes the current record
ENDIF.
ENDIF.
ENDLOOP.
Message was edited by: Srikanth Kidambi
added comments
Message was edited by: Srikanth Kidambi -
Deleting entry from internal table
Hi Experts,
i have the following internal table:
data : it_result1 TYPE crmt_object_guid_tab
and work area
data : wa_result1 type crmt_object_guid.
i have to delete a guid from internal table based on some condition.
loop at it_resul1 into wa_result1
if lv_priority eq priority.
delete this entry from internal table.
endif.
endloop..
i tried using delete table it_result with table key CRMT_OBJECT_GUID = wa_result. but this is giving syntax error.
what should be done to delete the entry?
Thanks and regards
ShilpiHi
Check Syntax for DELETE operator on pressing F1
1. DELETE itab.
2. DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
3. DELETE TABLE itab [FROM wa].
4. DELETE itab INDEX idx.
5. DELETE itab FROM idx1 TO idx2.
6. DELETE itab WHERE logexp.
7. DELETE ADJACENT DUPLICATES FROM itab.
delete table it_result with table key CRMT_OBJECT_GUID = wa_result
this is wrong
delete it_result where CRMT_OBJECT_GUID = wa_result
Edited by: Lavanya K on Apr 22, 2009 10:20 AM -
Delete duplicate entriess from the internal table its urgent pls help.
Hi friends,
Hope everybody is doing good,Here is m query on delete duplicate data from the intenal table.
I have an internal table which contain data in the following format.
Doc No Comp Cod Vendor Assignment
1500000009 JM11 00000000
1500000008 JM11 20070212(Repeating)
1500000007 JM11 20070212
1500000006 JM11 00000000
1500000005 JM11 00000000
1500000004 JM11 00000000(Repeating)
1500000003 JM11 00000000 (Repeating)
1500000002 JM11 00000000
1500000001 JM11 20050302
1500000000 JM11 00000000
1500000003 JM11 10000088
1500000001 JM11 10000088
1500000030 JM11 10006260
1500000010 JM11 10006269
1500000008 JM11 10006269
1500000006 JM11 10006269
1500000004 JM11 10006269
if you see the document numbers,there are some document number which are repeating here,there are some document numer which contain vendor number but not the assignments,some of the document numbers contain the assignments but not the vendors.
If my internal table contain this kind of data with repeted document numbers than i want the document number which contains only the vendor number.
Pls help me with the appropriate logic,its urgent.
Thanks a lot
mrutyun^Hi,
<u><b>Deleting Adjacent Duplicate Entries</b></u>
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f2> ...
|ALL FIELDS].
The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are
duplicate if they fulfill one of the following compare criteria:
Without the COMPARING addition, the contents of the key fields of the table must be
identical in both lines.
If you use the addition COMPARING <f1> <f2> ... the contents of the specified fields <f1>
<f2> ... must be identical in both lines. You can also specify a field <fi> dynamically as
the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is
executed, it is ignored. You can restrict the search to partial fields by
specifying offset and length.
If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines
must be identical.
You can use this statement to delete all duplicate entries from an internal table if the table is
sorted by the specified compare criterion.
If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.
Examples
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 1.
DELETE TABLE ITAB: FROM LINE,
WITH TABLE KEY COL1 = 3.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2.
ENDLOOP.
The output is:
2 4
4 16
The program fills a hashed table with a list of square numbers. The DELETE
statement delete the lines from the table where the key field COL1 has the contents 1 or 3.
Regards,
Bhaskar -
Problem in deleting entries from internal table
i am selecting
vrgar
perio
paobjnr
belnr
gjahr
perde
budat
kndnr
artnr
frwae
kursf
rec_waers
kaufn
kdpos
bukrs
kokrs
werks
gsber
vkorg
vtweg
spart
rbeln
rposn
prctr
pprctr
kunnr
land1
regio
kunwe
kvgr1
wwpmg
zterm
wwcst
wwrst
mvgr3
wwseg
wwcls
wwesa
prdha
wwbun
wwexd
wwph1
wwph2
wwph3
wwph4
prat1
prat2
vrprs
vv510
vv508
vv509
vvqt2
vv515
INTO TABLE ct_ce11000 FROM ce11000
WHERE paledger EQ gv_ledbo AND
vrgar EQ lc_vrgar AND
belnr GT uv_belnr AND
gjahr EQ pa_gjahr AND
perde EQ pa_perd AND
bukrs EQ pa_bukrs.
now i awant to delete all those entries from my internal table ct_ce11000 where my plant (WEKRS) and company code (BUKRS)
i am writting
loop at ct_ce11000 into wa_ce11000.
if wa_ce11000-werks ne wa_ce11000-bukrs.
now how can i delete all the entries from nmy internal table (ct_ce11000) when plant and company code is not same
pls help me with logic.
thank you for helping meHello Guys,
It is not advisable to delete the entries from the internal table you are looping upon. See this thread: [Sy-tabix in loop : Doubt|Sy-tabix in loop : Doubt]
And to answer the OP's question select data into some local internal table & based on the condition populate your final table. Creating a local table of the same type as the final table will not create too much performance overhead
Cheers,
Suhas -
How to delete duplicate entries in match code
I want to delete duplicate entries in match code.
If you go down the search exit route, using function module F4_IF_SHLP_EXAMPLE or function module F4_IF_SHLP_EXIT as a template you want it where callcontrol-step = 'DISP'. You would sort the table: SORT RECORD_TAB BY STRING and then delete adjacent duplicates. If this does not wok because of the fields you have in your search help, you will need to select the data into another internal table and match the relevant entries from your internal table with the relevant position in field STRING of RECORD_TAB. The positions in STRING will be as per the order of the parameters you have defined in the search help.
Hope this helps.
Regards
Larissa -
How to check duplicate entries in internal table??
Dear Friends,
How to check duplicate entries in internal table??
Exp: In my internal table if I am having the same records more then ones then I need to print the error message, here I am using steploop for selecting the values from screen, and the values are coming into my internal table if user enter the same value more then ones I need to print the error message.
Thanks,
SridharHi,
After storing the data into internal table say ITAb, move the data into another internal table.
t_dup[] = itab[].
LOOP AT itab.
count1 = count1 + 1.
itab-count1 = count1.
MODIFY itab.
ENDLOOP.
LOOP AT t_dup.
count2 = count2 + 1.
t_dup-count2 = count2.
MODIFY t_dup.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM itab.
LOOP AT t_dup.
record_dup = 'N'.
READ TABLE itab WITH KEY count1 = t_dup-count2.
IF sy-subrc = 0.
record_dup = 'Y'.
ENDIF.
IF record_dup NE 'Y'.
t_dup-message = 'DUPLICATE ENTRY'.
t_dup-flag = 1.
MODIFY t_dup.
ENDIF.
ENDLOOP.
Use this sample code.
Reward pts if it is helpfull.
Regards
Srimanta -
Please go to the following website:-
http://help.sap.com/saphelp_nw04/helpdata/en/06/aafd54fc4011d195280000e8353423/content.htm
and please scroll down to find:-
<b>Deleting Adjacent Duplicate Entries</b>
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f 2> ...
|ALL FIELDS].
Then please go to the last example where the code is written as :-
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.
IS THIS CORRECT ?
Regards
abaper.learnerHi learner,
<b>Deleting a sequence of lines</b>
DO 101 TIMES.
DELETE TAB_DEST INDEX 450.
ENDDO.
DELETE TAB_DEST FROM 450 TO 550.
<b>Deleting a set of lines</b>
LOOP AT TAB_DEST
WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP
DELETE TAB_DEST WHERE K = KVAL.
<b>DELETE ADJACENT DUPLICATES</b>
As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
LOOP AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.
IF TAB_DIFFERENT = SPACE. " ...
ENDIF.
IF TAB1[] = TAB2[]. " ...
ENDIF.
Regards,
Kumar. -
How to delete duplicate entries in address book
Is there an easy way to delete duplicate entries in Address Book?
I have an iPhone where I create new contact details and a MB Air running OX X 10.7.3
In Address Book I see duplicate entries across the whole book. The other day I was traveling without my MB and needed to urgently reach someone who's number I knew was in my iPhone contact list for sure but searched and search and couldn't find it.
Turns out that when I had been going through the Adress Book on the MB Air trying to eliminate some of the duplicates I had chosed --without even knowing it or realzing it-- the card that I guess sync with my iPhone. It was gone. Sure enough, when I got back and looked it up on the MB Air it was still there not syncing to my iPhone.
I have used Address Book / Card / Look for Duplicates ...
I have also followed the Help suggesting and pressed Control / select to highlight two duplicate cards and even though the First / Last / Company / phone numbers / etc. are all the same I get the message: "The cards could not be merged because they came from different accounts."
I have checked with guys from the office who have the exact same problem with no idea how to solve the problem.
Is it that in order to use Address Book on both an iPhone and an OS X machine you've just got to be smarter, more sophisticated, more IT oriented?
Seems like a pretty easy thing not to be struggling with.
I should mention that I was a Mobile Me subscriber and now use iCloud which I'm sure has something to do with all of this.
But it seems pretty basic to me. If I have an Address Book it should synchronize between OX X and IOS. -
Remove duplicate entries from dropdownlist in web dynpro abap
How to remove duplicate entries from dropdownlist in web dynpro abap? Can someone please help me
I have maintained the data in the z table wherein the records of particular fields are repeated but when i show that record in the Web Dynpro application dropdown list, the user should only be able to view the unique data for selection of that particular field.Hi,
try this code in init method.
use the
Delete adjacent duplicates.
<set the table>
select <f1> from <table> into TABLE <Itab> whre <condition>.
DELETE ADJACENT DUPLICATES FROM <Itab> COMPARING <f1>.
lo_nd_vbap->bind_table( new_items = <itab> set_initial_elements = abap_true ). -
Trick to remove duplicate entries from tables ?
hi.
i have 53tables which are having duplicate entries and names of all 53 tables r listed in top_t table ?
can any1 provide me solution to show and if possible ask for remove of those duplicates entries from each table if required ?
daily i am removing duplicates manually ....its too tedious now !
can any1 help me out ?Well, I suppose if the duplication is such that
SELECT DISTINCT * FROM tablename;gives you the required result, then you could have a procedure that made a copy of the table, deleted/truncated the original, then inserted the distinct values back into it.
In 10g you could even use flashback to avoid the temp copy - but it also means you can't use TRUNCATE so whether it's any more efficient I'm not sure. But just for fun and since it's urgent:
CREATE OR REPLACE PROCEDURE dedupe_table
( p_table_name user_tables.table_name%TYPE )
IS
k_start_timestamp TIMESTAMP := SYSTIMESTAMP;
BEGIN
SAVEPOINT start_of_dedupe;
BEGIN
EXECUTE IMMEDIATE 'DELETE ' || p_table_name;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO start_of_dedupe;
RAISE_APPLICATION_ERROR
( -20000
, 'Error deleting ' || UPPER(p_table_name) ||
CHR(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
, TRUE );
END;
BEGIN
EXECUTE IMMEDIATE
'INSERT INTO ' || p_table_name ||
' SELECT DISTINCT * FROM ' || p_table_name || ' AS OF TIMESTAMP :b1'
USING k_start_timestamp;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO start_of_dedupe;
RAISE_APPLICATION_ERROR
( -20000
, 'Error repopulating ' || UPPER(p_table_name) ||
CHR(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
, TRUE );
END;
END dedupe_table;
SQL> select * from wr_test;
COL1 C C
1 A B
1 A B
2 C D
2 C D
4 rows selected.
SQL> BEGIN
2 dedupe_table('WR_TEST');
3 END;
4 /
PL/SQL procedure successfully completed.
SQL> select * from wr_test;
COL1 C C
1 A B
2 C D
2 rows selected.I make no claims for robustness, efficiency or human safety.
Edited by: William Robertson on Sep 24, 2009 7:12 PM -
I have two tables (Accounts, and Accounts_LOAD). The _Load table is a daily feed.
For my first step, I need to delete all the duplicates from _Load that exist in Accounts.
How can I delete duplicate entries which exist in two tables..?I think that the Merge will suffice. My apologies.
But, now (again, sorry) I have a couple questions on the merge.
Below is similar to what I would use and a few Q's on it....
line4: can u use multiple "on" ?
line5:For 'when matched' i only want to update fields from "_load" to "Accounts" that need to be updated. If they are the same, they would be ignored... is that possible...?
1 MERGE INTO accounts acc
2 USING (SELECT **ALLFIELDS**
3 WHERE SOMESTUFF=STUFFS) STF
4 ON (ACC.ID_USER = STF.ID_USER) AND (ACC.SYSTEM_ID = STF.SYSTEM_ID)
5 WHEN MATCHED THEN UPDATE SET acc.bonus = D.bonus + S.salary*.01
6 DELETE WHERE (S.salary > 8000)
7 WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
8 VALUES (S.employee_id, S.salary*0.1)
9 WHERE (S.salary <= 8000); -
Deleting duplicate entries in iCal?
How do I delete duplicate entries in iCal (identical entries on the same date)?
Todd,
I suspected a more serious problem because the answer was too easy.
Thousands of duplicate entries...Is this what happened?
According to, Mac OS X 10.4: Stay away from the SyncServices folder: As if it were a swarm of bees, you should stay away from the SyncServices folder in Mac OS X 10.4. Removing or modifying anything in it—or in subfolders within it—may cause unexpected issues. (This folder is located in your Application Support folder, in your Library folder, in your Home folder.)
Deleting or modifying things in the SyncServices folder may cause unexpected results such as:
• Duplicate contacts in Address Book or appointments in iCal.
• Data loss in Address Book or iCal.
Important: Any lost or duplicate data could propagate to other devices and computers via iSync and .Mac sync. This means data could be lost on other computers.If that is your problem, I suspect that without a backup, duplicate entry deletion will at best be tedious, and at worst fraught with frustration. You may be better off starting from scratch.
;~) -
Remove duplicate entry from table
Hello all,
In my one table
File Stage log (File_Stage_Log_ID int identity(1,1),File ID int ,Quarter_Date nvarchar(50),StageID int )
have done duplicate entry by mistake on similar quarter_date
something like ..
FILE_ID
Quarter
FILE_STAGE_LOG_ID
STAGE_ID
22401
Dec-13
233091
450
22401
Dec-13
244116
420
22401
Mar-14
233095
450
22401
Mar-14
237478
405
22401
Jun-14
237479
405
22401
Jun-14
233099
450
22401
Sep-14
233102
450
22401
Sep-14
237480
405
22401
Dec-14
237481
405
22401
Dec-14
227275
420
there are too many files which have the same duplicacy ..
now , above you can see that dec -13 quarter coming twice for a single file
tell me the way to delete one entry from the table for a files
so that i have output at the end like ...
FILE_ID
Quarter
FILE_STAGE_LOG_ID
STAGE_ID
22401
Dec-13
233091
450
22401
Mar-14
233095
450
22401
Jun-14
237479
405
22401
Sep-14
233102
450
22401
Dec-14
237481
405
Please help me with easiest possible way ..
Dilip Patil..How do you determine which one out of duplicate to be kept? As per output it doesnt follow any pattern
so it may be this
--DELETE t
SELECT *
FROM
SELECT ROW_NUMBER() OVER (PARTITION BY FILE_ID,Quarter_Date ORDER BY FILE_ID) AS Rn,*
FROM FileStageLog
)t
WHERE Rn >1
Run the select above to see records to be removed and once happy uncomment the delete, comment the select * and run the query to do the delete
If it doesnt give expected records, explain on what basis you want to identify records to be deleted
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
TS4062 how do i remove duplicate entries from my phone directory?
question; how do i remove duplicate entries from my phone directory?
go to your contacts icon and choose the one you want to delate
Choose edit, top right and go (scroll) to the bottom of the page and press delete contact
Maybe you are looking for
-
How to get the value of a specific field in JTable
hi every one,,, i'm intersting to get a field of JTable how can i decide the row and the column of JTable??? and in which type will be the field ??
-
Capital Import Purchase Order for 1000000000.0000 Euro
Dear Sir I am creating Capital Import Purchase Order for 1000000000.0000 Euro.We have already set price up to four decimals also in case of Imports. But Field is not allowing Purchase Order for that amount, its reducing the price. Ma
-
Is there a way to select external skins for Flash media in Dreamweaver? In Dreamweaver 8, I only have the selection of 3 different kind of skins...all internal to the video. Does anyone know a solution to this? Thank you.
-
Cross-Repository Validation/Load
Assume that in the Product repository we have a qualified-lookup table which contains the Vendor/Pricing for a part. In this case we have two master objects that are (somewhat)related... like a Purchase Info Record in R3 ERP. The Product and the Vend
-
How can I sign in to my hotmail,gmail,aol,Facebook?
I tried to login but it says that "Service not enabled for this handheld"... Wat do I do?