首页 > 解决方案 > 如何在 ABAP CDS 视图中获取当前年份

问题描述

有没有办法获取当前时间戳或当前日期?SQL 语法是date.now(),但它在 ABAP CDS 中不起作用。有没有没有参数的解决方案?

标签: abapcds

解决方案


在 7.50 中,您拥有tstmp_current_utctimestamp(). 它可用于与其他时间戳进行比较,从而需要转换典型的日期和时间字段。例子:

// As our system is set to UTC already, these cast and calculation are OK awaiting ABAP 7.51. Add a day if time is 24:00.
case resb.bdztp when '240000' 
                then cast( cast( cast( concat( DATS_ADD_DAYS( resb.bdter, 1, 'NULL'), '000000' ) as abap.numc(14) ) as abap.dec( 15, 0 ) ) as timestamp )
                else cast( cast( cast( concat( resb.bdter, resb.bdztp )                          as abap.numc(14) ) as abap.dec( 15, 0 ) ) as timestamp )
end as RequirementDateTimeUTC,

消耗:

// Seconds since Requirement Date & Time for view isOverdue. 
tstmp_seconds_between( resb.RequirementDateTimeUTC, tstmp_current_utctimestamp(), 'NULL') as SecondsSinceReqDateTimeUTC,

推荐阅读