Skip to Content
author's profile photo Former Member
Former Member

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

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

11 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 05, 2008 at 12:17 PM

    step 1: sort the table with respect to the field

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

    Regards,

    Anirban

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 05, 2008 at 12:20 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 05, 2008 at 12:22 PM

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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 05, 2008 at 12:22 PM

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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 05, 2008 at 12:23 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 05, 2008 at 12:29 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 05, 2008 at 12:38 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 05, 2008 at 12:38 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 05, 2008 at 12:45 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 05, 2008 at 01:07 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.