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

Reg INSERT statement

Former Member
0 Kudos
248

Hi,

I have entries in internal table gt_zfgl_dm31_EST03. But i Couldn't able to insert these entries in custom table: zfgl_dm31_EST03 . Following insert statement is giving SY-SUBRC 4. Please advise how can i insert table entries from Internal table to Custom table.

INSERT zfgl_dm01_EST03 FROM TABLE gt_zfgl_dm31_EST03 ACCEPTING DUPLICATE KEYS.

Cheers

Srikanth

1 ACCEPTED SOLUTION
Read only

Former Member
0 Kudos
203

Hi,

If you get sy-subrc = 4, some of the records of the internal table are already contained in the database table.

If you need multiple records with a same key, you must add another key to the primary key. For this use timestamp.

7 REPLIES 7
Read only

Former Member
0 Kudos
203

Hi Sreekanth,

Please check if the structure of the internal table and database table are the same . This may sometime be the problem .

Hope this is helpful.

Cheers,

Vivek.

Read only

Former Member
0 Kudos
204

Hi,

If you get sy-subrc = 4, some of the records of the internal table are already contained in the database table.

If you need multiple records with a same key, you must add another key to the primary key. For this use timestamp.

Read only

madhu_vadlamani
Active Contributor
0 Kudos
203

Hi Kanth,

Need more clarity. As i understood you want to insert records in your custom table. Create work area and insert from that.

ex Insert ztab from wa. Are you inserting on record at at a time or bulk of records.Please post if this is not solved.

Regards,

Madhu.

Read only

Former Member
0 Kudos
203

Hi Srikanth,

Ideally, we cannot insert entries with duplicate keys inside a database table. So it is better that you sort the internal table and delete all the duplicate entries from the internal table before inserting the entries inside the database table.

You can try something like this .


sort gt_zfgl_dm31_EST03.
delete adjacent duplicates from gt_zfgl_dm31_EST03 comparing "key field"
modify zfgl_dm01_EST03 from gt_zfgl_dm31_EST03
 
The reason to use modify is that, it will do the work of insert and update.

Hope this is helpful.

Cheers,

Vivek.

Read only

sridhar_meesala
Active Contributor
0 Kudos
203

Hi,

It is as simple as INSERT cannot add duplicate entries into the table. The use of the addition with duplicate keys helps in not taking the INSERT to dump when there are duplicate values and it returns sy-subrc = 4.

Thanks,

Sri.

Edited by: Sri on Mar 18, 2011 10:05 AM

Read only

0 Kudos
203

Problem got solved. Thanks

Read only

Former Member
0 Kudos
203

Hi,

Please check whether duplicate entries are there in internal table comparing standard table entries. If you are trying to insert records which is already present in the table, it will give sy-subrc = 4. Check the primary keys for checking the duplicates. I mean the records with same primary key if trying to insert again will result this.