CDS Views
No Comments

Best Practices for SAP CDS Views

Close up view on violin's play.

Use the Virtual Data Model for CDS Views

follows

Use Type Annotations for Basic Views, Composite Views, and Consumption Views

Use the respective type annotation for basic, composite, and consumption views in the DDL file:

  • @VDM.viewType: #BASIC
  • @VDM.viewType: #COMPOSITE
  • @VDM.viewType: #CONSUMPTION
@VDM.viewType: #BASIC
define view I_BusinessPartner ... { 
	key BusinessPartner, 
	...
}

SAP uses the annotation @VDM.viewType for internal structuring and interpretation of the CDS views. For example, in the Fiori View Browser in S/4 HANA systems.

Use Naming Conventions for CDS views (THE SAP WAY)

The SQL View Name can have maximal 16 characters, and the CDS View name can have maximal 30 characters.

Use Z, Y, or the registered namespace of the company as the first character in every name to signal that it is a custom file and not an SAP file.

And when referring to SAP business entities reuse the field names defined by SAP. When creating own field names or when extending SAP delivered views then use as a prefix a YY or ZZ.

This is the way SAP names its CDS views. You can find an alternative way to name your CDS views below.

SQL View Name

<PREFIX><DESCRIPTION> – for example, ZIBPADDR.

The <PREFIX> consists of

  1. Y, Z or the registered namespace of the company,
  2. I (interface view – basic & composite views), C (consumption view), A (remote API view), P (private VDM view), E (extension include view), X (VDM view extension)

The <DESCRIPTION> is

  1. all written together,
  2. all in upper case letters,
  3. if the view is a value helper CDS view a VH at the end, for example, ZCBPADDRVH. A value helper CDS view is always a consumption view,
  4. if the view is a transactional object CDS view or a transactional consumption view a TP at the end, for example, ZCFOOTP.

CDS View Name

<PREFIX><Description> – for example, ZI_BPNameAddress.

The <PREFIX> consists of

  1. Y, Z or the registered namespace of the company,
  2. I (interface view – basic & composite views), C (consumption view), A (remote API view), P (private VDM view), E (extension include view), X (VDM view extension)
  3. an underscore _.

The <Description> is

  1. all written together,
  2. in CamelCase,
  3. if the view is a value helper CDS view a VH at the end, for example, ZC_BPNameVH. A value helper view is always a consumption view,
  4. if the view is a transactional object CDS view or a transactional consumption view a TP at the end, for example, ZC_FooTP.

Use Naming Conventions for CDS Views (NOT THE SAP WAY)

The SQL View Name can have maximal 16 characters, and the CDS View name can have maximal 30 characters.

Use Z, Y, or the registered namespace of the company as the first character in every name to signal that it is a custom file and not an SAP file.

And when referring to SAP business entities reuse the field names defined by SAP. When creating own field names or when extending SAP delivered views then use as a prefix a YY or ZZ.

In my opinion, there are better ways to name your CDS views than SAP does:

  • differentiate between basic and composite views
  • mark a value helper CDS view not with a suffix but with a prefix
  • mark transactional CDS view not with a suffix but with a prefix

At the latest when you add analytic CDS views you get the feeling that you need to come up with other naming conventions for your CDS views than how SAP handles it.

SQL View Name

<PREFIX><DESCRIPTION> – for example, ZIBPADDR.

The <PREFIX> consists of

  1. Y, Z or the registered namespace of the company,
  2. B (basic view), O (composite view), C (consumption view), A (remote API view), P (private VDM view), E (extension include view), X (VDM view extension)

The <DESCRIPTION> is

  1. all written together,
  2. all in upper case letters,
  3. if the view is a value helper CDS view a V right after the C for consumption view, for example, ZCVBPADDR. A value helper CDS view is always a consumption view,
  4. if the view is a transactional object CDS view or a transactional consumption view a T right after the B for basic, O for composite, or C for consumption view, for example, ZCTFOO.

CDS View Name

<PREFIX><Description> – for example, ZI_BPNameAddress.

The <PREFIX> consists of

  1. Y, Z or the registered namespace of the company,
  2. B (basic view), O (composite view), C (consumption view), A (remote API view), P (private VDM view), E (extension include view), X (VDM view extension)
  3. an underscore _.

The <Description> is

  1. all written together,
  2. in CamelCase,
  3. if the view is a value helper CDS view a V right after the C for consumption view, for example, ZC_BPNameVH. A value helper CDS view is always a consumption view,
  4. if the view is a transactional object CDS view or a transactional consumption view a T right after the B for basic, O for composite, or C for consumption view, for example, ZCT_Foo.

Use Naming Conventions for Analytical CDS Views (NOT THE SAP WAY)

The SQL View Name can have maximal 16 characters, and the CDS View name can have maximal 30 characters.

Use Z, Y, or the registered namespace of the company as the first character in every name to signal that it is a custom file and not an SAP file.

And when referring to SAP business entities reuse the field names defined by SAP. When creating own field names or when extending SAP delivered views then use as a prefix a YY or ZZ.

In my opinion, there are better ways to name your analytical CDS views than SAP does. Instead of suffixes such as Cube or Query rather prefixes such as C for a cube or Q for a query.

SQL View Name

<PREFIX><DESCRIPTION> – for example, ZFBMARA.

The <PREFIX> consists of

  1. Y, Z or the registered namespace of the company,
  2. FB (fact basic view), FO (fact composite view, DB (dimension basic view), DO (dimension composite view), CB (cube basic view), CO (cube composite view), or QC (query consumption view)

The <DESCRIPTION> is

  1. all written together,
  2. all in upper case letters

CDS View Name

<PREFIX><Description> – for example, ZFB_Mara.

The <PREFIX> consists of

  1. Y, Z or the registered namespace of the company,
  2. FB (fact basic view), FX (fact composite view, DB (dimension basic view), DO (dimension composite view), CB (cube basic view), CO (cube composite view), or QC (query consumption view)
  3. an underscore _.

The <Description> is

  1. all written together,
  2. in CamelCase

Most Recent Articles

Will SAP UI5 replace the SAP Web UI?

SAP Full Forms

More Similar Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu