Technology Blog Posts by Members
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
jeffrey_towell2
Participant
10,620

Introduction

This Quick Reference is a collection of new CDS functionality made available in ABAP 7.5x releases. This functionality is summarised in a way that will make sense to those familiar with SAP CDS. Links to the SAP Help  are also provided throughout to allow the reader to dive in deeper if desired. The version the functionality was released is also given to aid in determining if it is available in your system.

 

S/4HANA151116101709180919092020202120222023
ABAP7.507.517.527.537.547.557.567.577.58

Contents

  1. CDS View Entity

  2. CDS Abstract Entity
  3. CDS Custom Entity
  4. CDS Projection views
  5. CDS Access Controls

 

1. CDS View Entity (7.50)

Syntax

[@enity_annot1]
[@entity_annot2]
...
[@view_entity_annot1]
[@view_entity_annot2]
...
[DEFINE] [ROOT] VIEW ENTITY view_entity
        [parameter_list]
         AS select_statement [;]...

Description

CDS view entities are non DDIC-based views. While they were introduced in 7.50 the old DDIC-based views (DEFINE VIEW ddic_based_view) only became obsolete in 7.56.

 

Extensions

EXTEND VIEW ENTITY (7.55)

Makes it possible to add new view fields to existing CDS view entities and CDS projection views by using CDS view entity extensions.

EXTEND VIEW ENTITY cds_view_entity | projection_view
       WITH
            [association1
             association2 ...]
            { select_list_extension }
            [GROUP BY field1, field2, ...  ]
            [EXCEPT | INTERSECT | UNION [ALL]  { ... }] [;]

 

ANNOTATE ENTITY (7.53)

Define CDS metadata extensions(type:DDLX) for any CDS entities with the exception of CDS table functions.

@Metadata.layer: #CORE|#LOCALIZATION|#INDUSTRY|#PARTNER|#CUSTOMER
   [@entity_annot1]
   [@entity_annot2]
   ...
   ANNOTATE ENTITY cds_entity WITH
     [ parameter_list]
     { [element_list] }[;]

 

Set Operators

UNION (7.56)       

Now supported in CDS view entities.

EXCEPT (7.56) 

Returns all rows of a SELECT statement that are not part of the result sets of the following SELECT statements.

INTERSECT (7.56)

Returns all distinct rows that are included in all result sets of multiple SELECT statements.

 

Functions

GET_NUMERIC_VALUE (7.56)

Conversion Function. Returns the numeric value of a currency or quantity without its currency or unit key.

 

  key carrid,
  key connid,
  key fldate,
      @Semantics.amount.currencyCode: 'currency'
      price,
      currency,
      @Semantics.amount.currencyCode: 'currency'
      paymentsum,
      GET_NUMERIC_VALUE( paymentsum )  / GET_NUMERIC_VALUE( price )
                as number_of_bookings

 

CURR_TO_DECFLOAT_AMOUNT (7.56)

 Conversion Function. Converts the function argument(must have data type CURR and a currency key ) into a type DECFLOAT34.

 

  key id,
      cuky                              as currency,
      @Semantics.amount.currencyCode: 'currency'
      curr10_4                          as amount,
      @Semantics.amount.currencyCode: 'currency'
      CURR_TO_DECFLOAT_AMOUNT(curr10_4) as curr_conv

 

SUBSTRING (7.57)

Function enhanced to accept literals, fields, parameters, expressions, and built-in functions as arguments pos and len.

SUBSTRING(arg, pos, len)     Substring arg from the position pos with length len. 

 

LEFT and RIGHT (7.57)

Functions enhanced to accept  literals, fields, parameters, expressions, and built-in functions as argument len.

LEFT(arg, len)                String of the length len with the len left characters of arg (ignoring the trailing blanks).

RIGHT(arg,len)              String of the length len with the len right characters of arg (ignoring the trailing blanks).

 

Types

Typed Literals (7.56) 

Now supported in CDS view entities. Not supported in the ON condition of a CDS association.

 

{
  key id,
      abap.char'aaa   '       as char_trailing_blanks,
      abap.sstring'aaa   '  as sstring_trailing_blanks,

      abap.string'aaa   '    as string_trailing_blanks,
      'aaa'                               as untyped_literal   }
where
  numc1 = abap.numc'1' and
   datn < abap.datn'20200101'

 

CDS Calculated Quantity (7.56)

A new type that is the result of a calculation using amount and/or quantity fields.

 

Application Session Variables (7.57)

In form $session.vname

vname

Value when accessed

bs_instance_id

Instance ID of the current business service instance. The returned value has the data type SSTRING.

bs_zone_id

Zone ID of the current business service instance. The returned value has the data type SSTRING.

 

Input Parameters (7.57)

abap.string now supported.

 

ABAP Reports

RUTDDLS_MIGRATION_CANDIDATES (7.56) 

Evaluates whether a migration from a CDS DDIC-based view to a CDS view entity is possible.

 RUTDDLSV2MIGRATION (7.56) 

Migrates CDS DDIC-based views to CDS view entities.

RUT_WHERE_USE_SQLVIEW (7.57)

Lists all repository objects that use CDS-managed DDIC views.

 

Annotations

Table Buffering Annotation (7.57).

Defines whether table buffering is allowed for a CDS view entity or not.

@AbapCatalog.entityBuffer.definitionAllowed: true|false

 

CDS entity buffer (7.57)

The actual buffering type can be defined by a separate ABAP tuning object called a CDS entity buffer with the DDL statement:

DEFINE VIEW ENTITY BUFFER ON cds_view_entity
                   LAYER CORE
                       | LOCALIZATION
                       | INDUSTRY
                       | PARTNER
                       | CUSTOMER
                   TYPE SINGLE
                       | {GENERIC NUMBER OF KEY ELEMENTS number}
                       | FULL
                       | NONE

Table buffering can be defined differently for the layers core, localization, industry, partner and customer.

 

Other

DISTINCT (7.56)

Available for SELECT statements in CDS view entities. Works like ABAP SELECT.

 

Reusing Expressions (7.56)

Reuse expressions defined in the SELECT list in other operand positions of the same CDS view entity.

 

key id                                 as field1,
    concat($projection.field1, 'x')    as field_reuse,

 

WHERE clause (7.56)

Now supports arithmetic expressions and case expressions as operands.

 

define view entity DEMO_SALES_ORDER_WHERE
  as select from
    demo_sales_order
    association to demo_sales_bupa as _partner
      on $projection.id = _partner.id
    {
      key so_key,
          id,
          company_code,
          _partner.family_name
    }
    where
          _partner.family_name like    'S%'
      and length( _partner.family_name ) = abap.int1'4'
      and created_on between abap.dats'20200101' and abap.dats'20200401'
      and cast( _partner.birth_name as DEMO_BT_BIRTH_NAME
                preserving type )  =       abap.char'Meier'

 

 HAVING clause (7.56)

Now supports arithmetic expressions and case expressions as operands.

 

define view entity DEMO_CDS_VIEW_ENTITY_HAVING
  as select from sflight
  {
    concat_with_space(carrid, connid, 1) as ID,
    count(*)                             as col_count,
    seatsmax
  }
  group by
    carrid,
    connid,
    seatsmax
  having
    seatsmax > abap.int2'500'

 

Searched Case Expression (7.56)

Now supports arithmetic expressions and case expressions as operands.

 

define view entity demo_cds_searched_case_ve
  as select from
    spfli
    {
      key carrid,
      key connid,
          distance,
          distid,
          case
            when distance >= 2000 then 'long-haul flight'
            when distance >= 1000 and
                 distance <  2000 then 'medium-haul flight'
            when distance <  1000 then 'short-haul flight'
                                  else 'error'
          end as flight_type
    }
    where
      distid = 'MI'

 

2. CDS Abstract Entity (7.53)

Syntax

[@entity_annot1]
[@entity_annot2]
...
[DEFINE] [ROOT] ABSTRACT ENTITY abstract_entity
         [parameter_list]
          element_list[;]

Description

Works like a structure definition but nothing is created in DDIC and has annotations that can be evaluated with class CL_DD_DDL_ANNOTATION_SERVICE.

 

EXTEND ABSTRACT ENTITY (7.56)

Allows extension of existing abstract entity

EXTEND ABSTRACT ENTITY cds_abstract_entity WITH  { element_list_extension }

 

To-Parent Association Without ON (7.56) 

The ON condition can be left out of a ā€œto-parentā€ if the association target is also a CDS abstract entity.

 

define abstract entity DEMO_CDS_ABSTRACT_CHILD
{
  key key_field  : abap.char(1);
      data_field    : abap.int4;
      _to_parent  : association to parent DEMO_CDS_ABSTRACT_COMPOSITION  
                     on _to_parent.key_field = $projection.key_field;
           <- Last line can be omitted
}

 

 3. CDS Custom Entity (7.54)

Syntax

[@entity_annot1]
[@entity_annot2]
...
[@ObjectModel.query.implementedBy : 'class_name']
[DEFINE] [ROOT] CUSTOM ENTITY custom_entity
         [parameter_list]
          element_list[;]

Description

No DDIC entries created and has annotations that can be evaluated with class CL_DD_DDL_ANNOTATION_SERVICE.

Used in RAP as basis of unmanaged queries.

 

 EXTEND CUSTOM ENTITY (7.57)

Makes it possible to add new elements to existing CDS custom entities by using CDS custom entity extensions.

EXTEND CUSTOM ENTITY CustomEntity WITH { ElementListExtension }

 

4. CDS Projection Views

Syntax

[@entity_annot1]
[@entity_annot2]
...
[@proj_view_annot1]
[@proj_view_annot2]
...
DEFINE [ROOT] VIEW ENTITY projection_view
   [ PROVIDER CONTRACT provider_contract]               [From 7.56]
    AS PROJECTION ON cds_entity [AS alias_name]
   [association1 association2 ...                                [From 7.55]
   [redefined_assoc1 redefined_assoc2 ...]                    [From 7.56]
      { projection_list }
   [WHERE cds_cond]                                              [From 7.58 for Transactional Interfaces ]

Description

A special CDS view entity that is based on another CDS view entity (called projected entity). CDS projection views adapt a CDS data model for service-specific use cases.

 

Associations (7.55)

It is possible to add new, local, read-only associations association1, association2 to a projection view. Read-only associations in projection views can only be exposed but they cannot be used in path expressions to expose elements from new associations.

 

REDEFINE ASSOCIATION (7.56) 

For Projection views it is now possible to redefine an association. In this way, it is possible to modify an association from the underlying view. 

... REDEFINE ASSOCIATION [source.]_ProjAssoc [ filter] [AS _RedefinedName] redirection  ...

 

Provider Contracts

PROVIDER CONTRACT (7.56) 

For Projection views it is now possible to have a provider contract which specifies the scenario in which a CDS projection view is used.  Provider contract options available:

  • TRANSACTIONAL_QUERY (7.56)             [Default if not provided]
  • TRANSACTIONAL_INTERFACE (7.57)      [Use for Transactional Interfaces]
  • ANALYTICAL_QUERY (7.57)                     [Use for Transient View Entities]

 

CDS Transactional Query (7.56)

Uses DEFINE [ROOT] VIEW ENTITY AS PROJECTION ON  with  provider contract ā€œTRANSACTIONAL_QUERYā€.

Transactional queries are intended for modelling the projection layer of a RAP business object. A transactional projection view must always be part of a business object. That means it must either be a root entity itself, or it must be part of a composition tree that contains a root entity

 

CDS Transactional Interface (7.57)

Uses DEFINE VIEW ENTITY AS PROJECTION ON  with  provider contract ā€œTRANSACTIONAL_INTERFACEā€.

CDS transactional interfaces serve as stable public interface layer in a CDS data model. They are typically used in the context of the ABAP RESTful Application Programming Model to provide the basis for a RAP BO interface. 

WHERE  (7.58) condition allowed for Transactional Interfaces.

 

CDS Analytical Projection Views (7.57)

Uses DEFINE TRANSIENT VIEW ENTITY AS PROJECTION ON  with provider contract ā€œANALYTICAL_QUERYā€.

A CDS DDL that is intended for modeling analytical queries within a CDS data model. A CDS analytical projection view defines an analytical query in its element_list.

The projected entity cds_entity can be an analytical cube view(7.57) or an analytical dimension view(7.58). One base view can serve as a basis for multiple analytical projection views.

7 Comments