从 CDS 实体中选择与从 CDS 数据库视图中选择

Selecting from a CDS entity versus from a CDS Database view

在SAP的ABAP CDS中,define view语句用于创建CDS视图。这个对象有一个 CDS 实体名称,这是它在编辑器和包中的显示方式,但它还有一个必须不同的 AbapCatalog.sqlViewName 注释。 The documentation of the define view syntax 有一些信息:

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.

它提到了一些其他差异,例如实体在 SAP 的数据字典工具(SE11、SE16)中不可用,以及在 strict mode 中总是从实体中选择 运行 但更重要的是是:

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.

当我 运行 都在一个简单的查询中时,我注意到从实体中选择时没有 MANDT 列,但是从CDS 数据库视图。

那么,开发人员在使用 CDS 视图时应牢记数据库视图和 CDS 实体之间的真正区别是什么?

您不应再查询 ABAP CDS 数据库视图并将查询限制为使用 ABAP CDS 实体。尽管在 NetWeaver 7.40 中可以查询数据库视图,但在更高版本中已弃用。所以不用担心数据库视图:-)

请参阅文档:Obsolete Access to CDS Views in Open SQL

To keep the behavior consistent and to use only the defined properties of a CDS view, only the name of the CDS entity should be used to access a CDS view.

Direct access to a CDS database view is forbidden in strict mode from Release 7.50.

关于客户端处理,您应该相应地关注 CDS 实体的客户端行为。 ABAP CDS Client Handling.

描述了不同的选项