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

problem in cardinality

Former Member
0 Likes
1,541

Hi Abap ers,

   i create 2 custom tables zchk and zfor.. zchk is check table and zfor is foreign key table. zchk has 2 fields like mandt(keyfield) and matnr(keyfield).  zfor has 4 fields mandt(keyfield), matnr,(keyfield) werks(keyfield) and mtart.  i create a foreign key relationship between matnr (zchk) and matnr(zfor) from table zfor.

i provide my screen details.

in cardinality i have kept 1: C relationship. this means each record for check table there exist at most 1 record in foreign key table......but when i insert record in zfor table it allows me to insert more than one record....

Example: zchk has one record 

mandt   matnr

130    100

when i insert 100(matnr) in zfor it allows me many time.....but my cardinality 1:C ......

whats the reason???? have i any wrong concept about cardinality??? plzzz explain and solve this problem.......

Thanks and regards

Sabyasachi

9 REPLIES 9
Read only

former_member189905
Participant
0 Likes
1,334

Hi,  your foreignkey can not in same time 1 composant of your keyfields of the second table.  Check in database documentation for the primary key and foreign key contraints.  I hope that it will help you.  Regards.

Read only

0 Likes
1,334

Hi Khalid,

   its not clear to me.......

Regards

Sabyasachi

Read only

0 Likes
1,334

Hi Sabyasachi, 

matnr is the primary key of the table zchk and too 1 composant of the primary key zfor.

Your foreign key must to be 1 field of the table zfor without composant  of it primary key. 

The foreign key is done to check the data to fill in the table.

If your field is composant of the primary key the control of  the data is useless.

The foreign key is not to check the creation of the table records.

Regards.

Read only

0 Likes
1,334

Hi khalid,

              ri8 now zchk(check table) has 2 fields mandt and matnr. both are key fields. in case of zfor(foreign table) has 3 fields mandt matnr and mtart. here mandt and mtart are only key fields but not matnr..

foreign key relationship -> zchk-mandt = zfor-mandt and zchk-matnr = zfor-matnr. matnr is foreign key field in zfor.... relationship 1:C.

according to SAP There is at most one dependent record for each record of the check table.

in my check table there is only one record(for eg 1001) present. when i inserting a record 1001  to foreign key table it allows me to insert same record(1001) for many timess...WHY?? ist time when i insert 1001 record it allows me to insert....its okk...(1:C relationship), but next time, when i inserting the same record (1001) it allows me to insert...its should not be possible because 1:C relationship. if i see this case with respect to key relationship then its possible...Eg:

mandt (K)        mtart (K)       matnr          K  = key field

120                  halb              1001            [ just for example]

120                  abcd             1001

but in my case its a foreign key table and a check table present for this foreign key table...

hope you understand my problem...

Regards

Sabyasachi

Read only

Former Member
0 Likes
1,334

hi sabyasachi

here ypu have

n = 1,

There is exactly one record assigned to the check table for each record of the foreign key table.

m = c

There is at most one dependent record for each record of the check table.

you can insert values in zfor table which will be checked into corresponding zchek table based on the cardinality.

regards

vaibhav

Read only

0 Likes
1,334

Hi vaibhav,

        here m = c.

  so i can insert maxm 1 record in zfor.....but here i can insert same recods for many time.....

Regards

Sabyasachi

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
1,334

How are you inserting the records? If you are inserting the records using a program, then the cardinality specified in foreign key relationships is not respected. Cardinality is respected when you use the SAP GUI (for e.g using a table maintenance dialog) to create data entries in the table.

Read only

Former Member
0 Likes
1,334

Hi kumar,

          i am inserting the records through utilities->table content-> create entries.... here relationship is 1: C. in my check table there is only one record(for eg 1001) present. when i inserting recods 1001  to foreign key table it allows me to insert same record(1001) for many timess...WHY??  here my relationship is 1:C. according to SAP There is at most one dependent record for each record of the check table.

Regards

Sabyasachi

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
1,334