Show TOC

 Foreign Key Relationship and Join ConditionLocate this document in the navigation structure

Use

If there is already a suitable foreign key between two tables used in the view, these tables can be linked with a join condition from this foreign key.

Tip

You want to create a view of tables TAB1 and TAB2. TAB1 is the primary table of the view. TAB2 is the secondary table of the view. TAB1 is the check table for TAB2. The foreign key fields are assigned to the check table fields as follows:

TAB1-FIELD_A assigned to TAB2-FIELD_1

TAB1-FIELD_B assigned to TAB2-FIELD_2

The join condition of the view generated from the foreign key is then:

CREATE VIEW < name of the view> AS SELECT < name of the table fields> WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = TAB1-FIELD_B

Note

This SQL statement is a pseudo code that explains the corresponding functionality. The syntax of this statement is not the same in ABAP.

Join conditions can also be copied from generic and constant foreign keys. If a constant is assigned to a field in the foreign key, it is also assigned to the field in the join condition. There is no join condition for a generic relationship in the foreign key.

Tip

The foreign key between tables TAB1 (check table) and TAB2 (foreign key table) is defined as follows:

TAB1-FIELD_A assigned to TAB2-FIELD_1

TAB1-FIELD_B generic

TAB1-FIELD_C assigned to constant 'C'

The join condition for the view generated from the foreign key is in this case:

CREATE VIEW < name of the view> AS SELECT < name of the fields> WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = 'C'

Note

This SQL statement is a pseudo code that explains the corresponding functionality. The syntax of this statement is not the same in ABAP.