Chapter 03 foreign key relationships1
-
Upload
kranthi-kumar -
Category
Documents
-
view
255 -
download
2
description
Transcript of Chapter 03 foreign key relationships1
Foreign Key Relationships
March-2005 Foreign Key Relationships | 2.03
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
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.
Uses of Foreign Keys• Maintain data integrity• Provide help texts• Create aggregate dictionary objects
March-2005 Foreign Key Relationships | 2.03 4
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
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
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
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.
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.
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
Creating a Foreign Key Relationship
March-2005 Foreign Key Relationships | 2.03 11
Foreign key push-button
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
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
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.
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.
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.
Combined use of Partial and Constant foreign keys
March-2005 Foreign Key Relationships | 2.03 17
Generic foreign key
Constant foreign keyConstant foreign key
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
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
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
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