‎2006 Feb 23 9:58 AM
Hi Guys,
I have an internal table with two colums A and B. The table has records like:
A B
11 ii
11 iii
22 oo
44 kk
22 bb
I wants to know the A's which are repeated (like 11 and 22). How can I do this through code.
‎2006 Feb 23 10:07 AM
hi saurabh,
sort itab by a.
data : count type i.
loop at itab.
count = count + 1.
at new a.
if count gt 1.
write : / itab-a ,' is repeated', count ,'times'.
endif.
clear count.
endat.
endloop.
regards
satesh
‎2006 Feb 23 10:03 AM
Sort itab.
DELETE ADJACENT DUPLICATES COMPARING field name A.
SO u wont get repeated records, this can be done if u want to delete the records that are repeated.
OR. Sort itab.
Loop at itab.
store the value of A in a variable then in the next loop compare the previous A value with the new value that has come. If so then u imcrement the counter. or do so what ur req is.
Endloop.
‎2006 Feb 23 10:04 AM
Hi saurabh,
1. use this logic (just copy paste in new program)
2. it will write :
11
22
3.
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
a(5) TYPE c,
b(5) TYPE c,
END OF itab.
*----
Data
itab-a = '11'.
itab-b = 'ii'.
APPEND itab.
itab-a = '11'.
itab-b = 'iii'.
APPEND itab.
itab-a = '22'.
itab-b = 'oo'.
APPEND itab.
itab-a = '44'.
itab-b = 'kk'.
APPEND itab.
itab-a = '22'.
itab-b = 'bb'.
APPEND itab.
*----
Logic
DATA : olda(5) TYPE c.
DATA : flag TYPE c.
*----
Sort - Important
SORT itab BY a.
*----
Loop and check
LOOP AT itab.
IF olda = itab-a AND flag = ''.
WRITE 😕 itab-a.
flag = 'X'.
ELSE.
olda = itab-a.
flag = ''.
ENDIF.
ENDLOOP.
regards,
amit m.
‎2006 Feb 23 10:07 AM
DATA cnt TYPE i.
DATA wa LIKE LINE OF itab.
SORT itab BY A B.
LOOP AT itab into wa.
cnt = 0.
LOOP AT itab WHERE A=wa-A.
cnt =cnt + 1.
ENDLOOP.
IF cnt > 1.
WRITE ' DUPLICATE ', wa-A.
ENDIF.
ENDLOOP.
‎2006 Feb 23 10:07 AM
hi saurabh,
sort itab by a.
data : count type i.
loop at itab.
count = count + 1.
at new a.
if count gt 1.
write : / itab-a ,' is repeated', count ,'times'.
endif.
clear count.
endat.
endloop.
regards
satesh
‎2006 Feb 23 10:09 AM
Hi Saurabh,
data: begin of itab occurs 0,
a type i,
b(2) type c,
end of itab.
data: a type i,
count type i.
....
....
sort itab by a.
count = 1.
loop at itab.
if itab-a = a.
count = count + 1.
else.
write: 'no of ', itab-a, count.
count = 1.
endif.
endloop.Regards
vijay