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

Duplicate entries

Former Member
0 Likes
1,590

Hi guys,

In my requirement, i am looping at an internal table and updating the database table for each entry.

But i need to check for duplicate entries i.e if a similar entry is already updated, it should not go ahead.....kindly help me out on how do i go about this.

Thanks and regards,

Frank.

Edited by: frank on Mar 24, 2008 11:34 AM

10 REPLIES 10
Read only

Former Member
0 Likes
1,102

Hi,

You can sort the table and delete adjacent duplicates.

Example:

SORT pa_gt_update_rows BY ebeln ebelp.

  • Retain only unique combination of order number and item

DELETE ADJACENT DUPLICATES FROM pa_gt_update_rows

COMPARING ebeln ebelp.

Now, Loop at the resultant table and update the Database.

Regards,

Farheen

Read only

Former Member
0 Likes
1,102

Hi,

To delete the duplictae entries, Try this

DELETE ADJACENT DUPLICATES FROM <internal table>.

Also check this link,

http://help.sap.com/saphelp_nw04/helpdata/en/06/aafd54fc4011d195280000e8353423/content.htm

Thanks and Best Regards,

Ruthra

Read only

Former Member
0 Likes
1,102

Hi,

Check your internal table whether it has duplicate entries.

To remove the duplicate entries,


DELETE ADJACENT DUPLICATES FROM <it_tbl> COMPARING <field1> <field2>.

Hope this helps. Rwd points if helpful.

Thanks

Balaji

Read only

Former Member
0 Likes
1,102

Hi Frank.

Use the following

Modify databse table from the internal table.

Modify will only change the entries if they are different otherwise it will have the same copy.

Regards,

Rahul

Read only

Former Member
0 Likes
1,102

Hi,

1. First you remove any duplicates from your internal table.

SORT ITAB BY your prinmary key fields.

DELETE ADJACENT DUPLICATES BY COMPARING your primary key fields.

2.Suppose if all ready existing data may have same like internal table record that time.

select single primary key fields into (databasetabel-field1,

databasetabel-field2,.....)

from database table.

IF sy-subrc NE 0.

data not existed

ELSE.

data existed .

CONTINUE.

ENDIF.

Pls. reward if useful....

Read only

Former Member
0 Likes
1,102

Hi,

Before loopin thru the internal table.

Sort the internal table based on the key field and then use the statement....


Delete adjacent duplicates  from itab comparing fld1 fld2.........

where fld1 , fld2 etc are the fields in records which you are updating and you dont want to update them in case there are multiple entries in those fields.

Reward if helpful.

Regards.

Read only

Former Member
0 Likes
1,102

Hi,

May be u r getting the records in the file inorder to insert in the DB table.

Inorder to eliminate the duplicate entries, in if condition u have to compare the keyfields(of record from file) with the keyfields of the DB table(Keep all the key fields of DB table in one internal table).If the Keyfields matches i.e condition is true then that record is already existing.

Read only

Former Member
0 Likes
1,102

Hi,

Above the loop statement you have to sort the internal table by key fields. and delete adjacent duplicates from the internal table comparing the key fields.

With in the loop....endloop you have to update each of database table.

I think your question is that if the record already exists it will not be appended again. if this is the case you have to use modify database table from work area.

Reward.

Read only

Former Member
0 Likes
1,102

HI Frank,

Use these statement in end of ur select statement

DELETE ADJACENT DUPLICATES FROM itab (Which u given in ur program ) COMPARING FIELD NAME.

Sample Coding:

Select ekko~ebeln

ekpo~ebelp

ekko~bedat

ekko~lifnr

ekko~bukrs

ekpo~txz01

into table iekko_ekpo

from ekko

inner join ekpo

on ekkoebeln = ekpoebeln

for all entries in imkpf_mseg

where ekko~ebeln = imkpf_mseg-ebeln.

SORT iekko_ekpo BY ebeln ASCENDING

bedat DESCENDING.

  • DELETE ADJACENT DUPLICATES FROM iekko_ekpo COMPARING ebeln.*

clear iekko_ekpo.

I think it will solve ur problem,kindly give points if it helpful.

By

Pari.

Read only

Former Member
0 Likes
1,102

Before Deleting U have to short the fiels, untill n unless it will not work. Then use DELETE ADJACENT DUPLICATES ...comparing ur shorted fields. Try this it will work!!