Application Development 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: 

Updating a database Table

Former Member
0 Kudos

Hi All,

Using a function module, i am updating a z-table.

The Ztable will have the following fields.

employee id

name

date

project id

activity id

hrs spent

remarks

Now i will update the table by giving one employe number and details in function module.

If i want to update the data for SAME employee id, the system is overwriting.

I want the table to get more records on the same employee id.

How to do it?

Regards

Pavan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Pavan,

First check the Key fields. When you use <b>UPDATE</b> keyword, it updates all the non-primary key fields based on the primary key combination.

Suppose you want to update even the duplicate entries, use <b>INSERT</b> keyword with the <b>ACCEPTING DUPLICATE KEYS</b>.

Hope this resolves your query.

Regards

Nagaraj

16 REPLIES 16

former_member404244
Active Contributor
0 Kudos

Hi,

Try like this

UPDATE ZTABLE FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.

Reward if helpful.

Regards,

Nagaraj

amit_khare
Active Contributor
0 Kudos

Do you have one Key field or more than one.

Make atleast 3 key fields.

Former Member
0 Kudos

Hi Pavan,

Check your primary key. If your employee id is the primary key for your table means you can not insert duplicate values.

Thanks.

Former Member
0 Kudos

Hi,

In this case you need to look for some unique keys which are diffrent in case then you use that field to update the table

regards

Shiva

0 Kudos

Hi All,

Thanks for your quick response.

In my table, employee id is a primary key.

I have observed this scenario in CATSDB table. In that table, they have used a field called "counter" to avoid this problem

How to implement the same counter kind of value in my case....????

@ Shiva,

Hi Sir, i am Pavan...your college junior at BEC, bagalkot....

Regards

Pavan

0 Kudos

Hi

how r u?

i was busy with work.

mail me back

regards

Former Member
0 Kudos

Hi Pavan,

First check the Key fields. When you use <b>UPDATE</b> keyword, it updates all the non-primary key fields based on the primary key combination.

Suppose you want to update even the duplicate entries, use <b>INSERT</b> keyword with the <b>ACCEPTING DUPLICATE KEYS</b>.

Hope this resolves your query.

Regards

Nagaraj

0 Kudos

I am using the code as follows.

1. insert <Ztable> from <WA> accepting duplicate keys.

Error: after <WA>, period is missing.

2. insert <ztable> accepting duplicate keys.

Error: accepting is not a correct word. neither a abap statement nor a standard symbol...!!!

can you help me to some more extent?

Pavan

0 Kudos

Hi Pavan,

Use the following syntax :

<b>INSERT <Z-TABLE> FROM TABLE ITAB ACCEPTING DUPLICATE KEYS</b>.

Hope this resolves your query.

Regards

Nagaraj

0 Kudos

Nagaraj,

I have created an internal table same as the ztable.

now the values are dumped in internal table.

used the stament mentioned by you.

ie

INSERT <Z-TABLE> FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.

While debugging, i can see sy-subrc = 4 after execution of this statement.

Kindly help me........

Regards

Pavan

0 Kudos

Hi Pavan,

The previous syntax was litting misleading.

Use the following syntax :

<b>INSERT INTO <Z-TABLE> FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.</b>

Hope this resolves your query.

Regards

Nagaraj

0 Kudos

Nagaraj,

The statment provided by you doesn't work.

Any other idea?

Regards

Pavan

0 Kudos

Hi Pavan,

My suggestion is to add a key field containing serial number with type NUMC ,

and at every insertion to the table you should ensure this field is unique,

by select max( this_field ) first and then increment the value ,

only then it is valid to have duplicate employee ID in your database table.

It may be possible to create duplicate primary key,

but it is not the standard , isn't it ?

Rgds,

Tuwuh Sih Winedya

Rgds

Tuwuh Sih Winedya

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

If you look at CATSDB table, they have made counter as primary key and kept Pernr as non-key field.

Like that you maintain one more field similar to counter.

0 Kudos

Jayanti,

I have gone thorugh the CATSDB Table.

How to make counter kind of field in my ztable?

I believe something needs to be done after defining "counter" filed in the table.

Can anyone guide me....????

Regards

Pavan

Former Member
0 Kudos

Thanks...