2006 Oct 05 5:55 PM
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
2006 Oct 05 6:22 PM
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.
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
2006 Oct 05 6:02 PM
If you don't want to have duplicates you can simply
SORT the table
DELETE ADJACENT DUPLICATES FROM ...
2. If you want to just identify
SORT the tabe.
Loop the table
Compare the first row with the next row.
Contiue with this logic.
If match found, that is a duplicate.
ENDLOOP.
Regards,
Ravi
Note : Please mark all the helpful answers
2006 Oct 05 6:08 PM
Yes Ravi, i can go with the program , but to compare two record while in the same loop do we have any specific commmand available.
Regards,
Roby
2006 Oct 05 6:12 PM
There is no specific command other than the IF condition.
1. If you want to compare the entire record you can simply compare the entire work area.
2. If you want to compare specific fields, then you don't have a option other than comparing individual fields with a AND condition.
Regards,
Ravi
Note : Please mark all the helpful answers
2006 Oct 05 6:04 PM
2006 Oct 05 6:20 PM
Hi,
look at the below thread,
http://sap.ittoolbox.com/code/archives.asp?d=2237&a=s&i=10
Regards
Sudheer
2006 Oct 05 6:22 PM
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.