Ansicht
Dokumentation

ABENCDS_SELECT_LIST_ENTRY_V1 - CDS SELECT LIST ENTRY V1

ABENCDS_SELECT_LIST_ENTRY_V1 - CDS SELECT LIST ENTRY V1

ABAP Short Reference   General Material Data  
This documentation is copyright by SAP AG.
SAP E-Book

- DDIC-Based View, SELECT, element

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


Effect

Defines an element of a SELECT list of a . The names of the elements in a SELECT list must be unique and they are in the same namespace as the parameters of the view.

Alternative 1

... expose_assoc$|element$|path_expr$|literal$|parameter$|...


Additions

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

2. ... KEY

3. ... AS alias

Effect

Specifies individual elements in the SELECT list of a .

  • When the name element 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.
  • path_expr.element specifies an element element of the association target of the last CDS association of the path expression path_expr. The element defined in this way is part of the result set of the CDS view, a field of the CDS-managed DDIC view, and a component of a type defined in ABAP with respect to the CDS view. If no alternative element name alias is defined, and there is no name list, the element name is defined by the name of the element named by the path expression.
  • literal can be used to declare a literal. AS must be used to define an alternative element name alias. The literal can be prefixed with the name of a domain.
  • 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.
  • session_variable can be used to specify a session variable. AS must be used to define an alternative element name alias.
  • aggr_expr, arith_expr, builtin_func, and case_exp can be used to specify aggregate expressions, arithmetic expressions, calls of built-in functions, and case distinctions. The expressions and functions are evaluated by the database system when the CDS view is accessed. An alternative element name alias must be defined with the keyword AS, unless there is a name list.

Elements with the type CHAR can have a maximum of 1333 characters. Elements with the type LRAW or LCHR must be at the end of the view. Only one such element is allowed per view. Furthermore, a field of type INT2 or INT4 must stand directly in front of such an element, representing the maximum length of the element.

Example

SELECT list with all possible elements.

@AbapCatalog.sqlViewName: '...'
define view ...
  with parameters
    p_delay :abap.int4
  as select from
    spfli
    association to scarr as _scarr on
      _scarr.carrid = spfli.carrid
    {
      carrid,
      _scarr.carrname,
      '...'                                   as text,
      :p_delay                                as delay,
      $session.user                           as usr,
      count( * )                              as cnt,
      fltime + :p_delay                       as fltime_delayed,
      concat(concat('"',_scarr.carrname),'"') as carrname_quoted,
      case when fltime  60  then 'short'
           when fltime > 300 then 'long'
           else 'medium'
      end                                     as duration,
      cast(connid as int4)                    as connid_number
    }
    group by
      carrid,
      connid,
      _scarr.carrname,
      fltime


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.

Notes

  • An annotation can be used to assign further technical and semantic attributes to an element for evaluation by the ABAP runtime framework. Framework-specific annotations can be used to give the element specific semantic attributes that are evaluated by other SAP frameworks.
  • With respect to the element annotations, publications of a CDS association association are handled like any regular element. When a CDS association defined in a different CDS view is exposed, the annotations of preceding publications are inherited when annotations are evaluated using the class CL_DD_DDL_ANNOTATION_SERVICE.

Addition 2

... KEY

Effect

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

The keys you define in your CDS view only document the semantics of the data model. The addition KEY doesn't have any effect when the CDS view is activated and when other accesses are performed during program executions.

This default setting that keys have no effect can be overridden using the view annotation AbapCatalog.preserveKey:

  • If the value true is specified for this annotation, the key elements defined using KEY are also used as keys of the CDS-managed DDIC view.
  • If this annotation is not specified or specified with the value false, the key elements defined using KEY don't affect the key of the CDS-managed DDIC view. Like in DDIC database views in ABAP Dictionary, the key fields of the CDS-managed DDIC 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 DDIC database view are key fields.

Notes

  • For table buffering, the key fields of the CDS-managed DDIC view are always the decisive key fields.
  • In the syntax check in , the key elements used depend on whether the name of the CDS entity or the name of the CDS-managed DDIC view is specified (with the latter being obsolete).

Example

The following CDS view defines two elements as key elements:

Since those are not the same as the key fields of the underlying database table SPFLI, the result set of the view can contain duplicate entries in respect to the key elements. Program DEMO_CDS_ENITITY_KEY shows the result of an ABAP SQL access to the view. The key elements are evaluated by the addition ORDER BY PRIMARY KEY, but apart from that, the key elements have no effect. When trying to select into a hashed table that uses the key elements for its unique key, a runtime error will occur most probably.

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-managed DDIC view. Accordingly, the alternative element name must comply with the rules for names of view fields of DDIC database views, as well as the general naming rules for names:

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 a CDS association.

Note

In particular, an alternative element name cannot be used as the operand of an expression.

Alternative 2

... $EXTENSION.*

Effect

Specifies all elements of an enhancement in the enhancement concept for dictionary objects. If specified, $EXTENSION.* inserts (in this place) all fields of all customizing includes, append structures, and DDIC append views that exist in the current system for the DDIC database tables or DDIC views and which occur as a data source data_source in the current CDS view. $EXTENSION.* is ignored for CDS views used as a data source and extended using EXTEND VIEW.

If specified, $EXTENSION.* is applied to the current CDS view only. 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

  • $EXTENSION.* is specified independently of when an enhancement is made. It is also applied when a DDIC database table or a DDIC view is enhanced only after the activation of the CDS view.
  • The statement EXTEND VIEW can be used to extend the current CDS view.

Example

The data source of the CDS view sales_order is an inner join of the DDIC 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 DDIC 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.* }

Example

The following view accesses the CDS view DEMO_CDS_ORIGINAL_VIEW, which is extended in the example for EXTEND VIEW. $EXTENSION.* is ignored, if specified.

The following view, on the other hand, accesses the CDS-managed DDIC view DEMO_CDS_ORIG of DEMO_CDS_ORIGINAL_VIEW (not recommended). If specified, $EXTENSION.* includes both fields of the DDIC append view that extends the DDIC database view.

@AbapCatalog.sqlViewName: 'DEMOCDSEXT2'
define view demo_cds_extension2
   as select from
    demo_cds_orig
    {
      key carrier,
      key flight,
      $extension.*
    }






TXBHW - Original Tax Base Amount in Local Currency   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.

Length: 28439 Date: 20240425 Time: 042348     sap01-206 ( 295 ms )