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

Dump when inserting into a specific table ?

Former Member
0 Likes
2,415

Hi gurus,

I've created a specific table just like:

Field Key

MANDT X

F1

F2

F3

........................

This table contains only one key field is MANDT , then I try to insert using command:

INSERT zbc00 FROM TABLE wt_zbc00 ACCEPTING DUPLICATE KEYS.

The internal table contain 1 entry .

But then I try to insert 1 more record , It gave me an error ( Sy-subrc = 4 ) , this means that an error has occured .

if I do not use 'ACCEPTING DUPLICATE KEYS' Then It gave a dump .

Could you please help me

Thanks

1 ACCEPTED SOLUTION
Read only

former_member189059
Active Contributor
0 Likes
1,617

Since MANDT is your only primary key, the first entry you created fills MANDT with your current client

any subsequent entry would have the same client and hence create a duplicate key

Hence the error

8 REPLIES 8
Read only

former_member189059
Active Contributor
0 Likes
1,618

Since MANDT is your only primary key, the first entry you created fills MANDT with your current client

any subsequent entry would have the same client and hence create a duplicate key

Hence the error

Read only

rahul_kamble2
Participant
0 Likes
1,617

Hi,

Since your table has 1 key field as mandt.

so as per key field it will allow only 1 record per client unless u use accepting duplicate keys.

Regards,

Rahul

Read only

0 Likes
1,617

Thanks for your help

I've tried to use 'Accept duplicate entry' but I can not insert into the this table ( sy-subrc = 4 )..

How can I do to make it run ?

Thanks.

Read only

Former Member
0 Likes
1,617

hi,

........ACCEPTING DUPLICATE KEYS.

this option is used in order avoid dumps in the program when unknowingly the user tries to enter duplicate records....

Say if the record which u r trying to insert already exists in the DB , then it will not give u dump and instead will return sy-subrc as 4 to show u that the record was not inserted and user shd check the values which he s trying to insert.(i.e either the record exists thats y in was not inserted or some other inconsistency)

please reward points if useful .....

Read only

Former Member
0 Likes
1,617

MANDT is needed in your Z..... table?

I mean it is needed but give another key of the field so that it will work.

REgards,

Madan.

Edited by: madan mohan reddy on May 8, 2008 12:14 PM

Edited by: madan mohan reddy on May 8, 2008 12:15 PM

Read only

0 Likes
1,617

yes , But here I want to insert the duplicate entry too , So is there any way to do this ?

thanks

Read only

0 Likes
1,617

You can do one of the following things

1. remove the mandt field from the db

2. declare one or more of the f1, f2, f3 fields as part of your primary key

3. create another field in the db table such as counter, make it part of the primary key and use it as a count entering different numbers every time

Read only

former_member189059
Active Contributor
0 Likes
1,617

If you specify an internal table itab, several rows are created from
 its content for insertion in the database table. A row for insertion 
into the table is taken from each row of the internal table according 
to the same rules as for a single work area Einfügenwa. The line 
type of the internal table has to meet the prerequisites for use in 
Open-SQL statements. 

If a row witht he same primary key or a same unique secondary 
index does not already exist in the database table for any of the 
rows to be inserted, all rows are inserted and sy-subrc is set to 0. 
If the internal table is empty, sy-subrc is also set to 0. The system
 field sy-dbcnt is always set to the number of rows that were 
actually inserted. 

If a row with the same primary key or a same unique secondary 
index already exists in the database table for one or more of the 
rows to be inserted, these rows cannot be inserted. In this situation,
 there are three possibilities: 

Use of ACCEPTING DUPLICATE KEYS 

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. 


Handling an exception 

If the addition ACCEPTING DUPLICATE KEYS is not specified, a 
treatable exception occurs CX_SY_OPEN_SQL_DB (it always 
occurs since Release 6.10). Rows are inserted until the exception
 occurs. The number of rows that are inserted is not defined. The 
system fields sy-subrc and sy-dbcnt retain their previous value. 

I got this from F1 help

what it means is that.. lets say

1. You have 5 entries in your internal table to be entered in the db

2. The 4th entry is a duplicate entry (already exists in the db)

using 'ACCEPTING DUPLICATE KEYS' will insert records 1, 2, 3 and 5 into the db

without using it, only records 1, 2 and 3 will be inserted