Whats is foreign keys
Foreign keys describe the relationship between the tables in the ABAP Data Dictionary. Foreign keys can also be used to create value checks for the input fields, and when a foreign key relationship is maintained for particular field
To create foreign keys you can use SE11 SAP Transaction code. Open you table that you need to create foreign key.
Select fields you want to create foreign key and click button with icon key ( Foreign Keys ). and the new screen will shown. In this screen you need to entered Check Table for example ZCS2_MAJOR and click button Generate Proposal.
Foreign key field Type show whether the foreign key field identifies the foreign key table. this flag can have the following categories.
The semantic attributes of the foreign key relatioship are optional, however if you are using your foreign key for defining maintenance views, help views, matchcodes or lock objects, these semantic attributes must be defined.
This category applies when the foreign key is neither a primary key of the foreign key table nor the candidate key of the foreign key table.
Use this category when the foreign key is either a primary key of the foreign key table or the candidate key of the foreign key table. For example, table VBAP is an item level sales document table have VBELN field is a primary key of table, this field is uniquely so this field belong to the KEY FIELDS/CANDIDATES.
KEY FIELDS OF A TEXT TABLE.
The foreign key table is the text table for check table, for example table TSTCT is a text table of table TSTC. The foreign key must have the KEY FIELDS OF TEXT TABLE option checked.
Cardinality defines the number of record occurences in either side of the relation, for example cardinality 1:N this means for each record of the foreign key table, there is exactly one record assigned to the check table.
Screen Check flag is used for module pool program, the value you’ve entered will checked in the corresponding check table. If the value is not found in the check table an error message is displayed in status bar.
You also can customize Message Error by your custom message class using tcode SE91 SAP Transaction code. After you’ve finished maintain all attributes in that’s screen click COPY button. Go to Entry Help/Check tab and you can see ZCS2_MAJOR as your check table in COURSE_ID Field. This means you already succesfull create foreign key.