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

Finding Duplicates Records

Former Member
0 Likes
635

Hi All,

I have a scenario i got one internal table itab1 with 3 fields f1,f2,f3 and i am fetching some data from a standard table.Now i want to loop through the table itab1-f1 and see if there is any duplicate entries.How can this be done.I want some logic which is efficient.

Regards,

Ravi

Edited by: ravi r on Mar 3, 2010 7:34 AM

1 ACCEPTED SOLUTION
Read only

GauthamV
Active Contributor
0 Likes
602

If you already have data in itab1 from standard table then check something like this.


Sort itab by f1.
Loop at itab.
Delete adjacent duplicates from itab comparing f1.
endloop.

Hi All,

I have a scenario i got one internal table itab1 with 3 fields f1,f2,f3 and i am fetching some data from a standard table.Now i want to loop through the table itab1-f1 and see if there is any duplicate entries.How can this be done.I want some logic which is efficient.

Regards,

Ravi

Edited by: ravi r on Mar 3, 2010 7:34 AM

4 REPLIES 4
Read only

anup_deshmukh4
Active Contributor
0 Likes
602

Hello ravi r ,

Your can very well use contror break for the itab for itab-f1 and write the logic in same u can use CNT(itab-F1) for counting the duplicates Chek for F1 help...!

AT END.

ENDAT.

in your loop.

or the other way is Sort and Loop ...use binary search ..Use parell Cursor for effeciency...!

Edited by: Anup Deshmukh on Mar 3, 2010 7:43 AM

Read only

GauthamV
Active Contributor
0 Likes
603

If you already have data in itab1 from standard table then check something like this.


Sort itab by f1.
Loop at itab.
Delete adjacent duplicates from itab comparing f1.
endloop.

Read only

0 Likes
602

check example cnt will give you the number of duplicates count


NODES: spfli, sflight. 

FIELD-GROUPS: header, flight_info, flight_date. 

START-OF-SELECTION. 
  INSERT: spfli-carrid spfli-connid sflight-fldate 
            INTO header, 
          spfli-cityfrom spfli-cityto 
            INTO flight_info. 

GET spfli. 
  EXTRACT flight_info. 

GET sflight. 
  EXTRACT flight_date. 

END-OF-SELECTION. 
  SORT STABLE. 
  LOOP. 
    AT FIRST. 
      WRITE / 'Flight list'. 
      ULINE. 
    ENDAT. 
    AT flight_info WITH flight_date. 
      WRITE: / spfli-carrid , spfli-connid, sflight-fldate, 
               spfli-cityfrom, spfli-cityto. 
    ENDAT. 
    AT flight_date. 
      WRITE: / spfli-carrid , spfli-connid, sflight-fldate. 
    ENDAT. 
    AT LAST. 
      ULINE. 
      WRITE: cnt(spfli-carrid), 'Airlines'. 
      ULINE. 
    ENDAT. 
  ENDLOOP. 

Edited by: Anup Deshmukh on Mar 3, 2010 7:46 AM

Read only

Former Member
0 Likes
602

Hi,

Use the following logic.

SORT itab ASCENDING BY f1.

LOOP AT itab.
MOVE SY-INDEX to indx.
indx = indx + 1.
READ itab into wa_temp with index indx.
IF itab-f1 eq wa_temp-f1.
   duplicate.
ELSE.
   process your logic.
ENDIF.
CLEAR indx.
ENDLOOP.

Regards,

Shankar.