Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Data Definitions →  ABAP CDS - DDL for Data Definitions 

ABAP CDS - DEFINE VIEW

Other versions: 7.31 | 7.40 | 7.54

Syntax


[@entity_annot1] 
[@entity_annot2]
...
@AbapCatalog.sqlViewName: 'CDS_DB_VIEW'
[@view_annot1]
[@view_annot2]
...
[DEFINE] VIEW cds_entity
        [name_list]
        [parameter_list]
         AS select_statement [;]

Effect

Defines a CDS view in the CDS DDL. A CDS view is implemented using a query select_statement. The annotation AbapCatalog.sqlViewName must be specified before the view itself is defined using DEFINE VIEW. Further optional annotations entity_annot1, ..., view_annot1, ... can also be specified.

Two objects are created for a CDS view (of the ABAP CDS) that is defined using DEFINE VIEW. A name must be specified for each of the two objects:

  • The name CDS_DB_VIEW of the CDS database view must be specified in quotation marks after the annotation @AbapCatalog.sqlViewName. This view is the technical foundation of the CDS view in ABAP Dictionary. The usual rules for ABAP Dictionary views apply to this name and it is not case-sensitive (it is transformed internally into uppercase letters). The associated SQL view is created under this name on the database. The name given to the database view can no longer be changed after the CDS view is transported into a follow-on system.
  • The name cds_entity of the CDS entity is defined after the keywords DEFINE VIEW (DEFINE is optional). No quotation marks need to be specified. This name follows the rules of the CDS database view, but can have 30 characters. The CDS entity represents all properties of the CDS view.

Both names are in the namespace of the global data types in ABAP Dictionary and of the global object types in the class library and must each be unique. The name cds_entity of the CDS entity can be used in other CDS DDL statements or in ABAP programs to access the CDS view.

The information specified in name_list can be used to define the names of the elements of the view in a name list. parameter_list can be used to assign input parameters to the view. These input parameters can be specified in operand positions of the view and can be assigned actual parameters when the view is used.


Notes

  • The CDS database viewof a CDS view defined using DEFINE VIEW can be displayed by entering the name CDS_DB_VIEW in the ABAP Dictionary tool in ABAP Workbench. However the view cannot be edited here. Furthermore, this display does not provide all information. The CDS entity cds_entity cannot be displayed here.

  • The CDS database view CDS_DB_VIEW can also be accessed directly in the CDS DDL and in ABAP. It is strongly recommended, however, that only the CDS entity is used, since only this entity covers all properties of the CDS view. This makes the use of the CDS database view in ABAP SQL obsolete.

  • ABAP annotations can be used to assign further technical and semantic attributes to a view in ABAP Dictionary. Framework-specific annotations can be used to give the element specific semantic attributes for other SAP frameworks.

  • If a CDS entity is accessed using an ABAP SQL SELECT statement and the name cds_entity, the syntax check is performed in strict mode, which handles the statement more strictly than the normal syntax check.

  • The DDL source code of a CDS view does not need to have the same name as the CDS entity, but it is advisable to use this name.

  • After a piece of DDL source code is transported, the combination of its name and the name of the CDS view defined in it and its CDS database view is defined and can no longer be modified by being renamed.

  • The programming of CDS views using the DDL of the Core Data Services is one of the tasks included in the implementation of data models in ABAP Dictionary and is not usually the responsibility of regular ABAP application programmers. Once created, CDS views are used in ABAP programs using ABAP SQL read statements and must be stable enough to allow this.

Example

The following CDS view works in exactly the same way as the classic projection view DEMO_SPFLI. The program DEMO_CDS_PROJECTION uses SELECT to access the view. Unlike when the classic database view DEMO_SPFLI is accessed, no client column is returned when the CDS entity DEMO_CDS_SPFLI is accessed. The CDS database view DEMO_CDS_PRJCTN returns the client column too.

@AbapCatalog.sqlViewName: 'DEMO_CDS_PRJCTN'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_spfli
as select from
spfli
{
key spfli.carrid,
key spfli.connid,
spfli.cityfrom,
spfli.cityto
}    

Continue

ABAP CDS - DEFINE VIEW, view_annot

ABAP CDS - DEFINE VIEW, name_list

ABAP CDS - DEFINE VIEW, parameter_list

ABAP CDS - SELECT