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 to find same records from internal table?

Former Member
0 Kudos

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...

8 REPLIES 8

Former Member
0 Kudos

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

former_member156446
Active Contributor
0 Kudos

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.

kiran_k8
Active Contributor
0 Kudos

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.

asik_shameem
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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

Former Member
0 Kudos

Solved