chapter 03 foreign key relationships1
DESCRIPTION
TRANSCRIPT
![Page 1: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/1.jpg)
Foreign Key Relationships
March-2005 Foreign Key Relationships | 2.03
![Page 2: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/2.jpg)
Objectives• The participants will be able to:
– Define and Use Foreign Keys– Understand the Prerequisites for Constructing
Foreign Key Relationships– Interpret Cardinality and Foreign Key Field Types– Create Foreign Key Relation
March-2005 Foreign Key Relationships | 2.03 2
![Page 3: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/3.jpg)
Definition of Foreign Keys
March-2005 Foreign Key Relationships | 2.03 3
Relationships between tables are represented in the ABAP Dictionary by foreign keys.
A foreign key is a field (or combination of fields) that represents the primary key of another table.
![Page 4: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/4.jpg)
Uses of Foreign Keys• Maintain data integrity• Provide help texts• Create aggregate dictionary objects
March-2005 Foreign Key Relationships | 2.03 4
![Page 5: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/5.jpg)
Prerequisites for Constructing Foreign Key Relationships
• The foreign key field and the primary key of the check table must share the same domain.
• A value table must exist for that domain.
March-2005 Foreign Key Relationships | 2.03 5
![Page 6: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/6.jpg)
Foreign Keys: Key Terminology
March-2005 Foreign Key Relationships | 2.03 6
Check TableCheck Table
Value TableValue Table
Foreign Key TableForeign Key Table
The table containing the set of allowed values attached to a domain
The table that is referenced by a foreign key
The table containing fields that are the primary key of the other table
![Page 7: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/7.jpg)
Foreign Key Terminology: Check Table = Value Table
March-2005 Foreign Key Relationships | 2.03 7
Check Table
Value
Table
In many cases, the value table and the check table will be the same
![Page 8: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/8.jpg)
Foreign Key Terminology: Check Table Value Table
Check Table
March-2005 Foreign Key Relationships | 2.03 8
Value
Table
Sometimes check table is another table containing a subset of the records in a value table.
![Page 9: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/9.jpg)
Establishing a Foreign Key Relationship in the ABAP Dictionary
March-2005 Foreign Key Relationships | 2.03 9
DataDictionary
During defining Foreign Key Relationship, system suggests a Foreign Key Relationship for you.
![Page 10: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/10.jpg)
Cardinality
March-2005 Foreign Key Relationships | 2.03 10
n n : : m mn n : : m m1
C
1
C
N
CN
When creating foreign key relationships, you should always specify the cardinality of that relationship
![Page 11: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/11.jpg)
Creating a Foreign Key Relationship
March-2005 Foreign Key Relationships | 2.03 11
Foreign key push-button
![Page 12: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/12.jpg)
Maintaining a Foreign Key Relationship’s Attributes
March-2005 Foreign Key Relationships | 2.03 12
Enter a description (short text).
Maintain foreignkey type
Check table
Maintain cardinality n : m
![Page 13: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/13.jpg)
March-2005 Foreign Key Relationships | 2.03 13
If the primary key of a check table has multiple fields (i.e. it has a composite primary key), some type of assignment must be made for each field when creating a foreign key relationship.
Foreign Keys with Multiple Fields
![Page 14: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/14.jpg)
Field-By-Field Assignment
March-2005 Foreign Key Relationships | 2.03 14
Check TableCheck TableForeign Key TableForeign Key Table
When performing a field-by-field assignment, all key fields in the check table are used to determine valid entries in the foreign key table.
![Page 15: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/15.jpg)
Partial Foreign Keys
March-2005 Foreign Key Relationships | 2.03 15
When creating a partial foreign key, certain fields are flagged as generic.
These fields are ignored by the system when validating records that are inserted into the foreign key table.
![Page 16: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/16.jpg)
Constant Foreign Keys
March-2005 Foreign Key Relationships | 2.03 16
“BIO”
When creating a constant foreign key, certain fields are assigned a literal value
Only records in the check table with that value in the corresponding field are used to determine whether records in the foreign key table are valid.
![Page 17: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/17.jpg)
Combined use of Partial and Constant foreign keys
March-2005 Foreign Key Relationships | 2.03 17
Generic foreign key
Constant foreign keyConstant foreign key
![Page 18: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/18.jpg)
Demonstration
• Creation of a new transparent table for holding the payroll data for employees in an organization and establish a foreign key relationship with the employee table created for the previous chapter.
March-2005 Foreign Key Relationships | 2.03 18
![Page 19: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/19.jpg)
Practice
• Creation of a new transparent table for holding the payroll data for employees in an organization and establish a foreign key relationship with the employee table created for the previous chapter.
March-2005 Foreign Key Relationships | 2.03 19
![Page 20: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/20.jpg)
Summary
• Relationships between tables are represented in the ABAP Dictionary by foreign keys. A foreign key is a field (or combination of fields) that represents the primary key of another table.
• Foreign keys maintain data integrity & provide help texts.
• In order to establish a foreign key relationship in SAP, the fields involved must share the same domain, and that domain must have a value table specified.
March-2005 Foreign Key Relationships | 2.03 20
![Page 21: Chapter 03 foreign key relationships1](https://reader033.vdocuments.net/reader033/viewer/2022061218/54b5d2704a79590b108b45a7/html5/thumbnails/21.jpg)
Questions
• What is a foreign key ?• What is the need to define a foreign key
relationship ?• What is meant by cardinality in a foreign key
relationship ?
March-2005 Foreign Key Relationships | 2.03 21