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 issue

Former Member
0 Kudos

I previously posted the same but didnt get answer.The problem is that I created a table zforeign with fid and fname as fields.I mapped fid as foreign key with id field of check table zgtable.When I enter data in zforeign,for fid field list shows with corresponding values from check table.I select any one value and save it.Other than selecting,if i enter a value 123(which is not in check table),this record also gets saved.I think it should prevent me saving since 123 record is not found in check table.Can anyone tell me why its happening like that?Iam using 4.7 and check required check box is clicked while creating foreign key.

3 REPLIES 3

Former Member
0 Kudos

Hi,

1) Make confirm ur Chack table is ACTIVATED or not. if not Activated, Activated it.

2) Main table and Check table fields should have same domain. In ur case field <b>fid</b> should hv same domain in table <b>zforeign and zgtable</b>.

regards,

Paras

Message was edited by:

Paras

Former Member
0 Kudos

Hi Gopi,

Make sure that you have switched on 'Check required' when defining the foreign key in the table.

Regards,

John.

Former Member
0 Kudos

hI

SEE THIS ONE

Check table name of the foreign key

Check table

Table whose key fields are used to check the foreign key fields (see Foreign Keys). Only entries that are contained in the key fields of the check table can be contained in the foreign key fields.

The check table is used to check whether the input values are valid and for the input help (F4 help).

The field in the foreign key table, which is assigned to the primary key field in the check table.

A foreign key creates a link between two tables T1 and T2. Every primary key field from T2 (check table) is assigned a field from table T1 (foreign key field). The fields from T1 assigned to primary key fields are marked as foreign key fields.

The most important function of the foreign key is the support of data integrity. The foreign key fields can only accept values which appear in the primary key of the check table. During input the values of the foreign key fields can thus be checked against the entries of the assigned key fields of the check table.

In the ABAP Dictionary, such relationships between two tables are called foreign keys and they must be defined explicitly for the fields.

Foreign keys are used to ensure that the data is consistent. Data that has been entered is checked against existing data to ensure that it is consistent.

Foreign Key concept with an Example

Example: In this example, the foreign key table is table SBOOK. The purpose of the foreign key is to ensure that only valid counters of carriers can be assigned to a booking. Check table SCOUNTER contains exactly this information. Each counter is identified with three key fields in this table: MANDT, CARRID, and COUNTNUM.

In order to define the foreign key, these three fields are assigned to fields of the foreign key table (foreign key fields) with which the input to be checked is entered on the screen. In table SBOOK these are the fields: MANDT, CARRID, COUNTER. The entry is accepted if it represents a valid counter; otherwise the system will reject it.

The foreign key is defined for field SBOOK-COUNTER (check field), which means that the entry in this field is checked. Field COUNTER is therefore called the check field for this foreign key.