02-18-2012 3:25 PM
First of all to the moderators.. Sorry I know there are couple threads already on this topic but still i am posting a new one because no one has cared to answer those threads & apart from that i needed a much more comprehensive answer. So i request you please dont close this thread.
I know what an adapted foreign key is ,My questions are
1.) What are the prerequisites for defining an adapted foreign key relation ?
2.) What all has to be done to attain a successful input check using adapted foreign key relation?
3.) If you dont mind can you please explain with an example.
I tried googling a lot but there isn't much explanation on adapted foreign keys anywhere.. So please help me out here guyz
I know most of you dont have the time So lets take an example of 3 tables
tables & fields are
MAIN - id, region, country
CHECK1- region, province
CHECK2- state, country
So i am looking to set up an adapted foreign key relation for the field REGION of table MAIN so that both the the fields REGION & COUNTRY will be checked when creating an entry in MAIN
REGION has to be checked against REGION field of table CHECK1
COUNTRY has to be checked agaisnt COUNTRY field of table CHECK2
So how do we attain this, since its different tables we cant use compounded foreign keys
Edited by: Nikhil Chandra on Feb 18, 2012 4:39 PM
Edited by: Nikhil Chandra on Feb 18, 2012 4:47 PM
Edited by: Nikhil Chandra on Feb 18, 2012 4:48 PM
03-10-2012 10:54 AM
Hi,
What i understand of adapted foreign key
Adapted foreign keys: If all the fields of a compound foreign key are not from same table it is called as an adapted foreign key.
You can implement the same following way.
go to se11 select the field and Click on foreign key button. it will propose the check table based on the data element used, if you want different table say no and give your table name.
Note : You can avoid fields for which you do not want the reference to be maintained by selecting key as generic and removing those field from selection.
you can repeat the steps for each field you want a reference key to check the value..moreover you can specify the error message and message class you want to display when integrity fails.
Hope this will help.
Janisar
Edited by: janisar.munshi on Mar 10, 2012 4:26 PM
Edited by: janisar.munshi on Mar 10, 2012 4:27 PM
02-19-2012 8:33 AM
No answer yet ? Is it because no body knows the answer or is it that nobody cares to..
03-01-2012 9:15 AM
there is no per-requisite for this. just the necessity in your project.
just set CHECK1 as the value table in the domain of region and CHECK2 as the value table for country's domain. your problem will be solved.
03-02-2012 6:29 AM
Well i actually did that but that doesn't give the input check. ie when i try to make an entry in MAIN it sure checks for the region but not for the country, i am able to enter any country.
the foreign key relation prposal for MAIN-REGION looks like this
CHECK1-MANDT = MAIN-MANDT
CHECK1-REGION = MAIN-REGION
how do i make it an Adapted foreign key so that there will be another relation like this
CHECK1-MANDT = MAIN-MANDT
CHECK1-REGION = MAIN-REGION
CHECK2-COUNTRY = MAIN-COUNTRY
Or is it actually possible ?
03-02-2012 5:54 AM
Hi,
Please go through the below link.
http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21eb95446011d189700000e8322d00/content.htm
Regards,
Danish.
03-02-2012 6:32 AM
Thanks 4 de help buddy.. but i was actually looking for Adapted foreign key.. its not a normal foreign key relation but a different kind of compunded foreign key relation..
03-02-2012 6:54 AM
Hi,
You will hav to create 2 foreign key relationships on 2 different fields OR what you can do is attach check tables to the domains.
Regards,
Danish.
03-03-2012 7:37 AM
ya but adding the check tables as value table for domain doesnt check the input when i try to make an entry in the main table
03-03-2012 7:27 AM
Hi,
Please look at the data elements of the fields on which You want
to establish forign key relationship.
Those data elements must be same of the fields of those
CHECK1 & CHECK2 table..
Regards,
KP
03-03-2012 7:34 AM
03-03-2012 8:14 AM
MAIN - id, region, country
CHECK1- region, province
CHECK2- state, country
These are your tables....
Here,
for CHECK1 table, Region must be primary key.
&
for CHECK2 table, Country must be primary key.
Then goto MAIN table & establish foreign keys by click on Generate Proposal.
at the time of doing this if any error occur,
then goto SE14 & adjust tables.
Regards,
KP
03-03-2012 9:09 AM
They are already primary keys.
Check this out http://www.sapnet.ru/abap21day/ch04/f4-12.gif
this was an example of similar kind of assignment in some website
03-08-2012 9:39 PM
Hi Nihkil,
I think the screenshot that you provided does not relate to what you want to achieve. If I'm not wrong then I think you want to maintain check table for REGION and COUNTRY fields of MAIN table. That means establish a foreign key relationship between "CHECK1-REGION = MAIN-REGION" and "CHECK2-COUNTRY = MAIN-COUNTRY".
Now coming to your screenshot, check carefully that the scenario is for maintaining one check table (ZTXT005S) for two different tables (ZTXLFA1 & ZTXLFA1CC). To illustrate with your example: it means that you want to maintain foreign key relationship for CHECK1 and CHECK2 tables and MAIN table is the check table. Something like below:
MAIN-MANDT = CHECK1-MANDT
MAIN-REGION = CHECK1-REGION
MAIN-COUNTRY = CHECK2-COUNTRY
Left hand side is for Check table and right hand side is for assignment (your table). You will get left hand side data (mandt, region, and country) only if they are the primary key in MAIN table.
For your better understanding try this : You can try this combination for one of your Z CHECK1/CHECK2 tables. When you are establishing a foreign key for CHECK1 table say REGION field, it will give a popup whether you want to create/generate proposal with MAIN table (or any other table). Click yes. If MAIN table then on left hand side you will get the above 3 fields and here you can assign different table for country.
However, I think your requirement is to create CHECK1 and CHECK2 as check tables for MAIN table. For this do the following:
1) Go to the MAIN table, 'Entry help/check' tab. Select REGION field and click key icon/button (foreign keys). Generate foreign key with CHECK1 table. Here you will find MANDT and REGION on the left side since you may have declared only these 2 fields as primary key in CHECK1 table.
NOTE: Select 'Check Required' checkbox so that all the region values that you enter for MAIN must be checked against the CHECK1 table. (I think you probably must be missing this checkbox for country and so its value is not checked against CHECK2 or country table)
2) Do the same thing for country field.
Now, try to enter an invalid value in region and country fields. It will not allow you to save that entry.
Hope this helps!!!! Do let me know if it works.
Regards,
Saba
Edited by: Saba Sayed on Mar 8, 2012 10:41 PM
03-10-2012 10:54 AM
Hi,
What i understand of adapted foreign key
Adapted foreign keys: If all the fields of a compound foreign key are not from same table it is called as an adapted foreign key.
You can implement the same following way.
go to se11 select the field and Click on foreign key button. it will propose the check table based on the data element used, if you want different table say no and give your table name.
Note : You can avoid fields for which you do not want the reference to be maintained by selecting key as generic and removing those field from selection.
you can repeat the steps for each field you want a reference key to check the value..moreover you can specify the error message and message class you want to display when integrity fails.
Hope this will help.
Janisar
Edited by: janisar.munshi on Mar 10, 2012 4:26 PM
Edited by: janisar.munshi on Mar 10, 2012 4:27 PM
04-23-2013 11:44 AM
hi nikhil, i am also facing the same problem. did you solve it? please help if anyone know the solution.