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

Insert & Modify statems

Former Member
0 Likes
6,055

Hello,

In my code. I used INSERT stat for updating in DB Tab from Itab. I am getting dump,If i try to update existing recor. Dump is "The ABAP/4 Open SQL array insert results in duplicate database records"

I can avoid the prob by using MODIFY stat. Please correct me if i am wrong.

Thnx.

13 REPLIES 13
Read only

Former Member
0 Likes
2,149

Modify will insert record if it doesnt exist otherwise it will update the non key fields if it exists. But while Using modify statement be careful if u have any field with conversion or any rules follow them carefully otherwise it will treat it as new record and it will insert.

Example: MARA-Matnr = 100.

mara-matnr = 0000000000000100. Both are same only but make sure you will be following the rules.

Edited by: Phanindra Annaparthi on Feb 26, 2009 9:59 AM

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
2,149

Hi,

INSERT statement inserts a new record into the db table i.e., no duplicates (on primary key)

UPDATE statement updates the existing records using the combination of primary keys.

MODIFY statements works as INSERT + MODIFY i.e., if record found based on primary key then update, if not found then insert.

Hope this helps you.

Regards,

Tarun

Read only

GauthamV
Active Contributor
0 Likes
2,149

Yes,you can use modify statement.

It will act such that if you dont have record it will create new one

and modifies the record if already exists.

Read only

Former Member
0 Likes
2,149

check for the primary keys ....they should be different ..from the data existing in the db table.

use modify if u have to chage only one fieldd.....

thanks

Read only

Former Member
0 Likes
2,149

Hi Sandya,

You are trying to insert duplicate records.

You must be having a primary key right?

So check that no 2 such fieds are same.

Use delete adjacent duplicates and then try to insert.

Also If its a sorted table and your entries are not in the sorted form it will give Dump.

Sort it too!!

Much Regards,

Amuktha.

Read only

former_member632729
Contributor
0 Likes
2,149

Hi,

Insert is insert the record in a table ..

modify is used to update the record entry , if the record is not their in table then it acts like an insert only...

Read only

dev_parbutteea
Active Contributor
0 Likes
2,149

Hi,

You can do a select before doing the insert, to check which records already exist. Then pick out those records which are not yet in the table and do your insert. and use modify for the existing records if necessary.

Alternatively you can do a modify.

Regards.

Read only

Former Member
0 Likes
2,149

Hi,

By using the INSERT it will checks with the primary key entries in table if it find the duplicating..and tyring to insert it goes to dump.

so to avoid that dump use the MODIFY statiememt..

this will also check the primary key entry.....if it is there and does not update..but it wont go dump.

using UPDATE you can modify the non-primary key fileds update.

hope this info useful to you.

Regards!

Read only

Former Member
0 Likes
2,149

Hi Sandya,

Use the MODIFY command instead of INSERT statement.

If there is a record exists with the key fields then MODIFY command will overwrite the non key fields and the entry is saved in the database.

Regards,

Phani.

Read only

Former Member
0 Likes
2,149

Whenever you are using INSERT, it checks if the reocrd with same KEY fields exists, If yes , it gives dump.

But in MODIFY, if an record with same KEY found, it just updated that record, if not found, it acts same as INSERT.

Read only

Former Member
0 Likes
2,149

hi sandya

if you use MODIFY u can edit only the existing record.

for ur problem,

the DB table does not allow any duplicates . In your IT table add one more column which uniquely identifies each record .Also send that unique number to ur DB table.

one more way is u can use UPDATE instead of INSERT which does not throw any dump err. if u pass any record which already exists in DB.

hope this solves ur problem .

Read only

0 Likes
2,149

Hi all,

Is there are different between INSERT and MODIFY in performance point .i.e. which one give the better performence if i want to insert record

Thanks

Tarak

Read only

Former Member
0 Likes
2,149

Hi Sandya,

From error message, it is understood that you are trying to add duplicate record. So it is giving error.

If you want to modify any non-key fields, then you can use MODIFY statement.

INSERT - It inserts record as a last record.

MODIFY - If record with key fields exist, then it modifies the non-key fields. If record soes not exist, it adds new record at the end.

Regards,

Anil