2013 Jul 06 7:19 PM
HI experts,
I've created a Z table for which I'm trying to fill up the entries by using a FM.
now the problem is that first record is inserted but later on sy-subrc gives value 4 and no data is inserted.
syntax which I tried .
INSERT ZNWT_INV_ERRLIS1 from table lt_inv_errlist ACCEPTING DUPLICATE KEYS.
insert ZNWT_INV_ERRLIS1 into lwa_INV_ERRLIST values .
I need you help
Thanks in advance.
Regards Suhas.
HI experts,
I've created a Z table for which I'm trying to fill up the entries by using a FM.
now the problem is that first record is inserted but later on sy-subrc gives value 4 and no data is inserted.
syntax which I tried .
INSERT ZNWT_INV_ERRLIS1 from table lt_inv_errlist ACCEPTING DUPLICATE KEYS.
insert ZNWT_INV_ERRLIS1 into lwa_INV_ERRLIST values .
I need you help
Thanks in advance.
Regards Suhas.
2013 Jul 07 9:21 AM
Hi Suhas,
Subrc 4 is returned because you are inserting a record with the same key as the record inserted before.
syntax for db insertion is
INSERT INTO db_tab VALUES wa.
2013 Jul 07 10:39 AM
Hi Suhas,
This is what SAP documentation says about your issue -
" If one or more lines cannot be inserted because the database already contains a line with the same primary key, a runtime error occurs. You can prevent the runtime error occurring by using the addition ACCEPTING DUPLICATE KEYS. In this case, the lines that would otherwise cause runtime errors are discarded, and SY-SUBRC is set to 4."
Source- http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm
BR.
2013 Jul 08 7:44 AM
Hi,
Through my previous post what i wanted to convey is that you cannot in any situation insert duplicate keys in Database table but using the ACCEPTING DUPLICATE KEYS clause you can prevent the short dump decently since processor sets sy-subrc to 4 if such syntax is used.
BR.
2013 Jul 08 5:29 AM
There may be two cases where you the insertion can be failed.
Case 1:
A record may already exists in the data base with the same key of the record that you are trying to insert.
To know which record insertion is the problem:
SM13
Give required inputs and Execute.
You will see your update error.
Double click on it and there you can see a red colored row.
Select it and Ctrl+Shft.+F6 to see the tables data which resulted in the update termination.
Case 2 :
The record which you are trying to insert may contain inconsistent data as keys.
2013 Jul 08 5:51 AM
Hi suhas,
The sy-subrc = 4 becoz of the primary key combinations.you cannot insert duplicates entries.
'ACCEPTING DUPLICATE KEYS' is used for avoiding the runtime error only.
using sy-dbcnt you can get the number of records inserted.
Cheers
Priya.
2013 Jul 08 6:03 AM
Hi Suhas,
You are trying to insert the record with the same key values, so you are getting sy-subrc value 4 and not able to insert the values into database table. Change the key values and try inserting to database it will insert successfully.
2013 Jul 08 6:28 AM
Hey,
the correct syntax to insert data into table is:
INSERT { {INTO target VALUES source }
You are trying to insert duplicate record with same value of primary key, which is not possible to insert as the database already has the same record. Change the primary key value and then try to insert.
hope it helps!
2013 Jul 08 6:40 AM
Hi,
make sure to have cleared the internal table lt_inv_errlist bewtween to INSERTs with REFRESH (or CLEAR, if it has no header line).
You can sort the internal table and remove duplicates with DELETE ADJACENT DUPLICATES to avoid duplicates during one INSERT of several entries. Refer to the key fields of your Z-table.
Use MODIFY instead of INSERT, if you can't avoid duplicates because of data selection reasons.
Regards,
Klaus
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |