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

How to find same records from internal table?

Hi Experts,

I have to compare a key field with other three fields. If the values of three fields are same for more then one key field then that should be marked as duplicate. means I have to check each field with every record of the table.

Can anybody help me to find?

Thanks a ton in advance...

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Apr 23, 2008 at 04:44 AM

    Hi,

    You can do validations on a field by creating

    foreign key relationship with a check table's field.

    But as per ur requirement, checking a field aganist three fields is not possible.

    Can u be a little bit clear in ur query?

    Regards,

    Jagadish

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 23, 2008 at 04:45 AM

    keep a loop in a loop

    loop at itab into w_itab.

    loop at itab2 into w_itab2 where f1 = w_itab-f1 and

    f2 = w_itab-f2.

    endloop.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 23, 2008 at 04:49 AM

    Moni,

    DATA : previous TYPE lifnr,

    number TYPE C.

    LOOP AT printtab.

    IF printtab-wt_acco NE previous.

    number = ' '.

    ELSE.

    number = 'X'.

    ENDIF.

    previous = printtab-wt_acco.

    printtab-chk = number.

    MODIFY printtab.

    ENDLOOP.

    The above code checks the vendor in the internal table is same as the previous one,if it is same as the previous one it marks that record as X ie we have a field chk in the internal table.Now you will have all the duplicate records marked as X which you can use for further processing.

    K.Kiran.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 23, 2008 at 04:49 AM

    Hi,

    Use AT NEW keyword.

    SORT itab BY keyfield.
    LOOP AT itab.
    
      AT NEW OF itab-keyfield.
        CONTINUE.
      ENDAT.
    
      << Mark the record as duplicate >>
    
    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 23, 2008 at 04:50 AM

    Hi Moni,

    delare another table(itab2) similar to your table(itab1).

    loop at itab2.

    read table itab1 with key f2 = itab2-f2

    f3 = itab2-f3 (condition you have).

    if sy-subrc = 0.

    itab1-dupl = 'X'.

    modify itab1 transporting dupl index sy-tabix.

    endif.

    endloop.

    Regards,

    Vidya Chowdhary A.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 23, 2008 at 04:54 AM

    Hi,

    First do a sort statement like

    sort internal table by field1 descending field2 descending field3 descending..where field1/2/3 are the ones you need to compare

    decalre 3 local fields fiel1/2/3 and clear them.

    loop at internal table to workarea.

    if loc_field1/2/3 is initial.

    loc_field1/2/3 = workaera-field1/2/3.

    else.

    if loc_field1/2/3 = workarea-field1/2/3

    duplicate entries--> write your code here

    else.

    clear locfield1/2/3

    endif.

    endif.

    imagine you have 3 lines

    so what you are doing above by sorting is making sure that the lines with the same field1/2/3 come immediately after another

    so first time we fill the local fields from first line...and comapre with the next line(line2) for duplicate...if it is duplicate dont clear the local values check if again the next one(line3) is a duplicate of the previous one(line2)

    if the second line is not duplicate of the first,update the local fields with one of the currrent line since next we compare if we have common fields in line3 with respect to line2..

    since this is inside a loop this will go on until you have finished checking all the records

    The sort statement is vital otherwise the above code wont work as desired..

    Pls check and revert

    Reward if helpful

    Regards

    Byju

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Byju,

      Can you be little more clear with your code. As I have to insert the same values in another table with the duplicate field as mark and non duplicate without mark.

      Means I have to show all the records but which are duplicate I have to mark it .

      Thanks

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2009 at 10:55 AM

    Solved

    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.