How to create a Foreign Key in SAP table?

The purpose of the foreign key is to validate the data that is being entered into a table by checking entries in a check table. Foreign keys are checked by the front end user interface only and it is not checked if you issue a direct a SQL statement to update the database.

Follow the steps given below to create a foreign key in SAP table.

Step 1: Open the table in Data Dictionary (SE11) for which you want to create a foreign key. Select the field for which you want to create the foreign key and press Foreign Keys button.

foreign-key-1

Step 2: In the popup window enter the check table name and press Generate proposal button.

foreign-key-2

Step 3: The system proposes the foreign key relation based on the domain. Check that the foreign key relationship proposed by the system is correct and press copy.

foreign-key-3

Foreign key is created, now save and activate the table. To check the foreign key go to menu path Utilities->Table Contents->Create Entries.

foreign-key-4

Try to create an entry in “Zemployee” table with “Department ID” that is not there in the “Department” table. Enter the values and try to save the entry.

foreign-key-5

Observe the error message in the status bar. The user interface does the foreign key validation before creating the entries.


17 thoughts on “How to create a Foreign Key in SAP table?

  • April 24, 2011 at 1:46 pm
    Permalink

    wel thanks for the help this can serve the purpose

    Reply
    • July 1, 2015 at 4:49 am
      Permalink

      any one please can say me alv reports

      Reply
  • April 29, 2011 at 3:57 pm
    Permalink

    Thanks alot for giving such information.

    Reply
    • February 10, 2016 at 9:52 am
      Permalink

      That’s a subtle way of thnnikig about it.

      Reply
  • May 5, 2011 at 5:23 am
    Permalink

    Hi, I have tried the method you said above, but while entering the value in the screen in the foreignkey table it is not checked in the check table. I dont know why? Can you pls help me?

    Reply
  • May 5, 2011 at 9:07 am
    Permalink

    wel thanks for the help this can serve the purpose thanks again

    Reply
  • June 27, 2011 at 8:02 am
    Permalink

    very nice . it will b useful for learners.

    Reply
  • August 7, 2011 at 4:51 pm
    Permalink

    THANKS ALOT MAN.
    I HAVE ONE MORE QUERY CAN ANYONE TELL ME IS THERE ANY SITE WHERE I CAN DO PRACTICE FOR SAP ABAP MODULE ONLINE.
    OR IS THERE ANY SITE FROM WHERE I CAN DOWNLOAD THER SAP SETUP AND THEN I INSTALL IT IN MY SYSTEM.

    Reply
  • November 22, 2011 at 11:12 am
    Permalink

    Real good stuff and very helpful for sappers. Carry on please.

    Kumar from Germany

    Reply
  • November 24, 2011 at 7:33 am
    Permalink

    Well presented.. very useful

    Reply
  • March 25, 2012 at 2:01 pm
    Permalink

    WELL EXPLAINED…….. THUMBS UP!!!

    Reply
  • March 27, 2012 at 11:36 am
    Permalink

    Can any one tell me which is the foreign key and which is the check table amongst these and why??please
    give answers with using table field…..

    VBAK

    VBAP

    VBUP

    Reply
  • July 10, 2012 at 5:09 am
    Permalink

    the Primary key and foreign key all come from Relational Database theory. some concepts in this artical about foreign key are not accurate.

    Reply
  • February 26, 2013 at 4:19 am
    Permalink

    Really wonderful explination!

    Reply
  • June 2, 2016 at 9:53 am
    Permalink

    Thanks for this good explanation 🙂

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *