SlideShare a Scribd company logo
1 of 21
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
Data
Dictionary
 During defining Foreign Key Relationship, system suggests a Foreign Key
Relationship for you.
Cardinality
March-2005 Foreign Key Relationships | 2.03 10
nn :: mmnn :: mm
1
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 foreign
key 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 aMarch-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

More Related Content

What's hot

BATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONBATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONKranthi Kumar
 
SAP Modularization techniques
SAP Modularization techniquesSAP Modularization techniques
SAP Modularization techniquesJugul Crasta
 
Technical Overview of CDS View – SAP HANA Part I
Technical Overview of CDS View – SAP HANA Part ITechnical Overview of CDS View – SAP HANA Part I
Technical Overview of CDS View – SAP HANA Part IAshish Saxena
 
Top 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.comTop 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.combigclasses.com
 
Sap Abap Reports
Sap Abap ReportsSap Abap Reports
Sap Abap Reportsvbpc
 
Call transaction method
Call transaction methodCall transaction method
Call transaction methodKranthi Kumar
 
Introduction to ABAP
Introduction to ABAPIntroduction to ABAP
Introduction to ABAPsapdocs. info
 
Sap abap part1
Sap abap part1Sap abap part1
Sap abap part1sailesh107
 
HANA WITH ABAP OVERVIEW
HANA WITH ABAP OVERVIEWHANA WITH ABAP OVERVIEW
HANA WITH ABAP OVERVIEWdheerajad
 
SAP ABAP - Needed Notes
SAP   ABAP - Needed NotesSAP   ABAP - Needed Notes
SAP ABAP - Needed NotesAkash Bhavsar
 
Chapter 01 user exits
Chapter 01 user exitsChapter 01 user exits
Chapter 01 user exitsKranthi Kumar
 

What's hot (20)

Reports
ReportsReports
Reports
 
Sap abap
Sap abapSap abap
Sap abap
 
BATCH DATA COMMUNICATION
BATCH DATA COMMUNICATIONBATCH DATA COMMUNICATION
BATCH DATA COMMUNICATION
 
SAP Modularization techniques
SAP Modularization techniquesSAP Modularization techniques
SAP Modularization techniques
 
Technical Overview of CDS View – SAP HANA Part I
Technical Overview of CDS View – SAP HANA Part ITechnical Overview of CDS View – SAP HANA Part I
Technical Overview of CDS View – SAP HANA Part I
 
Abap dictionary 1
Abap dictionary 1Abap dictionary 1
Abap dictionary 1
 
Top 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.comTop 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.com
 
Sap Abap Reports
Sap Abap ReportsSap Abap Reports
Sap Abap Reports
 
Call transaction method
Call transaction methodCall transaction method
Call transaction method
 
Introduction to ABAP
Introduction to ABAPIntroduction to ABAP
Introduction to ABAP
 
Module pool programming
Module pool programmingModule pool programming
Module pool programming
 
Alv theory
Alv theoryAlv theory
Alv theory
 
Bapi step-by-step
Bapi step-by-stepBapi step-by-step
Bapi step-by-step
 
Sap abap part1
Sap abap part1Sap abap part1
Sap abap part1
 
SAP Adobe forms
SAP Adobe formsSAP Adobe forms
SAP Adobe forms
 
Abap Objects for BW
Abap Objects for BWAbap Objects for BW
Abap Objects for BW
 
HANA WITH ABAP OVERVIEW
HANA WITH ABAP OVERVIEWHANA WITH ABAP OVERVIEW
HANA WITH ABAP OVERVIEW
 
Index in SAP ABAP
Index in SAP ABAPIndex in SAP ABAP
Index in SAP ABAP
 
SAP ABAP - Needed Notes
SAP   ABAP - Needed NotesSAP   ABAP - Needed Notes
SAP ABAP - Needed Notes
 
Chapter 01 user exits
Chapter 01 user exitsChapter 01 user exits
Chapter 01 user exits
 

Viewers also liked

ABAP Material 04
ABAP Material 04ABAP Material 04
ABAP Material 04warcraft_c
 
Chapter 01 overview of abap dictionary1
Chapter 01 overview of abap dictionary1Chapter 01 overview of abap dictionary1
Chapter 01 overview of abap dictionary1Kranthi Kumar
 
Chapter 04 abap dictionary tables in relational databases1
Chapter 04 abap dictionary tables in relational databases1Chapter 04 abap dictionary tables in relational databases1
Chapter 04 abap dictionary tables in relational databases1Kranthi Kumar
 
Chapter 05 adding structures1
Chapter 05 adding structures1Chapter 05 adding structures1
Chapter 05 adding structures1Kranthi Kumar
 
Chapter 06 abap repository information system1
Chapter 06 abap  repository information system1Chapter 06 abap  repository information system1
Chapter 06 abap repository information system1Kranthi Kumar
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)Kranthi Kumar
 
Lecture02 abap on line
Lecture02 abap on lineLecture02 abap on line
Lecture02 abap on lineMilind Patil
 
Chapter 07 abap dictionary changes1
Chapter 07 abap dictionary changes1Chapter 07 abap dictionary changes1
Chapter 07 abap dictionary changes1Kranthi Kumar
 
Chapter 02 abap dictionary objects1
Chapter 02 abap dictionary objects1Chapter 02 abap dictionary objects1
Chapter 02 abap dictionary objects1Kranthi Kumar
 
Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Kranthi Kumar
 
Chapter 10 online help & documentation1
Chapter 10 online help & documentation1Chapter 10 online help & documentation1
Chapter 10 online help & documentation1Kranthi Kumar
 
0106 debugging
0106 debugging0106 debugging
0106 debuggingvkyecc1
 
Sujith ~ cross applications
Sujith ~ cross applicationsSujith ~ cross applications
Sujith ~ cross applicationsKranthi Kumar
 

Viewers also liked (20)

ABAP Material 04
ABAP Material 04ABAP Material 04
ABAP Material 04
 
Chapter 01 overview of abap dictionary1
Chapter 01 overview of abap dictionary1Chapter 01 overview of abap dictionary1
Chapter 01 overview of abap dictionary1
 
Chapter 04 abap dictionary tables in relational databases1
Chapter 04 abap dictionary tables in relational databases1Chapter 04 abap dictionary tables in relational databases1
Chapter 04 abap dictionary tables in relational databases1
 
Chapter 05 adding structures1
Chapter 05 adding structures1Chapter 05 adding structures1
Chapter 05 adding structures1
 
Chapter 06 abap repository information system1
Chapter 06 abap  repository information system1Chapter 06 abap  repository information system1
Chapter 06 abap repository information system1
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)
 
Contraints
ContraintsContraints
Contraints
 
Batch input session
Batch input sessionBatch input session
Batch input session
 
Badis
Badis Badis
Badis
 
Lecture02 abap on line
Lecture02 abap on lineLecture02 abap on line
Lecture02 abap on line
 
Chapter 07 abap dictionary changes1
Chapter 07 abap dictionary changes1Chapter 07 abap dictionary changes1
Chapter 07 abap dictionary changes1
 
Ale Idoc
Ale IdocAle Idoc
Ale Idoc
 
05 internal tables
05 internal tables05 internal tables
05 internal tables
 
data modelling1
 data modelling1 data modelling1
data modelling1
 
cardinality1
cardinality1cardinality1
cardinality1
 
Chapter 02 abap dictionary objects1
Chapter 02 abap dictionary objects1Chapter 02 abap dictionary objects1
Chapter 02 abap dictionary objects1
 
Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1
 
Chapter 10 online help & documentation1
Chapter 10 online help & documentation1Chapter 10 online help & documentation1
Chapter 10 online help & documentation1
 
0106 debugging
0106 debugging0106 debugging
0106 debugging
 
Sujith ~ cross applications
Sujith ~ cross applicationsSujith ~ cross applications
Sujith ~ cross applications
 

Similar to Chapter 03 foreign key relationships1

Create table relationships
Create table relationshipsCreate table relationships
Create table relationshipsDastan Kamaran
 
Create table relationships
Create table relationshipsCreate table relationships
Create table relationshipsDastan Kamaran
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database DesignArchit Saxena
 
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docxAB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docxbartholomeocoombs
 
IS230 - Chapter 4 - Keys and Relationship - Revised.ppt
IS230 - Chapter 4 - Keys and Relationship - Revised.pptIS230 - Chapter 4 - Keys and Relationship - Revised.ppt
IS230 - Chapter 4 - Keys and Relationship - Revised.pptwondmhunegn
 
Advance database system(part 5)
Advance database system(part 5)Advance database system(part 5)
Advance database system(part 5)Abdullah Khosa
 
Database Relationships
Database RelationshipsDatabase Relationships
Database Relationshipswmassie
 

Similar to Chapter 03 foreign key relationships1 (7)

Create table relationships
Create table relationshipsCreate table relationships
Create table relationships
 
Create table relationships
Create table relationshipsCreate table relationships
Create table relationships
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docxAB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
 
IS230 - Chapter 4 - Keys and Relationship - Revised.ppt
IS230 - Chapter 4 - Keys and Relationship - Revised.pptIS230 - Chapter 4 - Keys and Relationship - Revised.ppt
IS230 - Chapter 4 - Keys and Relationship - Revised.ppt
 
Advance database system(part 5)
Advance database system(part 5)Advance database system(part 5)
Advance database system(part 5)
 
Database Relationships
Database RelationshipsDatabase Relationships
Database Relationships
 

More from Kranthi Kumar

Creating simple comp
Creating simple compCreating simple comp
Creating simple compKranthi Kumar
 
Controllers and context programming
Controllers and context programmingControllers and context programming
Controllers and context programmingKranthi Kumar
 
Binding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseBinding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseKranthi Kumar
 
Web(abap introduction)
Web(abap introduction)Web(abap introduction)
Web(abap introduction)Kranthi Kumar
 
Chapter 07 debugging sap scripts
Chapter 07 debugging sap scriptsChapter 07 debugging sap scripts
Chapter 07 debugging sap scriptsKranthi Kumar
 
Chapter 06 printing sap script forms
Chapter 06 printing sap script formsChapter 06 printing sap script forms
Chapter 06 printing sap script formsKranthi Kumar
 
Chapter 05 sap script - configuration
Chapter 05 sap script - configurationChapter 05 sap script - configuration
Chapter 05 sap script - configurationKranthi Kumar
 
Chapter 04 sap script - output program
Chapter 04 sap script - output programChapter 04 sap script - output program
Chapter 04 sap script - output programKranthi Kumar
 
Chapter 02 sap script forms
Chapter 02 sap script formsChapter 02 sap script forms
Chapter 02 sap script formsKranthi Kumar
 

More from Kranthi Kumar (20)

Exercise in alv
Exercise in alvExercise in alv
Exercise in alv
 
Dynamic binding
Dynamic bindingDynamic binding
Dynamic binding
 
Data binding
Data bindingData binding
Data binding
 
Creating simple comp
Creating simple compCreating simple comp
Creating simple comp
 
Creating messages
Creating messagesCreating messages
Creating messages
 
Creating a comp
Creating a compCreating a comp
Creating a comp
 
Controllers and context programming
Controllers and context programmingControllers and context programming
Controllers and context programming
 
Context at design
Context at designContext at design
Context at design
 
Binding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseBinding,context mapping,navigation exercise
Binding,context mapping,navigation exercise
 
Alv for web
Alv for webAlv for web
Alv for web
 
Web(abap introduction)
Web(abap introduction)Web(abap introduction)
Web(abap introduction)
 
Abap faq
Abap faqAbap faq
Abap faq
 
Sap abap material
Sap abap materialSap abap material
Sap abap material
 
Crm technical
Crm technicalCrm technical
Crm technical
 
control techniques
control techniquescontrol techniques
control techniques
 
Chapter 07 debugging sap scripts
Chapter 07 debugging sap scriptsChapter 07 debugging sap scripts
Chapter 07 debugging sap scripts
 
Chapter 06 printing sap script forms
Chapter 06 printing sap script formsChapter 06 printing sap script forms
Chapter 06 printing sap script forms
 
Chapter 05 sap script - configuration
Chapter 05 sap script - configurationChapter 05 sap script - configuration
Chapter 05 sap script - configuration
 
Chapter 04 sap script - output program
Chapter 04 sap script - output programChapter 04 sap script - output program
Chapter 04 sap script - output program
 
Chapter 02 sap script forms
Chapter 02 sap script formsChapter 02 sap script forms
Chapter 02 sap script forms
 

Chapter 03 foreign key relationships1

  • 1. Foreign Key Relationships March-2005 Foreign Key Relationships | 2.03
  • 2. 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
  • 3. 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.
  • 4. Uses of Foreign Keys • Maintain data integrity • Provide help texts • Create aggregate dictionary objects March-2005 Foreign Key Relationships | 2.03 4
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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.
  • 9. Establishing a Foreign Key Relationship in the ABAP Dictionary March-2005 Foreign Key Relationships | 2.03 9 Data Dictionary  During defining Foreign Key Relationship, system suggests a Foreign Key Relationship for you.
  • 10. Cardinality March-2005 Foreign Key Relationships | 2.03 10 nn :: mmnn :: mm 1 C 1 C N CN  When creating foreign key relationships, you should always specify the cardinality of that relationship
  • 11. Creating a Foreign Key Relationship March-2005 Foreign Key Relationships | 2.03 11 Foreign key push-button
  • 12. Maintaining a Foreign Key Relationship’s Attributes March-2005 Foreign Key Relationships | 2.03 12 Enter a description (short text). Maintain foreign key type Check table Maintain cardinality n : m
  • 13. 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
  • 14. 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.
  • 15. 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.
  • 16. 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.
  • 17. Combined use of Partial and Constant foreign keys March-2005 Foreign Key Relationships | 2.03 17 Generic foreign key Constant foreign keyConstant foreign key
  • 18. 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
  • 19. 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
  • 20. 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 aMarch-2005 Foreign Key Relationships | 2.03 20
  • 21. 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

Editor's Notes

  1. 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. For example, if table YORDERS has a field CUSTID indicating which customer placed the order, that field could be established as a foreign key (assuming that CUSTID was the primary key of the YCUSTOMERS table). Note that CUSTID is not necessarily part of the primary key of the table YORDERS. The table that is referenced by the foreign key (in our example, YCUSTOMERS) is called the check table. The check table is also known as the “referenced” or “parent” table. The table that contains the foreign key fields (in our example, YORDERS) is called the foreign key table. The foreign key table is also known as the “dependent” or “child” table.
  2. Foreign keys are used for: Maintaining data integrity Providing additional texts in the online help system Creating other dictionary objects that are defined over multiple tables (such as views) Maintaining data integrity is probably the most important reason to use foreign keys. With foreign keys, it is possible to prevent values from being entered into one table that do not already exist in another table. For example, it becomes impossible to enter orders that do not have valid customer numbers. In this way, foreign keys are similar to domain value tables.
  3. In fact, not only are foreign keys similar to domain value tables, but 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. Therefore, foreign keys provide an additional data integrity check beyond that which is provided by the value table. Prior SAP versions required that Foreign Keys must have a Value Table specified.
  4. Let’s review some of the key terminology relating to foreign keys. Value table: The table containing the set of allowed values attached to a domain. Check table: The table that is referenced by a foreign key. A check table is either identical to a value table, or is another table containing a subset of the records in a value table. Foreign key table: The table containing fields that are the primary key of the other table. The foreign key table is also known own as the “dependent” or “child” table. Using Foreign Keys, you can Create value checks for input fields. Link several tables in a view or in a lock object. To see a full list of the allowed values for a screen field, place the cursor inside the field and hit the F4 key.
  5. For example, suppose a foreign key relationship was established between an ORDERS table and a PRODUCTS table in order to ensure that orders contained valid product numbers. In this case, it is likely that the value table and the check table would both be the PRODUCTS table. In many cases, the value table and the check table will be the same. However, it is important to understand the distinction between the two. The Value Table is optional in the foreign key definition. Foreign Key definitions must always have a Check Table assigned.
  6. For example, suppose a telephone company stores general customer information in the CUSTOMERS table and stores specialised information about business customers in the BUSINESS_CUSTOMERS table. Suppose that there was also a BUSINESS_OWNERS table that listed the owners of all business customers. The BUSINESS_OWNERS table might consist of two fields: Customer ID and the name of each individual owner. In this case, we would establish a foreign key relationship between the BUSINESS_OWNERS table and the BUSINESS-CUSTOMERS table. The value table for the customer ID field in the BUSINESS_OWNERS table would be the CUSTOMERS table, but the check table would be the BUSINESS_CUSTOMERS table. The foreign key table would be the BUSINESS_OWNERS table.
  7. To establish a Foreign Key in the ABAP Dictionary, begin by navigating to the field definition of the Foreign Key Table and entering change mode. The Foreign Key can then be established by placing the cursor on the Foreign Key Field, and then by clicking the icon in the Application Toolbar. Based on the Value Table for the domain of the field you selected, the system will suggest a Foreign Key Relationship for you.
  8. When creating foreign key relationships, you should always specify the cardinality of that relationship. Here is a reminder of the possible values for each side of the n : m notation that SAP uses to specify cardinality. For the left side: n = 1Each record in the foreign key table refers to exactly one record in the check table. n = CEach record in the foreign key table refers to zero or one records in the check table. For the right side: m = 1 Each record in the check table has exactly one dependent record. m = C Each record in the check table has a zero or one dependent records. m = N Each record in the check table has at least one dependent record. m = CN Each record in the check table has zero, one, or many dependent entities.
  9. Using the Object Navigator edit the Table ZXXFIRSTTABLE which we created in Chapter 2. Place the cursor on the field for which you wish to create a Foreign Key Relationship. In this example, we will add the Check Table T005S as a Foreign Key for the STATE field so that users will be forced to enter a valid state into the Table ZXXFIRSTTABLE. Click the icon to create the Foreign Key Relationship for the STATE field.Remember the criteria for establishing a Foreign Key Relationship: the Foreign Key Field and Check Table Field must share the same domain. A value table must exist for that domain.Since the field STATE’s domain (REGIO) has a Value Table (T005S), SAP will propose T005S as the Check Table for the field STATE when we click the Foreign Key pushbutton. Click Yes when the Create Foreign Key window appears. You can see a graphical representation of the foreign key relationships in a table by going to Utilities  Graphics. The option to view foreign key relationships graphically is not available in previous releases.
  10. Enter a description (short text). Maintain the semantic attributes (see Data Dictionary Appendix for information on setting up the Cardinality) Cardinality n : m n = 1 or C m = 1, C, N, CN Foreign Key Field Type (see Data Dictionary Appendix for information on setting up the Foreign Key Field Type) Not Specified Non-Key Field Candidates Key Field / Key Field Candidates Key Fields of a Text Table Click the Copy button at the bottom of the screen.
  11. 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. The options include: Creating a field-by-field assignment. Every primary key field in the check table is matched with a field in the foreign key table. Using a partial foreign key. Some fields will not be a determining factor in deciding what check table records provide acceptable values for the foreign key field being checked. Using a constant foreign key. Only check table records with a particular constant (literal) value in a particular field provide acceptable values for the foreign key field being checked.
  12. 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. For example, suppose there was a YCOURSES table with the key fields faculty (academic department) and course number. This table would provide the master list of courses that an academic institution offers. Suppose also that there was a YOFFERINGS table with the key fields faculty, course number, and section number. This table would list the times and dates that different sections of each course were offered. In this case, we would establish a foreign key relationship from YOFFERINGS to YCOURSES using field-by-field assignment. In other words, the faculty and course number fields for each record in the YOFFERINGS table would have to match the faculty and course number fields for some record in the YCOURSES table.
  13. 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. For example, suppose that we were tracking information about new courses that were under development in a YNEWCRS table. This table would have faculty and course number as the primary key. However, in this table, we would not want to validate the course number against the YCOURSES table, because by definition the new courses are not yet in the YCOURSES table. In this case, we might use a partial foreign key from YNEWCRS to YCOURSES and flag the course number field as generic. In other words, the table YNEWCRS would be forced to have valid values in the faculty field, but we could enter any course number we wanted. This example is for illustration purposes. In a real-world application, there would probably be a separate YFACULTY table that would list valid faculties, and the YNEWCRS table would probably be validated against that table.] Note: If additional fields are added to the primary key of a check table, the new fields are automatically flagged as generic in any previously existing foreign keys.
  14. 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. For example, suppose there was a table YBIOCRS that contained specific information about biology courses. The primary key of this table would be course number only (it would already be understood that the courses were biology courses). In this case, we would want to validate the course number against the YCOURSES table, but we would only want biology course numbers to be valid. That is, if there was a course “English 402” but no course “Biology 402”, we would not want 402 to be a valid entry in table YBIOCRS. To accomplish this, we could establish a foreign key from YBIOCRS to YCOURSES with the constant value “BIO” in the faculty field. Note: Assigning a constant value to a field has the effect of restricting the values that are permissible for the other foreign key fields in the foreign key table. Validation is actually turned off for the field that is assigned the constant value. For example, if we changed the above example so that the table YBIOCRS did have a faculty field, it would be possible to enter any value in that field.
  15. Click on the checkbox provided to flag a foreign key field as generic. Enter a constant value in quotes to define a foreign key relationship with a constant. It is possible to combine the use of partial and constant foreign keys within the same foreign key relationship.