Upload
bakkalibilal
View
216
Download
0
Embed Size (px)
Citation preview
8/10/2019 Chapter 03_Foreign Key Relationships
1/21
IBM Global Business Services
IBM Corporation 2013Foreign Key Relationships Dec-2008
Foreign Key Relationships
8/10/2019 Chapter 03_Foreign Key Relationships
2/21
IBM Global Business Services
IBM Corporation 20132 Dec-2008Foreign Key Relationships |
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
8/10/2019 Chapter 03_Foreign Key Relationships
3/21
IBM Global Business Services
IBM Corporation 20133 Dec-2008Foreign Key Relationships |
Definition of Foreign Keys
Relationships between tables are represented in the ABAP Dictionary byforeign keys.
A foreign key is a field (or combination of fields) that represents the primary
key of another table.
8/10/2019 Chapter 03_Foreign Key Relationships
4/21
IBM Global Business Services
IBM Corporation 20134 Dec-2008Foreign Key Relationships |
Uses of Foreign Keys
Maintain data integrity
Provide help texts
Create aggregate dictionary objects
8/10/2019 Chapter 03_Foreign Key Relationships
5/21
IBM Global Business Services
IBM Corporation 20135 Dec-2008Foreign Key Relationships |
Prerequisites for Constructing Foreign Key Relationships
The foreign key field and the primary key of the check table must share the samedomain.
8/10/2019 Chapter 03_Foreign Key Relationships
6/21
IBM Global Business Services
IBM Corporation 20136 Dec-2008Foreign Key Relationships |
Check Table
Value Table
Foreign Keys: Key Terminology
Foreign 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
8/10/2019 Chapter 03_Foreign Key Relationships
7/21
IBM Global Business Services
IBM Corporation 20137 Dec-2008Foreign Key Relationships |
CheckTable ValueTable
Foreign Key Terminology: Check Table = Value Table
In many cases, the value table and the check table will be the same
8/10/2019 Chapter 03_Foreign Key Relationships
8/21
IBM Global Business Services
IBM Corporation 20138 Dec-2008Foreign Key Relationships |
Foreign Key Terminology: Check Table Value Table
Check
Table
Value
Table
Sometimes check table is another table containing a subset of the records ina value table.
8/10/2019 Chapter 03_Foreign Key Relationships
9/21
IBM Global Business Services
IBM Corporation 20139 Dec-2008Foreign Key Relationships |
Establishing a Foreign Key Relationship in the ABAPDictionary
During defining Foreign Key Relationship, system suggests a Foreign KeyRelationship for you.
8/10/2019 Chapter 03_Foreign Key Relationships
10/21
IBM Global Business Services
IBM Corporation 201310 Dec-2008Foreign Key Relationships |
Cardinality
n : m
1
C
1
C
N
CN
When creating foreign key relationships, you should always specify the cardinalityof that relationship
8/10/2019 Chapter 03_Foreign Key Relationships
11/21
IBM Global Business Services
IBM Corporation 201311 Dec-2008Foreign Key Relationships |
Creating a Foreign Key Relationship
Foreign key push-button
8/10/2019 Chapter 03_Foreign Key Relationships
12/21
IBM Global Business Services
IBM Corporation 201312 Dec-2008Foreign Key Relationships |
Maintaining a Foreign Key Relationships Attributes
Enter a description (short text).
Maintain foreign
key type
Maintain cardinality n : m
Check table
8/10/2019 Chapter 03_Foreign Key Relationships
13/21
IBM Global Business Services
IBM Corporation 201313 Dec-2008Foreign Key Relationships |
If the primary key of a check table has multiple fields (i.e. it has a compositeprimary key), some type of assignment must be made for each field when
creating a foreign key relationship.
Foreign Keys with Multiple Fields
8/10/2019 Chapter 03_Foreign Key Relationships
14/21
IBM Global Business Services
IBM Corporation 201314 Dec-2008Foreign Key Relationships |
Check Table
Field-By-Field Assignment
Foreign Key Table
When performing a field-by-field assignment, all key fields in the check tableare used to determine valid entries in the foreign key table.
8/10/2019 Chapter 03_Foreign Key Relationships
15/21
IBM Global Business Services
IBM Corporation 201315 Dec-2008Foreign Key Relationships |
Partial Foreign Keys
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.
8/10/2019 Chapter 03_Foreign Key Relationships
16/21
IBM Global Business Services
IBM Corporation 201316 Dec-2008Foreign Key Relationships |
Constant Foreign Keys
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.
8/10/2019 Chapter 03_Foreign Key Relationships
17/21
IBM Global Business Services
IBM Corporation 201317 Dec-2008Foreign Key Relationships |
Combined use of Partial and Constant foreign keys
Generic foreign key
Constant foreign key
8/10/2019 Chapter 03_Foreign Key Relationships
18/21
IBM Global Business Services
IBM Corporation 201318 Dec-2008Foreign Key Relationships |
Demonstration
Creation of a new transparent table for holding the payroll data for employees inan organization and establish a foreign key relationship with the employee table
created for the previous chapter.
8/10/2019 Chapter 03_Foreign Key Relationships
19/21
IBM Global Business Services
IBM Corporation 201319 Dec-2008Foreign Key Relationships |
Practice
Creation of a new transparent table for holding the payroll data for employees inan organization and establish a foreign key relationship with the employee table
created for the previous chapter.
IBM Gl b l B i S i
8/10/2019 Chapter 03_Foreign Key Relationships
20/21
IBM Global Business Services
IBM Corporation 201320 Dec-2008Foreign Key Relationships |
Summary
Relationships between tables are represented in the ABAP Dictionary by foreignkeys. 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.
IBM Gl b l B i S i
8/10/2019 Chapter 03_Foreign Key Relationships
21/21
IBM Global Business Services
IBM Corporation 201321 Dec-2008Foreign Key Relationships |
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 ?