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

Insert data from internal table to ztable.

Former Member
0 Likes
3,244

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,959

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

14 REPLIES 14
Read only

Former Member
0 Likes
1,959

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

Read only

0 Likes
1,959

Hi Gaurav,

Can you send me the exact syntex for the [ACCEPTING DUPLICATE KEYS].

Thanks,

Satya

Read only

0 Likes
1,959

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

Read only

0 Likes
1,959

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.

Read only

0 Likes
1,959

Hi Sri,

i did as per you but its not working . FYI .. i tried both modify and insert .

Thanks,

Satya

Read only

JackGraus
Active Contributor
0 Likes
1,959

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

Read only

Former Member
0 Likes
1,959

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

Read only

JackGraus
Active Contributor
0 Likes
1,959

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

Read only

Former Member
0 Likes
1,959

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.

Read only

Former Member
0 Likes
1,960

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

Read only

0 Likes
1,959

Hi ,

can you suggest some alternative way to store the data.

Thanks,

Satya

Read only

0 Likes
1,959

Hi Satya,

Can you refer your internal table structure and database table structure ? please write KEY beside the key fields.

Thanks.

Read only

Former Member
0 Likes
1,959

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

Read only

Former Member
0 Likes
1,959

Thanks everyone for your help and time.

-Satya