‎2010 Aug 30 1:25 PM
Hello Experts,
I'm trying to INSERT the entry in my custom databse table that i have created. But I'm not sure what i'm missing as i'm getting the sy-subrc = 4 after the INSERT statement and my records are not added to the database table.
I'm using the INSERT as below:-
APPEND gw_relax TO gt_relax.
INSERT INTO zmm_bg_relax VALUES gw_relax.
Please let me know your helpful responses on this,
Thanks,
Naveen
‎2010 Aug 30 1:39 PM
Hello Naveen
sy-subrc = 4 usually means the record already exists in the DB table.
In order to check this you may add the option ...ACCEPTING DUPLICATE KEYS to the INSERT statement.
Regards
Uwe
‎2010 Aug 30 1:39 PM
hi,
please check the primary key values in the db table and the values in the internal table.... if the entries of the primary keys inserted from the internal table already exists then it might not get inserted ...
with regards,
syed
‎2010 Aug 30 1:39 PM
Hello Naveen
sy-subrc = 4 usually means the record already exists in the DB table.
In order to check this you may add the option ...ACCEPTING DUPLICATE KEYS to the INSERT statement.
Regards
Uwe
‎2010 Aug 30 1:51 PM
Hi Uwe,
Now i have modified my statement as INSERT zmm_bg_relax FROM TABLE gt_relax ACCEPTING DUPLICATE KEYS.
But still i'm getting sy-subrc = 4 .
Thanks,
Naveen
‎2010 Aug 30 2:01 PM
Check [INSERT dbtab|http://help.sap.com/abapdocu_70/en/ABAPINSERT_SOURCE.htm] [FROM TABLE itab [ACCEPTING DUPLICATE KEYS]|http://help.sap.com/abapdocu_70/en/ABAPINSERT_SOURCE.htm#&ABAP_ALTERNATIVE_2@2@],
If the addition ACCEPTING DUPLICATE KEYS is specified, all rows are inserted for which this is possible. The remaining rows are rejected and sy-subrc is set to 4. The system field sy-dbcnt is set to the number of lines that are inserted.
So if you get sy-subrc = 4, some of the records of the internal table are already contained in the database table.
You cannot put 2 or more records in a database table with the same primary key, primary keys are unique keys with the addition of a not-null constraint. If you need multiple records with a same key, you must add another key to the primary key. (use a timestamp or a counter)
Regards,
Raymond
‎2010 Aug 30 2:07 PM
If you try to INSERT rows using the same PRIMARY key then a treatable runtime exception CX_SY_OPEN_SQL_DB gets raised if you're not using ACCEPTING DUPLICATE KEYS.
SAP documentation: [http://help.sap.com/abapdocu_70/en/ABAPINSERT_SOURCE.htm#&ABAP_ALTERNATIVE_2@2@]
BR,
Suhas
‎2010 Aug 30 2:01 PM
HI,
try to fill your work area with the new entry you wanted to insert in the Ztable..
snippet code.
DATA : it_tab type standard table of Ztable with header line "mention your ztable name in place of ztable.
It_tab-name = 'ABC'.
it_tab-class='A'.
Insert Ztable from it_tab. " if you want to insert one recoed in to ztable
other wise...
It_tab-name = 'ABC'.
it_tab-class='A'.
append it_tab.
It_tab-name = 'ABC'.
it_tab-class='A'.
append it_tab.
Insert Ztable from table it_tab ' for multiple record..
hope this will help you.
Regards,
Kiran
‎2010 Aug 30 2:02 PM
HI,
try to fill your work area with the new entry you wanted to insert in the Ztable..
snippet code.
DATA : it_tab type standard table of Ztable with header line "mention your ztable name in place of ztable.
It_tab-name = 'ABC'.
it_tab-class='A'.
Insert Ztable from it_tab. " if you want to insert one recoed in to ztable
other wise...
It_tab-name = 'ABC'.
it_tab-class='A'.
append it_tab.
It_tab-name = 'ABC'.
it_tab-class='A'.
append it_tab.
Insert Ztable from table it_tab ' for multiple record..
hope this will help you.
Regards,
Kiran
‎2010 Aug 30 2:24 PM
Hello Naveen,
Use MODIFY statement instead of INSERT. MODIFY will either modify the existing record or create a new record.
Cheers,
Vasanth M