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

ITAB

0 Likes
795

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
777

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

5 REPLIES 5
Read only

Former Member
0 Likes
777

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.

Read only

Former Member
0 Likes
777

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.

Read only

Former Member
0 Likes
777

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.

Read only

Former Member
0 Likes
778

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

Read only

Former Member
0 Likes
777

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