SAP SELECT INTERSECT ABEXA



Get Example source ABAP code based on a different SAP table
  



SELECT, Intersection of Multiple Tables
This example demonstrates how an intersection is created across multiple tables.

ABAP_SOURCE_CODE
DEMO CL_DEMO_SELECT_INTRSCT

ABAP_DESCRIPTION
Four columns of the same type from result sets from three database tables DEMO_JOIN1, DEMO_JOIN2 and DEMO_JOIN3 are combined to different SELECT statements using INTERSECT. The DDIC database tables are filled in the static constructor.
The first statement shows the default behavior with addition DISTINCT in the second INTERSECT and without addition DISTINCT in the first INTERSECT. No rows are inserted from DDIC database table DEMO_JOIN2 and no rows are inserted from DDIC database table DEMO_JOIN3 because these rows either already exist or do not match the first result set. The non-matching rows between the first result set and DEMO_JOIN3 are removed from DEMO_JOIN1 .
The second statement shows the behavior of INTERSECT together with UNION. INTERSECT inserts no rows from DDIC database table DEMO_JOIN2 and UNION inserts two rows from DDIC database table DEMO_JOIN3. The result is the same as using only UNION DISTINCT.
The third statement is the same as the second, except that parentheses have been inserted here. First, the parentheses are evaluated. UNION inserts two rows from DDIC database table DEMO_JOIN3 . Afterwards, the result set of the parentheses is completely inserted into the result set of DEMO_JOIN1 and removes the two rows that were inserted before.