Anda di halaman 1dari 21

IBM Global Business Services

Foreign Key Relationships

Foreign Key Relationships

Dec-2008

IBM Corporation 2013

IBM Global Business Services

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

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Definition of Foreign Keys


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 Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Uses of Foreign Keys


Maintain data integrity

Provide help texts


Create aggregate dictionary objects

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Prerequisites for Constructing Foreign Key Relationships


The foreign key field and the primary key of the check table must share the same
domain.

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Foreign Keys: Key Terminology

Value Table

Check Table

Foreign Key Table

Foreign Key Relationships |

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

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Foreign Key Terminology: Check Table = Value Table


In many cases, the value table and the check table will be the same

Check
Table

Foreign Key Relationships |

Value
Table

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Foreign Key Terminology: Check Table Value Table


Sometimes check table is another table containing a subset of the records in
a value table.

Check
Table

Foreign Key Relationships |

Value
Table

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Establishing a Foreign Key Relationship in the ABAP


Dictionary
During defining Foreign Key Relationship, system suggests a Foreign Key
Relationship for you.

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Cardinality
When creating foreign key relationships, you should always specify the cardinality
of that relationship

n : m
1

C
N
CN

10

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Creating a Foreign Key Relationship

Foreign key push-button

11

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Maintaining a Foreign Key Relationships Attributes


Enter a description (short text).

Check table

Maintain foreign
key type

Maintain cardinality n : m

12

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Foreign Keys with Multiple Fields


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.

13

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Field-By-Field Assignment
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.

Foreign Key Table

14

Foreign Key Relationships |

Check Table

Dec-2008

IBM Corporation 2013

IBM Global Business Services

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.

15

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

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.

16

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Combined use of Partial and Constant foreign keys

Generic foreign key

Constant foreign key

17

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

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.

18

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Practice

19

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.

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

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.

20

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

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 ?

21

Foreign Key Relationships |

Dec-2008

IBM Corporation 2013

Anda mungkin juga menyukai