‎2013 Mar 27 10:31 AM
Hi everyone,
I'm new to ABAP and need help.
Below line of code inserts data from internal table ITEVEN into data dictionary table ZTEVDC.
-----------------------------------------------------------------------
INSERT ZTEVDC FROM TABLE ITEVEN.
-----------------------------------------------------------------------
However, sometimes there can be data in ITEVEN, that already exist in ZTEVDC with same primary key.
I want the code to save records from ITEVEN into ZTEVDC, however, if record already exist in ZTEVDC(With primary key PDSNR) then it should modify the existing record and not create a duplicate(Which crashes the program). If record does not exist in ZTEVDC, then a new record will be created.
Currently the system crashes if a record with same primary key(PDSNR) already exist in ZTEVDC.
Can anyone please help me?
BR
Turan
‎2013 Mar 27 4:15 PM
Dear Egemen,
Please try this.
Modify ztevdc from table iteven.
commit work.
Hope it helps you.
Thanks & Regards,
Vignesh Yeram
‎2013 Mar 27 4:42 PM
Hi Egemen,
Use MODIFY statement.
For your information.
Modify statement inserts a new records if there is no record exist with the same key combination fields and updates the table if record already exists in database table.
While INSERT statement only inserts a new record and gives short dump in case of duplicate entry.
Regards,
Amit Kumar Singh
‎2013 Mar 27 4:51 PM
Hi,
in this case you can use MODIFY statement.
An example:
* Updates database table Ztable with the contents of wa_itab
MODIFY Ztable FROM wa_itab.
other example
* Updates database table Ztable with the contents of it_itab
MODIFY Ztable FROM TABLE it_itab.
Regards
Ivan
‎2013 Mar 27 8:13 PM
Egemen,
Like stated above the modify statement will work. I just want to also point out if you do want to use insert but avoid duplicate entries, this will work.
insert ztevdc from table iteven accepting duplicate keys.
if sy-subrc <> 0.
"your error message
endif.
This will prevent the run-time error occurring and set sy-subrc to 4 while disregarding the data you tried to insert.
Thanks,
Justin
‎2013 Mar 28 6:18 AM
Hi,
Instead of INSERT statement, use MODIFY statement which is the best option to proceed with in your scenario.
Regards,
Ravi.
‎2013 Mar 28 7:33 AM
Modify statement is the solution for your question...................
‎2013 Mar 28 10:08 AM
‎2013 Mar 28 3:31 PM
Hi Egemen,
In your case use MODIFY instead of INSERT.
basic difference between INSERT, UPDATE & MODIFY --
INSERT: when new record has to inserted into table.
UPDATE: When record in present in table & need to be change.
MODIFY: this combination of both Insert & Update, means if record is not present it will add the record into table otherwise it will update the existing record without inserting again.
For more information check these link.
Regards,
Jyoti