Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 20

Foreign Key Relationships | 1.

03 | September-2003 Slide 1
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 | 1.03 | September-2003 Slide 2
Uses of Foreign Keys
Maintain data integrity
Provide help texts
Create aggregate dictionary objects
Foreign Key Relationships | 1.03 | September-2003 Slide 3
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
Foreign Key Relationships | 1.03 | September-2003 Slide 4
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
Foreign Key Relationships | 1.03 | September-2003 Slide 5
Check
Table
Value
Table
Foreign Key Terminology:
Check Table = Value Table
In many cases, the value table and the check table will be the same
Foreign Key Relationships | 1.03 | September-2003 Slide 6
Foreign Key Terminology:
Check Table Value Table
Check
Table
Value
Table
Sometimes check table is another table containing a subset of the records in
a value table.
Foreign Key Relationships | 1.03 | September-2003 Slide 7
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 | 1.03 | September-2003 Slide 8
Cardinality
n : m
1
C
1
C
N
CN
When creating foreign key relationships, you should always specify the cardinality
of that relationship
Foreign Key Relationships | 1.03 | September-2003 Slide 9
Foreign key push-button
Creating a Foreign Key
Relationship
Foreign Key Relationships | 1.03 | September-2003 Slide 10
Enter a description (short text).
Maintain cardinality n : m
Maintain foreign
key type
Check table
Maintaining a Foreign Key
Relationships Attributes
Foreign Key Relationships | 1.03 | September-2003 Slide 11
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.

Foreign Key Relationships | 1.03 | September-2003 Slide 12
Check Table
Field-By-Field Assignment
Foreign 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.
Foreign Key Relationships | 1.03 | September-2003 Slide 13
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.
Foreign Key Relationships | 1.03 | September-2003 Slide 14
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.
Foreign Key Relationships | 1.03 | September-2003 Slide 15
Combined use of Partial and
Constant foreign keys
Generic foreign key
Constant foreign key
Including Structures in Tables
Table XYZ
.INCLUDE CI_XXX

Table T

.APPEND ZAT

Table YCUSTAB
.INCLUDE YSTRUC

Append Structures
Substructures Customizing Includes
Customer Tables SAP Tables
SAP Tables
Field 1
Field 2
...
Field n
Structure is a group of internal fields that logically belong together
Table XYZ

.INCLUDE CI_XXX

Table T

.APPEND ZAT

Table YCUSTAB

.INCLUDE YSTRUC

Append Structures
Substructures Customizing Includes
Customer Tables
SAP Tables
SAP Tables
Field 1
Field 2
...
Field n
Including Structures in Tables
(Continued..)
YS-F1 YS-F2 YS-F3...
Table Field Data element
YT2 S1
(TRANSP) S2

F1
Table Field Data element
YT1 S1
(TRANSP) S2

F1
.INCLUDE YS
.INCLUDE YS
YS
Substructure
CI_XXX
Table Field Data element

XYZ S1
F1
. . .
Fn



.INCLUDE CI_XXX
CI_XXX-F1 CI_XXX-F2 CI_XXX-F3
Customizing Include
ZAT-F1 ZAT-F2 ZAT-F3
Table Field Data element

T S1
F1
. . .
Fn



.APPEND ZAT
ZAT
Append Structure

You might also like