时间戳字段上的 ABAP CDS COUNT DISTINCT

ABAP CDS COUNT DISTINCT on Timestamp field

我在 TIMESTAMP 字段上使用带有 DISTINCT 的 COUNT 时遇到问题。以下是我的 CDS 视图,请帮忙。 我想在 ConfirmedDate 字段上输入 COUNT。

 @AbapCatalog.sqlViewName: 'ZXEWMIWT'
 @AbapCatalog.compiler.compareFilter: true
 @AbapCatalog.preserveKey: true
 @AccessControl.authorizationCheck: #CHECK
 @EndUserText.label: 'Interface View for Warehouse Task detail'
 @OData.publish: true
// I* type:ddls

define view ZXEWMI_WT as select from /scwm/ordim_c as ORDIM_C {
    key ORDIM_C.lgnum as WarehouseNo,
    @UI.selectionField: [{ position: 1 }]
    @UI.lineItem: [{ position : 1 }]
    ORDIM_C.processor as Processor,
    @UI.lineItem: [{ position : 2 }]
    //count(distinct ORDIM_C.confirmed_at) as sum_wt

    **tstmp_to_dats( ORDIM_C.confirmed_at,
    abap_system_timezone( $session.client,'NULL' ),
    $session.client,
    'NULL' ) as ConfirmedDate**

}where processor <> '' 
group by lgnum, processor, confirmed_at;

您在字段 ORDIM_C.confirmed_at 中似乎有精确到毫秒的时间戳,但您想按天对结果进行分组。

不幸的是,GROUP BY 只允许您按输入 table(s)/view(s) 中的列进行分组。它不能用于计算列。

但是您可以做的是首先创建一个单独的 CDS 视图,它为您提供 table /scwm/ordim_c 的字段并将时间戳转换为日期,然后查询该视图。

视图 1:

define view Z_ORDIM_C_WITH_DAY as 
select from /scwm/ordim_c as ORDIM_C {
    key ORDIM_C.lgnum as WarehouseNo,
    ORDIM_C.processor as Processor,
    tstmp_to_dats( ORDIM_C.confirmed_at,
    abap_system_timezone( $session.client,'NULL' ),
    $session.client,
    'NULL' ) as ConfirmedDate    
}

视图 2:

define view ZXEWMI_WT as 
select from Z_ORDIM_C_WITH_DAY {
    key WarehouseNo,
    @UI.selectionField: [{ position: 1 }]
    @UI.lineItem: [{ position : 1 }]
    Processor,
    @UI.lineItem: [{ position : 2 }]
    count( * ) as sum_wt
    ConfirmedDate    
}
where processor <> ''
group by WarehouseNo, Processor, ConfirmedDate;