ABAP CDS - DEFINE VIEW
@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 information specified in the 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 that can be assigned to the positions when the view actual parameters are used.
Notes
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.
[@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.
The information specified in the 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 that 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 a SADL query.
- 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.
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 }
********************************ROHINI KUMAR*********************************
Please support my work : sap.rohini988@gmail.com LinkedIn Link : https://www.linkedin.com/in/rohini-kumar-14647a13a/
********************************************************************************
Comments
Post a Comment