Skip to content

ABAP Keyword Documentation →  ABAP Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Views →  ABAP CDS - DDL Statements →  ABAP CDS - DEFINE VIEW →  ABAP CDS - SELECT →  ABAP CDS - SELECT, select_list 

ABAP CDS - SELECT, element

Other versions: 7.31 | 7.40 | 7.54

Syntax


... { [@element_annot1] 
      [@element_annot2]
      ...
         [KEY] { { field
                 | path_expr [AS alias] }
               | { literal
                 | parameter
                 | aggregate
                 | 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 in ABAP CDS.

Alternative 1

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

Extras

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

2. ... KEY
3. ... AS alias

Effect

Specifying individual elements..

  • When the name field is specified directly, an element of a data source data_source of the current CDS view is defined as an element. The field name can be prefixed with the name of the data source or its alternative name. The prefix is separated using a period (.) . AS can be used to define an alternative element name alias.
  • When a path expression path_expr is specified, two cases arise:
  • If the path expression identifies an element, the target of the path expression is defined for evaluating an association as an element.
  • If, in the special case of a path expression, only the name of an association is specified, the association is published for use in other CDS views. A different CDS view that uses the current CDS view as a data source can evaluate the association in its path expressions. An association published in this way cannot be accessed in Open SQL.
AS can be used to define an alternative element name alias.
  • literal can be used to declare a literal. AS must be used to define an alternative element name alias.
  • parameter can be used to specify a parameter from the parameter list parameter_list. If AS is used, an alternative element name alias must be defined, which cannot be the name pname of the parameter.
  • aggregate, arith_exp, builtin_func, and case_exp can be used to specify aggregate expressions, arithmetic expressions, calls of predefined functions in the database, and case distinctions. The expressions and functions are evaluated when the CDS view is accessed in the database system. AS must be used to define an alternative element name alias.

Addition 1

... @element_annot ... @<element_annot

Effect

Specify 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 properties to an element in ABAP Dictionary. User-defined annotations can be used to assign freely definable semantic properties to the entity.

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. The key elements of the CDS entity are used to document the semantics of the data model. They are not evaluated as key elements when the CDS view is activated and in accesses when the program is executed.

More specifically, the key elements defined using KEY are ignored by the key of the CDS database view. Like in classic views, the key fields of the database view are derived implicitly from the key fields of the basis tables and the join conditions. If this is not possible, all fields of the database view are key fields.


Note

In SAP buffering, only the key fields of the CDS database view are relevant and not the key elements of the CDS entity defined using KEY. In the syntax check in Open SQL, the relevant factor is whether the name of the CDS entity is specified or the CDS database view.

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

  • cannot be a reserved component name. The reserved names that cannot be used are in the database table TRESE.

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. The alternative element names must be used instead of the actual name within the current CDS view and when the view is accessed, except after WHERE, GROUP BY, and HAVING. The actual name must be used in these cases.

Alternative 2

... $EXTENSION.*

Effect

Specifies all elements of an enhancement of the enhancement concept for ABAP Dictionary classic objects. 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 aggregate occur in the current SELECT list or if the current CDS view is a union set created using UNION.


Notes

  • $EXTENSION.* is specified independently of when an enhancement is made. It is also applied when a database table or a view is enhanced only after the activation of the CDS view.

  • The statement EXTEND VIEW can be used to enhance the current CDS view.

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 - element_annot