This
is continuation to my previous post. In my previous post, I created below two
database tables.
· ZSTUDNT
· ZTEACHINGFACULTY
In
this post, I am going to show how to set the foreign key relationships between
database tables.
I
am going to create a table ZFACULTY_RATING and going to set the foreign key
relationship with ZSTUDNT and ZTEACHINGFACULTY.
Firs
create the table ZFACULTY_RATING.
ZFACULTYRATING
faculty_id
|
student_id
|
faculty_rating
|
|
|
|
Field
|
Data Element
|
faculty_id
|
ZFACULTY_ID
|
student_id
|
ZSTUDENT_ID
|
faculty_rating
|
ZFACULTY_RATING
|
Use
the transaction ‘SE11’ to open ABAP dictionary.
Give
the table name as ‘ZFACULTYRATING’ and
click on Create button.
Update
the short description as ‘Faculty Rating table’
Set the Delivery class as Application Table
Set the Data Browser/Table View Editing field to
‘Display/Maintenance allowed’.
Click on Fields tab.
Since this is an Application table, we need to add MANDT
field here. Add all the fields and data elements of ZFACULTYRATING
table.
Select
the fields MANDT and faculty_id as key.
Press
Enter, it will populate other information (data type, length etc.,) like below.
Go
to Extras -> Enhancement Category
Press
Ok.
Select
the option ‘Can Be Enhanced (Deep)’ an click on the button Copy.
Save the changes.
Click on ‘Technical Settings’.
Add
data class as APPL0’.
Set
the ‘Size Category’ to 1.
Save
settings.
Activate
the table ‘ZFACULTYRATING’.
Adding the foreign
key constraint to the table ZFACULTYRATING
Open
the table ‘ZFACULTYRATING’ in Edit mode.
Go
to ‘Input Help/Check’ tab.
Select
the FACULTY_ID field and click on the ‘key icon’ button.
It
opens below window.
Update
the Short text as ‘Faculty id referring to faculty table’.
Click
on the Check table input box, it opens the list of tables.
Select
‘ZTEACHINGFACULTY’ field.
Click
on ‘Create Proposal’ button.
Press
the button ‘Copy’.
That’s
it, you are done.
Add foreign key
constraint to the field STUDENT_ID.
Select
the STUDENT_ID field and click on
the ‘key icon’ button.
Add ZStudnt table.
Now
the screen change like below.
Press
Save button and activate the table.
That’s
it you are done.
No comments:
Post a Comment