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, select_list → 

ABAP CDS - SELECT, element

Syntax

... { [@element_annot1]
      [@element_annot2]
      ...
        [KEY] { { field
                | path_expr [AS alias] }
              | { literal
                | parameter
                | session_variable
                | aggr_expr
                | arith_expr
                | builtin_func
                | case_expr
                | cast_expr AS alias }
      [@<element_annot1]
      [@<element_annot2]
      ... }
  | { $EXTENSION.* } }  ...


Alternatives:

1. ... field|path_expr|literal|parameter|...

2. ... $EXTENSION.*

Effect

Defines an element of a SELECT list of a CDS view. The names of the elements of a SELECT list must be unique.

Alternative 1

... field|path_expr|literal|parameter|...


Extras:

1. ... @element_annot ... @<element_annot

2. ... KEY

3. ... AS alias

Effect

Specifies individual elements.

AS can be used to define an alternative element name alias.

If an association is published in the SELECT list using a path expression path_expr, all fields of the source data source that occur in the ON condition must also be specified as elements of the SELECT list. If a path expression contains more than one association, this type of element must be listed as a path expression closed by the field.

Notes

Example

The following CDS view opens its own association _spfli and the association _sflight published by its target data source demo_cds_assoc_spfli. The fields of the source data source, which are used in the ON conditions of the associations, are specified in the SELECT list. In the case of the association published using _spfli._sflight, path expressions _spfli.carrid and _spfli.connid must be used accordingly. The element scarr occurs twice, which means that an alternative element name must be defined using AS.

@AbapCatalog.sqlViewName: 'DEMO_CDS_PUBASC'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_publish_assoc
  as select from
    scarr
    association to demo_cds_assoc_spfli as _spfli on
      scarr.carrid = _spfli.carrid
    {
      _spfli,
      scarr.carrid as scarr_carrid,
      _spfli._sflight,
      _spfli.carrid,
      _spfli.connid
    }
  


Addition 1

... @element_annot ... @<element_annot

Effect

Specifies annotations for the element. The annotations can be specified before the element using @element_annot or after the element using @<element_annot.

Note

An annotation can be used to assign further technical and semantic attributes to an element in ABAP Dictionary. Framework-specific annotations can be used to give the element specific semantic attributes for other SAP frameworks.

Addition 2

... KEY

Effect

KEY is used to define the current element as the key element of the current CDS entity. Any elements of a SELECT list can be defined as key elements that are placed without gaps at the start of the list.

The key elements of the CDS entity are evaluated as follows if they are used as a data source of a SELECT statement in Open SQL.

By default, the key elements of the CDS entity are used to document the semantics of the data model. The addition KEY is then ignored when the CDS view is activated and when other accesses are performed in program executions.

The default setting can be overridden using the view annotation AbapCatalog.preserveKey:

Notes

Addition 3

... AS alias

Effect

Defines an alternative element name for the current element. The alternative element name replaces the actual name of the element from the data source data_source. The view field is created under the alternative element name in the CDS database view. Accordingly, the alternative element name must comply with the rules for names of view fields of database views, as well as the general naming rules for names:

which means that it must also meet the

This is only checked, however, if there is no explicit name list that overrides the alternative element names.

Alternative element names can be used in the current CDS view to grant unique names for identically named elements from different entities of the data source. When the current CDS view is accessed, the alternative element names must be used instead of the actual name. Alternative element names cannot be used within the CDS view, with one exception: alternative element names can be specified directly or after $projection in the ON condition of an association.

Alternative 2

... $EXTENSION.*


Effect

Specifies all elements of an enhancement of the enhancement concept for classic objects in ABAP Dictionary. If $EXTENSION.* is specified as an element, all fields that occur in an enhancement of a database table or a classic view in ABAP Dictionary in the data source data_source become elements of the current CDS view automatically.

If $EXTENSION.* is specified, it works only for the current CDS view. It is not applied to other CDS views in whose data source the current CDS view is used or to CDS views in the data source of the current CDS view.

$EXTENSION.* cannot be specified if aggregate expressions aggr_expr occur in the current SELECT list or if the current CDS view is a union set created using UNION.

Notes

Example

The data source of the CDS view sales_order is an inner join of the database tables snwd_bpa and snwd_so and contains three directly defined elements sales_order_id, business_partner_id, and company_name and (because $EXTENSION.* is specified) all fields that exist due to enhancements in the database tables snwd_bpa and snwd_so. The alternative name partner is defined for the database snwd_bpa and is used in the ON condition. The names of the elements sales_order_id and business_partner_id are alternative element names. The element sales_order_id is defined as a key element.

@AbapCatalog.sqlViewName: 'SALES_ORDER_VW'
define view sales_order as
  select from snwd_bpa as partner
    inner join
      snwd_so on partner.node_key = snwd_so.buyer_guid
  { key so_id as sales_order_id,
        bp_id as business_partner_id,
        company_name, //from snwd_bpa
        $extension.* }


Continue
ABAP CDS - SELECT, element_annot