简体   繁体   English

如何在 ABAP CDS 视图中获取当前年份

[英]How to get current year in ABAP CDS view

Is there any way to get current timestamp or current date?有没有办法获取当前时间戳或当前日期? SQL syntax is date.now() but it doesn't work in ABAP CDS. SQL 语法是date.now()但它在 ABAP CDS 中不起作用。 Is there any solution without parameters?有没有没有参数的解决方案?

In 7.50 you have tstmp_current_utctimestamp() .在 7.50 中,您有tstmp_current_utctimestamp() It may be used to compare with other timestamps, leading to a need to convert typical date and time fields.它可用于与其他时间戳进行比较,从而需要转换典型的日期和时间字段。 Example:例子:

// 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,

Consumption:消耗:

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

The session variable $session.system_date is used in a CDS view to provide direct access to the current system date. session 变量$session.system_date在 CDS 视图中用于提供对当前系统日期的直接访问。

There is not yet a session variable for the current system time and a CDS view can be given an appropriate input parameter instead.当前系统时间还没有 session 变量,可以为 CDS 视图提供适当的输入参数。 The special annotation @Environment.systemField makes it possible to pass the value of the ABAP system field sy-uzeit to a parameter of this type.特殊注解@Environment.systemField可以将ABAP 系统字段sy-uzeit的值传递给这种类型的参数。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM