Comparing Duplicates in an internal table
Hi ,
Can anyone let me know , how to compare two duplicate records in an internal table.
is there any Function Module or Command for it.
Please let me know .
Thank you ,
Regards,
Roby
Check this logic works:
REPORT yspra_sample89.
TYPES: BEGIN OF ty_data,
column1 TYPE char10,
column2 TYPE char10,
END OF ty_data.
DATA: i_data TYPE ty_data OCCURS 0 WITH HEADER LINE,
i_data_repeat TYPE ty_data OCCURS 0 WITH HEADER LINE.
DATA: wa_data TYPE ty_data,
wa_data1 TYPE ty_data.
DATA: lines TYPE sy-tabix.
i_data-column1 = '10'.
i_data-column2 = '20'.
APPEND i_data.
i_data-column1 = '10'.
i_data-column2 = '20'.
APPEND i_data.
i_data-column1 = '10'.
i_data-column2 = '20'.
APPEND i_data.
i_data-column1 = '10'.
i_data-column2 = '20'.
APPEND i_data.
SORT i_data BY column1 column2.
LOOP AT i_data INTO wa_data.
lines = sy-tabix + 1.
READ TABLE i_data INTO wa_data1 INDEX lines.
IF sy-subrc = 0.
IF wa_data = wa_data1.
APPEND wa_data1 TO i_data_repeat.
ENDIF.
ENDIF.
CLEAR: lines, wa_data, wa_data1.
ENDLOOP.
LOOP AT i_data_repeat.
WRITE: / i_data_repeat-column1 , i_data_repeat-column2.
ENDLOOP.
Sort ur table first and read the next row if it duplicate append it to some internal. In this way u can take all the duplicate records.
Regards,
Prakash.
Similar Messages
-
Removing duplicates in the Internal Table
Dear friends,
Could any one of you kindly help me with a code to delete the duplicates in the internal table, but each duplicate should be counted, how many times that appeared and should be displayed again as a report with the messages and no of times that message appeared.
Thank you,
Best Regards,
subramanyeshwerYou can try something like this.
report zrich_0001.
data: begin of itab1 occurs 0,
fld1 type c,
fld2 type c,
fld3 type c,
end of itab1.
data: begin of itab2 occurs 0,
fld1 type c,
fld2 type c,
fld3 type c,
end of itab2.
data: counter type i.
itab1 = 'ABC'. append itab1.
itab1 = 'DEF'. append itab1.
itab1 = 'GHI'. append itab1.
itab1 = 'DEF'. append itab1.
itab1 = 'GHI'. append itab1.
itab1 = 'DEF'. append itab1.
itab2[] = itab1[].
sort itab1 ascending.
delete adjacent duplicates from itab1.
loop at itab1.
clear counter.
loop at itab2 where fld1 = itab1-fld1
and fld2 = itab1-fld2
and fld3 = itab1-fld3.
counter = counter + 1.
endloop.
write:/ itab1-fld1, itab1-fld2, itab1-fld3,
'Number of occurances:', counter.
endloop.
Regards,
Rich Heilman -
Function module for comparing contents of two internal tables
Hi All,
Is there any function module to compare contents of two internal tables of same structure?
If yes please let me know.
Thanks in advance.
AmolHi
call SE16 with table TFTIT in order to get a full list (it will be long...)
A list of FMs with parameters can be found in table FUNCT.
Finally go to sm37rsdf4
that will give you all the function modules with description
Here is the list:
http://www.erpgenie.com/abap/functions.htm
hope this helps...
Regards
CSM Reddy -
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 -
Duplicate Entries in Internal table
Hi All,
As per my requirement
1. The internal table is the input.
2. I need the duplicate records of the internal table with the combination of 2 key fields.
3. I should not use SORT because i need the index number in order as per in the table .
EX : Take Table MSEG.
Take key fields as MBLNR and WERKS.
I want the duplicate records of the combination of these 2 key fields.
The *Index Number * should not to be changed as per the table entry. ( So i avoided sorting the internal table)
Kindly give some solutions.
Thanks,
Pradeep.
Moderator message : Duplicate post locked,follow forum Rules of Engagement. Thread locked.
Edited by: Vinod Kumar on Mar 1, 2012 4:59 PMHi Pradeep,
Try this...
first you copy your internal table to another temporary table of same type.
itab_temp[] = itab[].
sort itab_temp[].
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MBLNR WERKS.
LOOP AT ITAB_TEMP INTO WA_ITAB1.
DO.
READ TABLE ITAB INTO WA_ITAB2 WITH KEY MBLNR = WA_ITAB1-MBLNR AND WERKS = WA_ITAB1-WERKS.
IF SY-SUBRC EQ 0.
APPEND WA_ITAB2 TO ITAB_NEW.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
you may get the duplicate records in itab_new. -
Duplicate records in Internal table
Hi All,
I want to find out the duplicate entry in the internal table. I have used,
Delete Adjacent duplicates from itab.
It is straight away deleting the record.
I want the user to correct that duplicate record.
May be some error message.
I have tried, with read,
Read table itab with key bzirk = itab-bzirk vkorg = itab-vkorg kunnr = itab-kunnr
matnr = itab-matnr comparing bzirk vkorg kunnr matnr.
But it's giving sy-subrc = 0 for the first record also.
Even, I have tried like, but it's giving syntax error.
Loop at itab where bzirk = itab-bzirk vkorg = itab-vkorg kunnr = itab-kunnr
matnr = itab-matnr.
Endloop.
Any method in case on Table control entries.
Thanks & Regards,
Kalyan Chandramouli
SAP ConsultantHi,
Create a new internal table and assign the all the records of itab1 to itab2.
1.Sort Itab2.
2.delete adjacent duplicates.
3. loop at itab2.
loop at itab1 where <conditon you want....>
count = count + 1.
endloop.
if count GT 1.
append the iatb2 records for user correction....
endif.
endloop.
If the hint is useful Say thanks by reward .
Regards,
Prabhu Rajesh -
Duplicate Entries in Internal Tables
Hallo Friends,
It Would be nice if some one let me know, if there is a way in ABAP to select the duplicates records in an internal tables.
Lets say I have two internal tabels, itabA have following structure:
BNAME | WORKAREA | ROLES
abc | wa1 | ro1
cde | wa1 | ro1
cde | wa3 | rol..
abc | wa2 | rol2
xyz | wa1 | rol3
xyz | wa3 | rol2..
the itabB have the following structure:
WORKAREA | ROLES|
wa1 | rol1
wa2 | rol1
wa3 | rol1
wa4 | rol1
Now problem is, I need to select the common WorkAreas from itabA ( which is commom in all BNAME ) in above example it will be workarea wa1. as it is commom in all i.e ( abc ,cde and xyz). I need to select this commom workarea, and then mark it with some flage in itabB ( to display that this workarea is common among the users...)
Would be nice if some one let me know, is there any way I can select the duplicate rows in an internal table or I have to go one by one and then do some kind of comparision.
Many thanks,
Thx in advance....
HaiderHi marek,
below information might help you.
The first criterion for comparing internal tables is the number of lines they contain. The more lines an internal table contains, the larger it is. If two internal tables contain the same number of lines, they are compared line by line, component by component. If components of the table lines are themselves internal tables, they are compared recursively. If you are testing internal tables for anything other than equality, the comparison stops when it reaches the first pair of components that are unequal, and returns the corresponding result.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA: ITAB LIKE TABLE OF LINE,
JTAB LIKE TABLE OF LINE.
DO 3 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
MOVE ITAB TO JTAB.
LINE-COL1 = 10. LINE-COL2 = 20.
APPEND LINE TO ITAB.
IF ITAB GT JTAB.
WRITE / 'ITAB GT JTAB'.
ENDIF.
APPEND LINE TO JTAB.
IF ITAB EQ JTAB.
WRITE / 'ITAB EQ JTAB'.
ENDIF.
LINE-COL1 = 30. LINE-COL2 = 80.
APPEND LINE TO ITAB.
IF JTAB LE ITAB.
WRITE / 'JTAB LE ITAB'.
ENDIF.
LINE-COL1 = 50. LINE-COL2 = 60.
APPEND LINE TO JTAB.
IF ITAB NE JTAB.
WRITE / 'ITAB NE JTAB'.
ENDIF.
IF ITAB LT JTAB.
WRITE / 'ITAB LT JTAB'.
ENDIF.
The output is:
ITAB GT JTAB
ITAB EQ JTAB
JTAB LE ITAB
ITAB NE JTAB
ITAB LT JTAB
This example creates two standard tables, ITAB and JTAB. ITAB is filled with 3 lines and copied to JTAB. Then, another line is appended to ITAB and the first logical expression tests whether ITAB is greater than JTAB. After appending the same line to JTAB, the second logical expression tests whether both tables are equal. Then, another line is appended to ITAB and the third logical expressions tests whether JTAB is less than or equal to ITAB. Next, another line is appended to JTAB. Its contents are unequal to the contents of the last line of ITAB. The next logical expressions test whether ITAB is not equal to JTAB. The first table field whose contents are different in ITAB and JTAB is COL1 in the last line of the table: 30 in ITAB and 50 in JTAB. Therefore, in the last logical expression, ITAB is less than JTAB.
reward with points and close the thread if your question is solved
regards,
venu. -
Regarding Delete duplicates adjacent in internal table
hey
In my report i tried to delete the adjacent datas as
below from table itab_rbusa.but it is not deleting. why
code------
append lines of itab_glt0[] to itab_rbusa.
delete adjacent duplicates from itab_rbusa comparing all fields.
endof code----
if internal table has below values
011F
316A
789B
789B
131B
132B
302B
i get the same values as output after using the delete statement why?(789B-Business Area is not deleting)
could you please guide me.
ambichan.Hi,
You can use the addition FOR ALL ENTRIES rather than issuing SELECT in a loop. Try something like:
SELECT [DISTINCT] rbusa
FROM glt0
INTO TABLE itab_glt0
FOR ALL ENTRIES IN TABLE itab_t001
WHERE bukrs EQ itab_t001-bukrs
AND <other fields>...
APPEND LINES OF itab_t001[] TO itab_rbusa....
If DISTINCT does not serve the purpose, then you will need:
SORT itab_rbusa.
DELETE ADJACENT DUPLICATES FROM...
Regards
Message was edited by: Shehryar Khan -
To find the duplicate record in internal table
Hi,
i have a requirement to fine the duplicate record with 3 fields.
i am getting a flat file with 15 fields .
i need to check the duplaicate records of 3 fields . if i get any 2nd same record of 3 fields , the records will go to other internal table.
for ex :
1. aaa bbb ccc ddd eee fff ggg hhh
2. aaa bbb ccf dde edd ffg ggh hhj
3. aaa bbb cce ddd ees ffh ggu hhk
in that 1st record and 3rd record are same (aaa bbb ddd)
i need to find 3rd record
please help me
regrards
srinivasuhi,
itab2[] = itab1[].
sort itab1 by f1 f2 f3.
sort itab2 by f1 f2 f3.
delete itab2 index 1. "to delete the first record in itab2.
loop at itab1 into ws_itab1.
loop at itab2 into ws_itab2.
if ws_itab1-f1 = ws_itab2-f1 and
ws_itab1-f2 = ws_itab2-f2 and
ws_itab1-f3 = ws_itab2-f3.
ws_itab3 = ws_itab2.
append ws_itab3 into itab3. "Third internal table.
endif.
endloop.
delete itab2 index 1.
endloop.
ITAB3 will have all the duplicate records.
Regards,
Subramanian -
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 -
Urgent: to compare plant name in internal table with plant of log on user
Dear Guru,
I want to compare whether plant of current log on user and plant data in internal table are same. Does anyone has examples or concepts of doing this. Solved answer will be rewarded. Thanks.
Cheers,
Message was edited by:
SAP HunterA user is assigned to authorisation roles.The data for the authorisation is stored in AGR* tables.
Check AGR* series of tables... -
How to compare records in singe internal table
Hi Folks,
iam having 3 records in my first itab( T_FINAL) with fields
material no, descrip , mat type and group.
and 16 records in second itab(T_MVKE ) with fields
mat no , distri.chanel and division
now I want to fetch the records from T_MVKE by comparing the records in
T_FINAL .my requirement is to check the given mat no. in sales org.2000,2100. if yes then i have to consider 2000 only, if it is in only 2100 then consider 2100 only . is it is in 2000 only then consider 2100 only
my code is
LOOP AT T_FINAL.
READ TABLE T_MVKE WITH KEY MATNR = T_FINAL-MATNR.
IF SY-SUBRC = 0.
ON CHANGE OF T_MVKE-MATNR OR T_MVKE-VKORG.
IF T_MVKE-VKORG = '2000' and SY-TABIX > 1.
CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
ELSEIF T_MVKE-VKORG = '2000' AND SY-TABIX = 1.
CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
ELSE.
CONCATENATE '2100' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
ENDIF.
this logic fails ,. could tell me how to compare values in single itab?
Thanks
nehaHi ,
if i've understand you correctly , try that:
LOOP AT t_final.
AT NEW matnr.
CLEAR: v_2000, v_2100.
*1) 2000
READ TABLE t_mvke WITH KEY matnr = t_final-matnr
vkorg = 2000.
IF sy-subrc = 0.
v_2000 = 'X'.
ENDIF.
*2) 2100
READ TABLE t_mvke WITH KEY matnr = t_final-matnr
vkorg = 2100.
IF sy-subrc = 0.
v_2100 = 'X'.
ENDIF.
*compare
IF v_2000 = 'X' AND v_2100 = 'X'.
*read 2000 only
ELSEIF v_2000 = ' ' AND v_2100 = ' '.
*nothing found
ELSE.
*all other combinations
*read 2100 only
ENDIF.
ENDAT.
ENDLOOP.
regards Andreas -
Delete Duplicates from internal table with object references
Hi
How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
I have created a method, with the following code:
LOOP AT me->business_document_lines INTO l_add_line.
CREATE OBJECT ot_line_owner
EXPORTING
i_user = l_add_line->add_line_data-line_owner
i_busdoc = me->business_document_id.
APPEND ot_line_owner TO e_line_owners.
ENDLOOP.
e_line_owners are defined as a table containing only object references.
One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
How can do this?
Regards,
Morten NielsenHello Morten
Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
SORT e_line_owners BY table_line->user.
DELETE ADJACENT DUPLICATES FROM e_line_owners
COMPARING table_line->user.
However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
Alternative solution:
DATA:
ld_idx TYPE sy-tabix.
LOOP AT e_line_owners INTO ls_line.
ld_idx = syst-tabix + 1.
LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
WHERE ( table_line->user = ls_line->user ).
DELETE e_line_owners INDEX syst-tabix.
ENDLOOP.
ENDLOOP.
Regards
Uwe -
Delete duplicate from internal table
HI Abapers,
I have a query on how to remove the duplicates from an internal table
My internal table data is as follows :
Cno Catg1 Catg2
01 0 1000
01 2000 0
I want to get only one record as
01 2000 1000
How to get the result.
I tried sorted by cno and used delete duplicates but it was not helpful.
Is there any other alternative to get this done
Please help me.
Regards,
Priyacheck it out with delete adjacent duplicate records
Deleting Adjacent Duplicate Entries
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f 2> ...
|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> <f 2> ... the contents of the specified fields <f 1 > <f 2 > ... must be identical in both lines. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > 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. -
How to compare two entries in the same internal table
Hi
I hav e an internal table. I want to compare the entries in the internal table and delete the entries which is duplicates from the internal table. for ex. if plant 1000 is repeated two times. Then both the record of plant 1000 should be removed .
Please suggest some idea.
Thanks
SubhaHi,
Apply this code.
include one more field in itab & jtab as delete_flag(1) type c.
move itab to jtab.
Loop at itab into wa_itab.
lv_tabix = sy-tabix.
Loop at jtab into wa_jtab where plant = wa_itab-plant.
if sy-tabix ne lv_tabix.
wa_itab-delete_flag = 'X'.
endif.
Endloop.
modify itab from wa_itab transporting delete_flag.
clear: wa_itab,wa_jtab.
endloop.
delete itab where delete_flag = 'X'.
Now you have filtered ITAB with your desired results.
It will surely help.
Edited by: Adarsh Jain on Aug 18, 2010 7:57 AM
Edited by: Adarsh Jain on Aug 18, 2010 7:58 AM
Maybe you are looking for
-
I set up my fingerprint ID and it worked fine for 1.5 weeks. Last night phone shut off for no reason. I turned back on and fingerprint id does not work. Cannot see my fingerprint in settings to even edit it, and I cannot add a fingerprint. Have d
-
What kind of "PCI to PCMCIA" adaptor do I need?
I have been logging data from analytical balances to a laptop running LabVIEW through a "4 port PCMCIA RS-232 Interface board". I would like to know if I can still use this card in a normal desktop PC by a "16-bit PCMCIA-PCI adaptor". Thanks.
-
Embedded Icc Profiles-Are they needed?
What are they for? Do i need them if my images contain no color?
-
I have created two different forms that I need to combine. Whether I have someone fill out Form B is conditional on an answer within Form A. It would be nice if, at completion of Form A, the user could be sent directly to Form B. Is there any way to
-
How convert Microsoft viso to JPEG Image format
Hi, Can any one suggest me how to convert Microsoft Visio format to JPEG Image format in java. Please write me back at [email protected] Thanks, Meraj