ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Reads → UNION → UNION Examples
SELECT, Union of CDS View with Input Parameters
This example demonstrates a union of a CDS view with input parameters.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA:
from_distance TYPE s_distance VALUE 0000,
to_distance TYPE s_distance VALUE 1000.
cl_demo_input=>new(
)->add_field( CHANGING field = from_distance
)->add_field( CHANGING field = to_distance
)->request( ).
SELECT carrid, connid, cityfrom, cityto, distance, distid
FROM demo_cds_parameters( p_distance_l = @from_distance,
p_distance_u = @to_distance,
p_unit = 'MI' )
UNION
SELECT carrid, connid, cityfrom, cityto, distance, distid
FROM demo_cds_parameters( p_distance_l = @from_distance,
p_distance_u = @to_distance,
p_unit = 'KM' )
ORDER BY distid, carrid, connid
INTO TABLE @DATA(result).
cl_demo_output=>display( result ).
Description
This example uses two SELECT
statements joined using UNION
to access the following
CDS view:
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions
@EndUserText.label: 'Demo für Parameter-View'
define view demo_cds_parameters
with parameters
p_distance_l :s_distance,
p_distance_u :s_distance,
p_unit :s_distid
as select from
spfli
{
key carrid,
key connid,
cityfrom,
cityto,
distance,
distid
}
where
distid = :p_unit
and distance between :p_distance_l and :p_distance_u;
This fills the input parameter p_unit with different values.