‎2008 May 08 7:14 AM
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
‎2008 May 08 7:21 AM
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
‎2008 May 08 7:21 AM
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
‎2008 May 08 7:21 AM
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
‎2008 May 08 7:29 AM
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.
‎2008 May 08 7:38 AM
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 .....
‎2008 May 08 7:43 AM
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
‎2008 May 08 7:53 AM
yes , But here I want to insert the duplicate entry too , So is there any way to do this ?
thanks
‎2008 May 08 7:57 AM
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
‎2008 May 08 7:47 AM
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