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

Foreign key relationship.....

Former Member
0 Likes
1,080

Hi,

I'm creating a foreign key relation between two table T1 and T2 .

In T1(TABLE) i have fields Mandt,Empno,Empname and DEpno in this table primary keys are Mandt and Empno

In T2(TABLE) i have fields Mandt,Depno and Depname in this table primary keys are Mandt and Depno .

eg. Data in T2 is 800 201 SAP

800 202 Java

i made a foreign table as T1 and check table as T2 . and check field is depno

i can even see in my foreign key table T1 in that TAB Entry help/Check

depno as checked as foreign key and Origin of input help as Input help implemented with check table....

and while i'm entering data in my T1 table i can see f4 help also on Depno fields (201,202)....

very thing sounds good so far.....................

Now if i create a new record in T1 and i gave 309 in depno field it is adding into table...

As i heard it should not take 309 it has to take only (201,202) ....

I request you to help me what is the problem or if i need to do any changes or i heard some thing wrong..

I'm sorry if the information given was not clear....i would appreciate if you can reply me what you need..

Thanks & Have a Nice..

Kiran.

Hi,

I'm creating a foreign key relation between two table T1 and T2 .

In T1(TABLE) i have fields Mandt,Empno,Empname and DEpno in this table primary keys are Mandt and Empno

In T2(TABLE) i have fields Mandt,Depno and Depname in this table primary keys are Mandt and Depno .

eg. Data in T2 is 800 201 SAP

800 202 Java

i made a foreign table as T1 and check table as T2 . and check field is depno

i can even see in my foreign key table T1 in that TAB Entry help/Check

depno as checked as foreign key and Origin of input help as Input help implemented with check table....

and while i'm entering data in my T1 table i can see f4 help also on Depno fields (201,202)....

very thing sounds good so far.....................

Now if i create a new record in T1 and i gave 309 in depno field it is adding into table...

As i heard it should not take 309 it has to take only (201,202) ....

I request you to help me what is the problem or if i need to do any changes or i heard some thing wrong..

I'm sorry if the information given was not clear....i would appreciate if you can reply me what you need..

Thanks & Have a Nice..

Kiran.

6 REPLIES 6
Read only

rejish_balakrishnan
Contributor
0 Likes
885

Hi,

Maintains the Check tables name at the Domain level of the T1 table's Depno field and then Create the relationship.

This will restirct the entries.

[refer|http://help.sap.com/saphelp_nw70/helpdata/EN/63/1b70bcc32111d1950600a0c929b3c3/content.htm]

regards,

RBK

Read only

keerthy_k
Product and Topic Expert
Product and Topic Expert
0 Likes
885

Hi Kiran,

For restricting the entry u need to maintain the value table in the domain of required field , here 'DEPNO'. In the domain, there is a place to give the value range or the value table. In the value table u ave to give the table name as T2 for ur case.

keerthi.

Read only

Former Member
0 Likes
885

Hi,

A relationship which can be defined between tables and must be explicitly defined at field level. Foreign keys are used to ensure the consistency of data. Data entered should be checked against existing data to ensure that there are now contradiction. While defining foreign key relationship cardinality has to be specified. Cardinality mentions how many dependent records or how referenced records are possible.

Referenc with the following links.

http://help.sap.com/saphelp_nw70/helpdata/EN/cf/21ea77446011d189700000e8322d00/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/cf/21ec84446011d189700000e8322d00/content.htm

Regards,

Neelima.

Read only

Former Member
0 Likes
885

hi Kiran

u have 2 tables right T1 & T2.

T1 fields : Mandt,Depno,Empno,Empname.

T2 fields : Mandt,Depno,Depname.

in the T1 table select the Depno field and click on Foreign Keys

u wil get a Create Foreign key screen in that mention the check table : T2

and check fields Mandt & Depno (both shud be mandatory) and in the *screen check tab*

select the check box Check Required, the semantic attributes for foreign key field type select

the radiobutton key fields/candidates and mention the cardinality also then click on copy.

save the table.then check.

Read only

Former Member
0 Likes
885
Read only

Former Member
0 Likes
885

hi Kiran,

Foreign key checks only works in online mode.

If you are forcing the table to accept the Dept No which is not their in foreign key table through SELECT QUERY, system wont perform foreign key check and it will bypass foreign key check and db will get updated .