Skip to Content
Technical Articles
Author's profile photo Andrea Schlotthauer

New type of CDS entity available: CDS projection views

Since ABAP release 7.76, there’s a new CDS entity available: the CDS projection view. This blog post explains what a CDS projection view is, what it does, and which components it consists of.

Background on CDS views

There are currently three types of CDS views available: CDS view entities (DEFINE VIEW ENTITY), CDS DDIC-based views (DEFINE VIEW), and CDS projection views. CDS projection views have been designed similarly to CDS view entities. For example, they don’t have an SQL view attached. For further details on the different types of CDS views, see this blog post post about CDS view entities.

What is a CDS projection view and what does it do?

CDS projection views serve a special purpose within the ABAP RESTful Application Programming Model (RAP). They define interfaces on the basis of existing CDS view models. A projection view is always based on exactly one existing CDS view entity or CDS DDIC-based view and exposes a subset of its elements, which are required for a specific business service. A CDS projection view is a CDS view defined using DEFINE VIEW ENTITY AS PROJECTION ON.

The following image shows the role that CDS projection views play in making a business service. Because CDS projection views are always based on existing CDS view models, they can’t directly access a database table.

The image is an adaptation of the image published in the Developer Guide for the ABAP RESTful Application Programming Model.

Syntax of a CDS projection view

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Exposure of SO Projection View'
define root view entity DEMO_SALES_PV_SO_EXP
  as projection on DEMO_SALES_CDS_SO
  {
    key     so_key,
            id,
            lifecycle_status as LifecycleStatus,
            buyer_id         as BuyerId,
            created_by,
            @ObjectModel.virtualElementCalculatedBy:
                        'ABAP:CL_DEMO_SALES_VIRT_ELEM_EXIT'
    virtual expiry_date : abap.dats(8),
            _Buyer : redirected to DEMO_SALES_PV_BUPA_EXP
  }

 

The example shows the syntax of a CDS projection view:

  • Annotations (entity annotations, view annotations, and element annotations) are inherited from the projected entity by default, but they can be overwritten. You can also add new annotations.
  • A projection view is defined using DEFINE [ROOT] VIEW ENTITY AS PROJECTION ON.
  • The data source of a CDS projection view can be either a CDS view entity without parameters, or a CDS DDIC-based view without parameters (this is still supported for downward compatibility).
  • In the element list, fields and associations from the underlying projected entity are exposed.
  • New calculated fields can be added with the keyword VIRTUAL (more details below).
  • All elements can be given a new alias name.
  • Associations from the projected entity can either be exposed directly or redirected to a new target (more details below).

Associations in CDS projection views

When CDS projection views were first published, it was not possible to define new associations. This feature was later introduced with ABAP release 7.80. The newly defined associations in CDS projection view have limitations though: they can be defined and exposed in the element list, but they cannot be used to include fields from the association target in the current projection view. Associations in CDS projection views can be used only to model new relationships that can be interpreted by consumer frameworks, such as SADL.

Virtual elements in CDS projection views

Virtual elements are not part of the projected entity – they are newly added elements that are calculated by frameworks, such as SADL, during runtime. Therefore, virtual elements cannot be read with ABAP SQL, ABAP SQL just returns initial values.

For example, in the ABAP RESTful Application Programming Model, a virtual element can be connected to an ABAP class that implements a special virtual element interface by using the framework-specific annotation ObjectModel.virtualElement.CalculatedBy. In that case the value of the virtual element is calculated during runtime by the SADL framework.

In the syntax above, the class CL_DEMO_SALES_VIRT_ELEM_EXIT is used to calculate the expiry date of a sales order item.

For more information, see Using Virtual Elements in CDS Projection Views.

Redirecting exposed associations in CDS projection views

You can expose a CDS association of the projected entity in the element list of a CDS projection view. If the target of the association does not change in the projection layer, the association can be exposed directly. If the target entity is also projected, the association should be redirected to the target projection view, as shown for the association _Buyer in the example above. There are three different keywords available for redirection, depending on the type of association:

  • REDIRECTED TO: redirects a simple association.
  • REDIRECTED TO COMPOSITION CHILD: redirects a composition. The redirected association must be a CDS composition.
  • REDIRECTED TO PARENT: redirects a to-parent association. The redirected association must be a to-parent association.

The image below shows how several views belonging to a business object are projected and redirected.

Redirected%20compositions%20in%20a%20CDS%20projection%20view

Redirected compositions in a CDS projection view

The image is an adaptation of the image published in the Developer Guide for the ABAP RESTful Application Programming Model.

Outlook

Do CDS projection views remind you of consumption views? That’s right: CDS projection views are the RAP pendant to consumption views, and new scenarios within this framework will be designed using CDS projection views. The existing consumption views will still be available, but fewer new ones will be created.

More development on CDS projection views is being done. Soon there’ll be different types of CDS projection views available: general, transactional, and analytical projection views.

To find out more, see our documentation:

 

 

Assigned tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Samir Dutta
      Samir Dutta

      Excellent feature.

      Thanks Andrea.

       

       

      Regards
      Samir

      Author's profile photo Ali Özgec
      Ali Özgec

      Hi Andrea,

      thank you for the post. Can you please tell me if this feature available in s/4 hana 2020 release?

      thanks in advance.

      Best regards,

      Ali Özgeç

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer
      Blog Post Author

      Hi Ali,

      yes CDS projection views are available on-premise starting with S/4HANA 1909. They were first shipped with ABAP platform cloud 1905.

      Best,

      Andrea

      Author's profile photo Guru Ayarekar
      Guru Ayarekar

      Hi Andrea,

      Thanks for the post.

      How to check( find out )ABAP version associated with the release.

      Thanks in advance.

      Best regards,

      Guru Ayarekar

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer
      Blog Post Author

      Hi Guru Ayarekar,

      here's a mapping of on-premise releases: ABAP Keyword Documentation (sap.com). This is the only external resource available.

      If you're asking about ABAP release 7.76, which is mentioned in this blog, here's a mapping from an internal resource:

      Changes%20in%20Releases%207.7x

      Changes in Releases 7.7x

       

      Hope this helps.

      Best,

      Andrea

      Author's profile photo Minh Tri Nguyen
      Minh Tri Nguyen

      I get a weird error message "You don't have a right to view this website", when I open the Developer Guide for the ABAP RESTful Application Programming Model. Please check and advise

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer
      Blog Post Author

      Sorry, my bad. I've updated the links to the Developer Guide for the ABAP RESTful Application Programming Model and they should work now.

      Thanks for notifying.

      Author's profile photo Sebastien Phan
      Sebastien Phan

      Hi Andrea,

       

      interesting post, I just take a chance here: are the projection views or entity views support propagation of access layer? i.e. if I have a CDS view that uses an underlying CDS with authority check in access layer?

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer
      Blog Post Author

      Hi Sebastien,

      your question is whether access control specified using the annotation AccessControl.authorizationCheck is inherited in a CDS projection view, correct?

      The answer is no, access control is not inherited in CDS projection views. This is described in the ABAP Keyword documentation in the topic about annotations in CDS projection views.

      Quote:

      • "Projection views inherit the field and association annotations of the projected entity. View annotations are not inherited and must be specified anew, if required."

      AccessControl is a view annotation and therefore, it is not inherited and must be specified anew.

      Best,

      Andrea

      Author's profile photo Andile Khanyile
      Andile Khanyile

      Hi Andrea and colleagues,

      Is it possible to create a projection view for a consumption cds view with input parameters?

      I have created a projection view on standard CDS view 'C_OverdueAcctRbls' in order to then add additional fields as virtual elements.  However when I activate my projection view I get error messages stating that the entity 'C_OverdueAcctRbls' requires input parameter '<p_param1>' ... '<p_param2>'  ...  etc...

      How can I map the input paramers to the standard CDS view in my projection view?

      I hope to hear from you soon.

      Thank you.

       

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer
      Blog Post Author

      Hi Andile Khanyile,

      the syntax for passing input parameters in CDS projection views is as follows:

      ...

      define root view entity ...

      as projection on DEMO_CDS_SCARR_FROM_ABAP_CLASS( <param1> : <value>, <param2> : <value>, ... )

      {

      ...

      }

      Please note the following:

      C_OverdueAcctRbls is an analytical query and it is not recommended to build views on analytical queries. The reason is that analytical queries are not intended to be run on HANA database.

      It would be advisable to build your query on I_OverdueAccountsReceivables directly. However, analytical projection views are currently under construction and your query on I_OverdueAccountsReceivables would need to be a CDS view or CDS view entity.

      Also, please note that C_OverdueAcctRbls and I_OverdueAccountsReceivables are not released under C1-stability contract. That means that the interface might be subject to incompatible changes in the future.

      Best

      Andrea

      Author's profile photo Andile Khanyile
      Andile Khanyile

      Hi Andrea,

      Thanks a lot for the comprehensive feedback.

      I will continue exploring my options in line with your suggestions and take the best approach to meet the business requirements.

      Take care & keep well!