Skip to Content
Technical Articles

Maintaining the One-to-Many (1 = CN) cardinality between the Check table & Foreign Key tables in ABAP

Introduction: In this article we are going to learn how to provide the one to many ( 1 = CN ) cardinality between the check table and foreign key tables. one to many carnality can be selected upon our requirement while providing the foreign key relationship from key fields of foreign key table to check table key fields . One to many ( 1 = CN) cardinality refers there can be any number of matching records in the foreign key table for each record of the check table.

Below are the steps to maintain the one to many ( 1 = CN ) cardinality between the check table and foreign key table.

Check table is the master data table with unique key field value records.

Foreign key table is the dependent table where each record is checked against the check table key fields with which foreign key relationship has been maintained with appropriate cardinality.

Step1: Create a database table ZMASTER using tcode SE11 with the below fields NUM, NAME and AGE fields and maintain the NUM as the keyfield.

Step2: Select the Data Browser/Table View Maint. value as Display/Maintenance Allowed under Delivery and Maintenance tab.

Step3: Maintain the proper values under the Technical Settings.

Step4: Create the entries by going through the Utilities ->Table Contents -> Create Entries

Step5: Enter the record and click on Save button.

Step6: Now the ZMASTER table having only one record as shown below.

Step7: Now create another table ZFOREIGN using tcode SE11 with the following fields NUM and VILLAGE with NUM field as the key field.

Step8: Now maintain the foreign key relationship between ZFOREIGN and ZMASTER. We can achive this by giving  ZMASTER table in Check table field and click on ‘Generate Proposal’ button. Select ‘Foreign key field type’ as Key fields/Candidates and cardinality as 1 : CN then click on Copy button as below.

Step9: Now make the VILLAGE field also as key field and activate the table. so the fields NUM and field VILLAGE is the key for table ZFOREIGN.

Step10: Now create the entry in ZFOREIGN table by going through Utilities ->Table Contents ->Create Entries.

Step11: Now create the entries with key NUM and VILLAGE in table ZFOREIGN as shown below.

Step12: The records in the ZFOREIGN as shown below.

Conclusion: From the above example it is clear that ZMASTER is working as check table for the foreign key table ZFOREIGN for field NUM and we can enter many records with various field VILLAGE values for the same field NUM value in table ZFOREIGN. Here the key of table ZFOREIGN is combination of NUM and VILLAGE fields. So we have achieved one to many (1=CN) cardinality.

2 Comments
You must be Logged on to comment or reply to a post.
  • Sorry to say but this is not a good blog and not even a good example.

    Creating tables is a basic task that everyone should learn from their training or an ABAP book. There is also this YouTube video and Google -> “create table in SE11 site:sap.com” brings 18,500 results. That’s a lot of material! There is nothing special about creating a foreign key between two tables, this is just another textbook item.

    But even that aside, let’s look at the specific content in the blog.

    1. Introduction – sorry, if I didn’t know what foreign keys are I probably wouldn’t be able to understand anything from it. English is not a native language for me either but things like “refers there many be many” are just sloppy.
    2. The choice of terminology is rather odd. E.g. what do you mean by “combined key”? What does m = CN mean? It’s used several times, so must be important. In SE11 this cardinality is shown as “1:CN”, so what is “m”? Very confusing.
    3. There is no explanation of the business case or any kind of background. Why are we creating these tables?
    4. In the example tables pretty much everything is just bad. Terrible name choices for everything (ZTAB1 and ZTAB2, couldn’t these be at least ZMASTER and ZFOREIGN or something?), MANDT is not included, custom data types are used for no reason (with bad names again), activation step is missing (you can’t add entries to an inactive table). Even “village” names are cryptic. Why such laziness?

    Overall this just looks very sloppy and unprofessional, sorry. If you chose to post content on SCN please make sure that it adds some value to the readers and that it looks presentable. It’s also always a good idea to follow the current guidelines and use descriptive names, no matter how simple the example is. And please make sure to use proper grammar going forward and proof-read the text at least once before publishing.

    • Hi Jelena,

      Thank you for your response. I have done most of changes by considering you suggestions.

      Please feel free to advise.

      Thanks,

      Kolatum Suman