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

Internal Table

Former Member
0 Likes
551

Hi ,

I have an Internal table which is reading the data from different sources and inserting the data into the database table locally. I ma doing this through INSERT command but if any entry already exists in the database table this command raising a short Dump "Insert Duplicate".

Can anyone tell me the easiest way to check the data or to solve this problem.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
529

hi ,

i think the way is checking sy-subrc ..if that dont work before inserting the rescord do a select query if the sy-subrc ne 0 then u can insert...

select * from table..

if sy-subrc ne 0.

insert into table.

endif

regards,

karthik

6 REPLIES 6
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
529

This is because the primary key duplicate...

the issues can be solved by checking whether the table contains the entries before insertion....

for ex:folow this steps:

check whether the entry exists in table.

if not exits:

insert

commit work.

endif...

****************************************************

insert into table.

if sy-subrc <> 0.

rollback work.

if u nedd print a error message here....

else.

commitwork.

endif.

any way its better to check whether a entry exists in table before insertion

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
529

correct code

This is because the primary key duplicate...

the issues can be solved by checking whether the table contains the entries before insertion....

for ex:follow this steps:

insert into table

if sy-subrc = 0.

commit work.

else.

rollback work.

if u nedd print a error message here....

endif.

endif...

any way its better to check whether the same entry exists in table before and the steps above

Read only

Former Member
0 Likes
529

Hi,

You can use UPDATE dbtab or MODIFY dbtab commands instead of Insert command as insert command can insert a wrong value into the database table (it is going to just insert a record which you specify). So, go for either UPDATE or MODIFY commands.

Modify command and Update commands will make changes in already existing record.If it could not find that perticular record, it just inserts it.

Read only

Former Member
0 Likes
530

hi ,

i think the way is checking sy-subrc ..if that dont work before inserting the rescord do a select query if the sy-subrc ne 0 then u can insert...

select * from table..

if sy-subrc ne 0.

insert into table.

endif

regards,

karthik

Read only

Former Member
0 Likes
529

Hi,

The problem occured due to duplicate insertion of primary key. Check whether record already exist or not in the database table.

Ex:

Select * from dbtb where key = itab-key.

If sy-subrc <> 0.

Insert internal table data.

if sy-subrc =0.

commit work.

endif.

endif.

Otherwise you can check for the sy-subrc value after insertion.

INSERT .....into dbtable

if sy-subrc <> 0.

Message

else.

COMMIT WORK.

endif.

Read only

Former Member
0 Likes
529

Hi Moni,

Before inserting ITAB into table check duplicate entries in iternal table and INSERT.

Loop at ITAB.

SELECT <flds> FROM <table> where field=<itab-fld>.

if sy-subrc = 4.

INSERT <into ur table>

endif.

ENDLOOP.