SAP NetWeaver AS ABAP Release 751, ©Copyright 2017 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions → ABAP CDS - DDL for Data Definitions → ABAP CDS - DEFINE VIEW → ABAP CDS - SELECT → ABAP CDS- SELECT, clauses →ABAP CDS - SELECT, UNION
Syntax
... UNION [ALL] select_statement ...
Effect
Creates the union of rows in the results sets of two SELECT statements of a CDS view. A prerequisite is that the structures of the results sets are compatible. This means that the results sets must have the same number of elements and that the pairs of elements in each position have a compatible data type. If no name list is specified, the element names of the result sets must match.
A union results set can itself be the left side of a further union. The properties of the union results set are defined as follows:
A CDS view in which union sets are formed with UNION can expose associations. An association must be defined and exposed in the same way in all SELECT statements joined with UNION. That is, associations that are published in the respective SELECT lists must appear in all SELECT statements joined with UNION and the following requirements must be met:
These rules also apply if an association is defined in a data source of a SELECT statement and is exposed by the current statement. From outside, the associations with the same name that are published in the individual SELECT lists act like an association published by the union set. There are no restrictions on associations that are not published in the SELECT lists.
Notes
Examples
Union set without name list. The element names of the SELECT lists must match.
Union set with name list. The element names of the SELECT lists do not need to match.