Foreign Keys in SAP ABAP
Foreign Keys in SAP ABAP
What is Foreign Key
We are using foreign keys to define relationships between the tables in the SAP ABAP and to create value checks for input fields and to link several tables in a view or a lock object.
Field Relationship in the Foreign Key
A foreign key links two tables T1 and T2 by assigning fields of table T1 to the primary key fields of table T2.
Table T1 is called the foreign key table (dependent table) and table T2 the check table (referenced table). The pair of fields for the two tables must have the same data type and length. One field of the foreign key table corresponds to each key field of the check table. This field is called the foreign key field.
Check Field and Value Check
When you make an entry in the check field, the system checks whether the check table contains a record with the key defined by the values in the foreign key fields. If there is such a record, the entry is valid. Otherwise the system rejects the entry.
You have the option of not checking against all the key fields of the check table.
How the Input Check Works
A SELECT statement is generated from the definition of the foreign key. If you make an entry in the check field, the system submits this SELECT statement. If the system finds a suitable record of the check table, the entry is valid. Otherwise the system rejects the entry.
Types of foreign keys in SAP ABAP
Generic foreign keys
You can use generic foreign keys when you have to do a search in a table using only certain fields of the foreign key. Using generic foreign keys, you can exclude fields from the assignment to the key fields of the check table.
Constant foreign keys
You can also assign a constant value to a key field of the check table. In this case, you only have to check against the specified constant. You can use this check if only records of the check table which contain a constant value in this key field are valid.
How to create Foreign Key in SAP ABAP
Step 1. First create the the two SAP Tables ,Now we have to maintain the Foreign key relationship between these two tables ,for that, open the Table in SE11(Data Dictionary) to which we have to create foreign key ,select the particular row and click on the FOREIGN KEY Button.
Step 2. Provide the check table name ZEMP_DEPT and click on the GENERATE PROPOSAL button.
Step 3. After clicking the Generate Proposal button , system will automatically populates the matching domains between the check table and the foreign key table. Just click on the COPY button.
Save and Activate, now Foreign key is created. To check the foreign key go to menu path Utilities->Table Contents->Create Entries.
I am good at codes. How to shift between real temp to prefetch.
ReplyDelete<a href="https://www.kitsonlinetrainings.com/course/sap-abap-on-hana-online-training"rel="ugc>sap abap online training in hyderabad training</a>