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
Slide 1
Foreign Key Relationships | 1.03 | September-2003
Uses of Foreign Keys • • •
Slide 2
Maintain data integrity Provide help texts Create aggregate dictionary objects
Foreign Key Relationships | 1.03 | September-2003
Prerequisites for Constructing Foreign Key Relationships • •
Slide 3
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
Foreign Keys: Key Terminology Value Table
Check Table
Foreign Key Table Slide 4
Foreign Key Relationships | 1.03 | September-2003
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 In many cases, the value table and the check table will be the same
Check Table
Slide 5
Foreign Key Relationships | 1.03 | September-2003
Valu e Tabl e
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
Slide 6
Foreign Key Relationships | 1.03 | September-2003
Valu e Tabl e
Establishing a Foreign Key Relationship in the ABAP Dictionary During defining Foreign Key Relationship, system suggests a Foreign Key Relationship for you.
Data Dictionary
Slide 7
Foreign Key Relationships | 1.03 | September-2003
Cardinality When creating foreign key relationships, you should always specify the cardinality of that relationship
n : m 1
1
C
C N CN
Slide 8
Foreign Key Relationships | 1.03 | September-2003
Creating a Foreign Key Relationship
Foreign key push-button
Slide 9
Foreign Key Relationships | 1.03 | September-2003
Maintaining a Foreign Key Relationship’s Attributes
Enter a description (short text). Check table
Maintain foreign key type
Slide 10
Foreign Key Relationships | 1.03 | September-2003
Maintain cardinality n : m
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.
Slide 11
Foreign Key Relationships | 1.03 | September-2003
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
Slide 12
Foreign Key Relationships | 1.03 | September-2003
Check Table
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.
Slide 13
Foreign Key Relationships | 1.03 | September-2003
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.
” O I B “
Slide 14
Foreign Key Relationships | 1.03 | September-2003
Combined use of Partial and Constant foreign keys
Generic foreign key Constant foreign key
Slide 15
Foreign Key Relationships | 1.03 | September-2003
Including Structures in Tables Structure is a group of internal fields that logically belong together
Substructures
SAP Tables Customizing Includes
Table YCUSTAB .INCLUDE YSTRUC
Table XYZ .INCLUDE CI_XXX
Customer Tables
Append Structures Field 1 Field 2 ... Field n
Table T .APPEND
ZAT
SAP Tables
Including Structures in Tables (Continued..) Customer Tables Substructures Table YCUSTAB .INCLUDE
YSTRUC
SAP Tables Customizing Includes Table XYZ .INCLUDE
CI_XXX
Append Structures Field 1 Field 2 ... Field n
Table T .APPEND
ZAT
SAP Tables
Substructure YS Table Field YT1 S1 (TRANSP) S2 .INCLUDE
YS-F1 YS-F2 YS-F3...
Data element
YS
F1 Table Field YT2 S1 (TRANSP) S2 .INCLUDE F1
Data element
YS
Customizing Include CI_XXX CI_XXX-F1CI_XXX-F2CI_XXXF3 Table Table
Field Field
XYZ XYZ
S1 S1 F1 F1 .. .. .. Fn Fn .INCLUDE
Data Data element element
CI_XXX
Append Structure ZAT
Table
Field
T
S1 F1 ... Fn .APPEND
ZAT-F1 ZAT-F2 ZAT-F3
Data element
ZAT