Skip to content

ABAP Keyword Documentation →  ABAP Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Views →  ABAP CDS - DDL Statements 

ABAP CDS - DEFINE VIEW

Other versions: 7.31 | 7.40 | 7.54

Syntax


@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 CDS source code. A CDS is implemented using a query select_statement. The annotation AbapCatalog.sqlViewName must be specified before the view itself is defined using DEFINE VIEW. Further annotations view_annot1, view_annot2, ... can also be specified. This is optional.

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. 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 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 it can be 30 places in length.

Both names are in the namespace of the data types in ABAP Dictionary and must each be unique. The two names can be used in other 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 at operand positions of the view can be assigned to the positions when the view actual parameters are used.


Notes

  • The CDS database view of 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. Furthermore, this display does not provide all information. The CDS entity cds_entity cannot be displayed here.

  • In the DDL of the CDS and in ABAP, a CDS view can be addressed as a CDS database view CDS_DB_VIEW and as a CDS entity cds_entity. It is strongly recommended, however, that only the CDS entity is used.

  • Predefined annotations can be used to assign further technical and semantic properties to a view in ABAP Dictionary. User-defined annotations can be used to assign freely definable semantic properties to the entity.

  • If a CDS role is defined for a CDS entity using the DCL statement DEFINE ROLE, an implicit authorization check is performed when the CDS entity is accessed using Open SQL.

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

  • Every CDS view has its own CDS source code. The CDS source code in a CDS view is edited in a different editor from the CDS source code of CDS role or a CDS access policy. The ADT documentation describes how different types of source code are created.

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 Open 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.

@AbapCatalog.sqlViewName: 'DEMO_CDS_PRJCTN'
define view demo_cds_spfli
  as select from spfli
     { key spfli.mandt,
       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