Application Development 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: 

How Can i find out if the internal table has a duplicate entry or not?

Former Member
0 Kudos

Hi All,

i have one internal table which has one field MGEIN.If the value of MGEIN is identical for all the rows only then i have to do some calculation.Please help how doi fins whether all values are identical.

Thanks in Advance,

Saket.

11 REPLIES 11

Former Member
0 Kudos

step 1: sort the table with respect to the field

step 2: check the value in IF....ENDIF. block

Regards,

Anirban

Former Member
0 Kudos

Hi,

Use the command DELETE ADJACENT DUPLICATES FROM itab COMPARING <field name> for delete duplicate entries from internal table.

OR

check the below code...

LOOP AT gt_input[] INTO gx_input.

AT NEW <Fname>.

CLEAR lv_count.

ENDAT.

lv_count = lv_count + 1.

  • At end of each <Fname> check if there are more than one same entry

AT END OF <Fname>.

IF lv_count > 1.

<Do your own process>

ENDIF.

ENDAT.

ENDLOOP.

Rgds,

Bujji

Edited by: Bujji on Aug 5, 2008 2:32 PM

Former Member
0 Kudos

I think you need to use the control break statements AT NEW <FIELD_NAME>...AT END OF <FIELD_NAME>.

Former Member
0 Kudos

I think you need to use the control break statements AT NEW <FIELD_NAME>...AT END OF <FIELD_NAME>.

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Saket,

Quite simple SORT the internal table by MGEIN & then DELETE ADJACENT DUPLICATES from the table.

This will delete the duplicate entries. This way you can know if any duplicate entries exist. Can you tell me what operation you want to perform, that way i can suggest a better soln.

BR,

Suhas

naveen_inuganti2
Active Contributor
0 Kudos

Hi....

Declare var1, var2, flag, loop variables.... and..

>Loop at itab.

>

>if loop is initial.

>var1 = itab-mgein.

>move var1 to var2.

>loop = 'X'.

>else if itab-mgein ne var2.

> flag = 'X'.

>else.

>flag = space.

>endif.

>

>endloop.

Now in the process of the doing sum...

Check flag = space or not.

If flag = space then only proceed...

Thanks,

Naveen.I

former_member181995
Active Contributor
0 Kudos

Saket,

you can copy your internal table into some other temp internal table.than in temp internal table you can check like this:

sort temp by MGEIN.
delete adjecent duplicates from temp comparing MGEIN.
if sy-subrc = 0.
"means duplicate entry found.
else.
"do calculation here with your orignal internal table.
endif.

Former Member
0 Kudos

hiii

you can use following code for comparing field values..for this you need to have same values in another internal tabel

sort it_prd by a.
sort it_chs by a.
LOOP AT it_prd.

  READ TABLE it_chs WITH KEY
                             a = it_prd-a
                             b = it_prd-b.

    w_tmp2 = it_chs-a.
    w_tmp3 = it_chs-b.

    if w_tmp = w_tmp2 and w_tmp1 = w_tmp3.
     if sy-subrc EQ 0.
    APPEND it_prd TO it_s.

  ENDIF.
  w_tmp = it_prd-a.
  w_tmp1 = it_prd-b.
  ENDLOOP.

i hope it helps you

regards

twinkal

Former Member
0 Kudos

First SORT internal table by MGEIN.

Then use AT-NEW command and add up the values you want.

or you can

read the first entry in a variable and the subsequent entry in another variable

Compare them as

IF var1 = var2

add up the values

ENDIF.

Hope this helps

Former Member
0 Kudos

Hi,

First declare another internal table with same structure and transfer all the data into newly declared table. Now take this newly declared table perform remove adjacent duplicates.

Then check for sy-dbcnt (total number if records) if the total number of records is greater than one means there exists different MGEIN values. else there exists only one MGEIN then do summation of the required field with your original internal table.

Hope this will help you,

Regards,

Aswini.

Former Member
0 Kudos

Thanks for all help.