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: 

Foreign key relation issue

Former Member
0 Kudos

Dear Experts,


I have created foreign key relationship already using foreign key button then if i try to create an entry in my foreign key table with field 'food' that is not there in the check table. It is acepting the entries which is not having in my check table entries.I need the error message like this 'Entry does not exist in check table - Check your entry'.

I tried not working. Please explain me clearly. How to do this.



Thanks and regards

Samir


8 REPLIES 8

D_Chia
Active Participant
0 Kudos

are you attempting to insert the entry using a screen/dialog or purely using SQL in ABAP program?

Former Member
0 Kudos

You need to check 2 things.

1. Is the new entry created using a program or thru the screen just as specified on the previous reply.

2. You need to check the cardinality relationship between your check table and FK table.

Thanks,

Vikram.M

0 Kudos

The cardinality field of the foreign key is just for information (as said in the field help).

0 Kudos

Sandra,

I have not tried this yet, but if the cardinality is defined as N:M and N has a value of 'C', then doesn't the system allow to create entries in FK table even if the check table does not have an entry?

Thanks,

Vikram.M

0 Kudos

Hi

You should consider every table exists in two different level:

- Dictionary

- Database

The foreign key is an attribute at dictionary level, as Sandra Rossi has already explained, it can be used to have an automatic validation in the SAP screen (selection-screen or dynpro): in this case the system will do the validation for you automatically

But the sql commands (like INSERT) don't use it, no validation will be done except uniqueness of the record

0 Kudos

Sandra/Max,

Thanks. I thought that the cardinality will impact the FK. I just ran a test and it does not affect the same. The error message was raised ir respective of the cardinality.

Vikram.M

Former Member
0 Kudos

Hi

You need you validate the data by yourself before inserting them

The foreign key doesn't work at database level, so the INSERT statament will insert a record though the forign key is not respected.

Max

0 Kudos

Or, if it's about a field in a dynpro, the validation is automatic if the dynpro field name is tablename-fieldname and the checkbox "field attached to the DDIC" is ticked (and of course, the foreign key must have checkbox "error if value doesn't exist" ticked).