2013 Jan 01 2:30 PM
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
2013 Jan 01 2:52 PM
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.
2013 Jan 01 3:50 PM
2013 Jan 03 8:24 AM
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.
2013 Jan 03 11:02 AM
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
2013 Jan 01 4:31 PM
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
2013 Jan 01 4:39 PM
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
2013 Jan 03 9:19 AM
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.
2013 Jan 03 10:40 AM
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
2013 Jan 03 10:58 AM
Check the following link. It should address your query.
https://help.sap.com/saphelp_nwpi71/helpdata/en/cf/21ea91446011d189700000e8322d00/content.htm