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

compare records within single internal table

Former Member
0 Likes
763

Can we compare records within single internal table.how to do it.

Can we compare records within single internal table.how to do it.

4 REPLIES 4
Read only

Former Member
0 Likes
682

loop at it into wa. "read same itenal table

read table itab from wa with key wa-field wa-field.

endloop.

Read only

Former Member
0 Likes
682

Do you want to compare the same field or different fields from the internal table.?

Regards,

Atish

Read only

Former Member
0 Likes
682
data : l_lines type sy-tabix.
describe table itab lines l_lines.
loop at itab into watab.
l_tabix = sy-tabix + 1.
loop at itab into wtemp from l_tabix to l_lines where matnr = watab-matnr.
write :/ 'duplicate record exists'.
endloop.
clear : l_tabix,
          watab,
          wtemp.
endloop.
Read only

Former Member
0 Likes
682

Hi Suganya,

Yes, we can compare records within single internal table.

ex:

Case1: Want to compare only the key fields.

i_tab is the internal table without work area.

w_tab is the external work area for the table i_tab.

w2_tab is the second external work area for the table i_tab.

loop at i_tab into w_tab.

loop at i_tab into w2_tab where field1 = w_tab-field and

field2 = w_tab-field.

  • If the control enter the second loop, the duplicate record exits.

endloop.

endloop.

If u want to count the number of duplicate records exist in the single internal record, then set a counter.

ex : i_tab is the internal table without work area.

w_tab is the external work area for the table i_tab.

w2_tab is the second external work area for the table i_tab.

  • Declare the structure to count the dup records in the same internal table

types : begin of s_dup_cnt ,

record type i,

count type i.

end of s_dup_cnt.

  • Declare the internal table & work area

data : t_dup_cnt type standard table of s_dup_cnt.

w_dup_cnt type s_dup_cnt.

loop at i_tab into w_tab.

  • get the record number

w_dup_cnt-record = SY-TABIX.

w_dup_cnt-count = 0.

loop at i_tab into w2_tab where field1 = w_tab-field and

field2 = w_tab-field.

w_dup_cnt-count = w_dup_cnt-count + 1.

endloop.

append w_dup_cnt to t_dup_cnt.

clear w_dup_cnt.

endloop.

loop at t_dup_cnt into w_dup_cnt.

write w_dup_cnt-record .

write w_dup_cnt-count.

endloop.

  • t_dup_cnt now contains the record number & the number of times the record repeated * in the same internal table,