在ABAP CDS DDL SQL视图中,如果所有字段都被定义为主键,则需要将其中一个或多个字段设置为非主键。以下是一个示例代码段,将“material”字段设置为非主键:
@AbapCatalog.sqlViewName: 'ZSQL_VIEW' @AbapCatalog.compiler.compareFilter: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Materials with Sales Data' define view Z_MATERIAL_SALES_DATA as select from mara association [0..1] to Z_SALES_DATA as _Sales on $projection.material = _Sales.MaterialKey { key material, key _Sales.Year, key _Sales.Month, salesQty, salesAmount, currency }
在此示例中,“material”字段是键字段,因为它被标记为“key”。要将其设置为非键字段,请将“key”关键字从此字段中删除。
@AbapCatalog.sqlViewName: 'ZSQL_VIEW' @AbapCatalog.compiler.compareFilter: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Materials with Sales Data' define view Z_MATERIAL_SALES_DATA as select from mara association [0..1] to Z_SALES_DATA as _Sales on $projection.material = _Sales.MaterialKey { material, key _Sales.Year, key _Sales.Month, salesQty, salesAmount, currency }
在上面的代码示例中,“material”字段已不再是主键字段。