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

Duplicates in a database table

Former Member
0 Likes
1,691

Hi !

I have a database table. It has 4 fields. 3 of them are key.

Table (f1,f2,f3,f4)

f1,f2,f3: key

f4: numeric field.

From a ABAP program, I can insert (using insert sentence) two records with the same key. why ???

Then, if I try ....

select f1 f2 f3 sum(f4)

from table

group by f1 f2 f3

... it doesn´t work. This sentence returns two records. Why ?

(some fields of the key can be nulls)

Thanks.

12 REPLIES 12
Read only

Former Member
0 Likes
1,503

HI...

programatially you can insert an entry in a database table....it doesnot look for any other thing....

and after you are done with insertion or deletion or whatever it may be...it will feel as if the created entry are orignal ones

regards

Read only

Former Member
0 Likes
1,503

hi,

plz tell ur table or paste ur code

Read only

Former Member
0 Likes
1,503

Hi,

When u use groupby statement it will add the similar records and give the result into one record.

check is there any matching records are there...

fro ex:

f1 f2 f3 f4

1 2 3 4

1 2 3 7

1 3 4 10

the output is like this..

f1 f2 f3 f4

1 2 3 11

1 3 4 10

if u perform select query then it will fetch the above two records...

Regards

Kiran

Read only

former_member222860
Active Contributor
0 Likes
1,503

Hi,

From a ABAP program, I can insert (using insert sentence) two records with the same key. why ???

If it column is defined with NOT NULL key, you can insert duplicate records as well.

thanks\

Mahesh

Read only

Former Member
0 Likes
1,503

select f1 f2 f3 sum(f4)

from table

group by f1 f2 f3

The above select statement does the summation for the same values of f1, f2, f3 and returns. say if table contains

a b c 1

a b c 2

a b d 3

output will be :

a b c 3

a b d 3

Technically the above select statement won't make sense, as you said f1, f2, f3 are key fields and table contains unique row for any f1, f2, f3.

this statement is as good as

select f1 f2 f3 f4

from table

Read only

Former Member
0 Likes
1,503

HI OSCAR ,

You can insert duplicate entries in DB table from Program .

Some fields of the key can be nulls .

As far my Knowledge Group By should work .

Thanks

Pinaki

Read only

ThomasZloch
Active Contributor
0 Likes
1,503

>

> From a ABAP program, I can insert (using insert sentence) two records with the same key. why ???

No you cannot, the second INSERT will result in SY-SUBRC = 4.

Thomas

Read only

Former Member
0 Likes
1,503

HI,

From a ABAP program, I can insert (using insert sentence) two records with the same key. why ???

first of all It is not at all possible. There should be atleast one key value different for 2 data-row in database table. It is the fundamental concept of key. Your above statement holds for nonkey vaule or partial key field view/selection only.

for next query,

Instead of

select f1 f2 f3 sum(f4)
from table
group by f1 f2 f3........

use

select distinct f1 f2 f3 sum(f4)
from table
group by f1 f2 f3............

Regards,

Anirban

Read only

Former Member
0 Likes
1,503

for the same set of primary keys, u can not insert a value twice.

even if u try to modify the table with adifferent value for the same set of primary keys,it will overwrite the previous value.

Edited by: Kalyan Chakravarthi on Feb 16, 2009 11:33 AM

Read only

Former Member
0 Likes
1,503

hi,

well when try creating your table as a sorted table and handle the error. that will not allow you to enter duplicate vales.

the reason u can enter duplicate values is because you have declared your table as a standard table and programatically u can do whatever you like with your standard table..

Read only

Former Member
0 Likes
1,503

hi,

well when try creating your table as a sorted table and handle the error. that will not allow you to enter duplicate vales.

the reason u can enter duplicate values is because you have declared your table as a standard table and programatically u can do whatever you like with your standard table..

Read only

Former Member
0 Likes
1,503

Hi,

First of all u canot insert two ecirds with the same key.

i u insert then with this key the value of 4th field will change but not a new record with same key.

so, first see this,

Regards