‎2009 Nov 18 3:43 AM
Hello Expert,
I have a ztable with a primary key, now i want to pass my data from the internal table to the ztable . I am using modify option to
pass the data to the ztable but the problem is if the primary key value is same then its update the first record rather add one row in the zrable .But i want to push all the data what are available in the internal table though all the data are same. I even tried with Insert statement but its seems it doesnot work.
Can you please advice me the right approach.
Thanks.
Satya
‎2009 Nov 18 4:53 AM
Hi Satya,
This is not possible to insert into database with same key by INSERT statement that you have used.
If your internal table have multiple records and there is a probabilty to have same key value in some record with the comparison of database table , then if you are not using ACCEPTING DUPLICATE KEYS then the whole itab record will be discarded and raise a error which cannot be handled by system and lead a SHORT DUMP , and if you specify ACCEPTING DUPLICATE KEYS then only those record will be discarded for which there is a previous entry in database table and other records will be inserted properly.
Here ACCEPTING DUPLICATE KEY does not serve your purpose.
Hope this information will help you.
Thanks.
Edited by: CONTACTSANKU on Nov 18, 2009 10:26 AM
‎2009 Nov 18 3:53 AM
Hi Satya
I would suggest you to make use of ACCEPTING DUPLICATE KEYS addition wit the INSERT command. This can solve your problem.
Regards
Gaurav
‎2009 Nov 18 4:08 AM
Hi Gaurav,
Can you send me the exact syntex for the [ACCEPTING DUPLICATE KEYS].
Thanks,
Satya
‎2009 Nov 18 4:25 AM
Hi Gaurav,
I tried this INSERT zcm_XX_posupdet from TABLE zcm_XX_posupdet_itab ACCEPTING DUPLICATE KEYS. But not even inserting the data in the table.
Please advice.
Thanks,
Satya
‎2009 Nov 18 4:35 AM
Hi,
Do you want your table to accept all the records from internal table even though it has duplicate records?
If that is what you want, then remove the primary key for the field in database table and keep it only for the mandt field.
Thanks,
Sri.
‎2009 Nov 18 4:43 AM
Hi Sri,
i did as per you but its not working . FYI .. i tried both modify and insert .
Thanks,
Satya
‎2009 Nov 18 3:54 AM
Hi Satya, that is the characteristic of a key field, the key fields identify a record in a table and only one record can be identified by a set of key fields. If you need all yout internal table data to be stored in a database table then you could expand the number of key fields of your database table, eventually all your table fields could be key fields.
Regards Jack
‎2009 Nov 18 3:59 AM
Thanks Jack for your quick replay,
But here my all data are same in the internal table.Can it be possible to remove the key field and put teh MANDT field as key, does it work with Insert or any other statement.
Thanks,
Satya
‎2009 Nov 18 4:09 AM
Removing the key field will not work, then MANDT will be you key field and that will allow you to have just one record per client. Better add more key field to your table.
There are no insert or any other statements that will allow you to add duplicate fields into the datbase
Regards jack
‎2009 Nov 18 3:56 AM
You must change Ztable, add one or more primary key to distinguish records.
If not application data can be designed, maybe execute date / time / user name etc can be use.
‎2009 Nov 18 4:53 AM
Hi Satya,
This is not possible to insert into database with same key by INSERT statement that you have used.
If your internal table have multiple records and there is a probabilty to have same key value in some record with the comparison of database table , then if you are not using ACCEPTING DUPLICATE KEYS then the whole itab record will be discarded and raise a error which cannot be handled by system and lead a SHORT DUMP , and if you specify ACCEPTING DUPLICATE KEYS then only those record will be discarded for which there is a previous entry in database table and other records will be inserted properly.
Here ACCEPTING DUPLICATE KEY does not serve your purpose.
Hope this information will help you.
Thanks.
Edited by: CONTACTSANKU on Nov 18, 2009 10:26 AM
‎2009 Nov 18 5:03 AM
Hi ,
can you suggest some alternative way to store the data.
Thanks,
Satya
‎2009 Nov 18 5:21 AM
Hi Satya,
Can you refer your internal table structure and database table structure ? please write KEY beside the key fields.
Thanks.
‎2009 Nov 18 5:43 AM
Hi,
It is all about the primary key fields of the database table.
Example:
You have a db table with following fields
MANDT (primary key field)
BUKRS (primary key field)
BELNR (primary key field)
GJAHR
VBELN
and it with same fields.
MANDT BUKRS BELNR GJAHR VBELN
120 0010 160000 2008 450000
120 0010 160000 2007 450003
120 0020 160000 2008 450000
200 0010 160001 2008 450001
200 0010 160001 2007 450001
If you use INSERT statement, only 3 of these will be inserted into the database table, why?
Because: Each database table must include one or a very small group of key fields that uniquely identify each table line by its value. These fields are known as the primary keys of the table.
And as lines 1 and 2 / 4 and 5 have the same MANDT BUKRS and BELNR only one will be inserted into the table.
If the database table is your own one, you will need to modify it so that it would work.
Thankyou.
Regards,
Dhanalakshmi L
‎2009 Dec 03 6:47 AM