Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Comparing Duplicates in an internal table

Former Member
0 Likes
1,104

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
974

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

6 REPLIES 6
Read only

Former Member
0 Likes
974

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

Read only

0 Likes
974

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

Read only

0 Likes
974

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

Read only

Former Member
0 Likes
974

Hi Roby,

Please check FM COMPARE_TABLES.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
974

Hi,

look at the below thread,

http://sap.ittoolbox.com/code/archives.asp?d=2237&a=s&i=10

Regards

Sudheer

Read only

Former Member
0 Likes
975

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.