Start of Content Area

Background documentation Foreign Key Relationship and Join Condition  Locate the document in its SAP Library structure

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.

Example

Create a view on 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_A assigned to TAB2-FIELD_1

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

CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = TAB1-FIELD_B.

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.

Example

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 ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = ‘C’.