Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current year in ABAP CDS view

Tags:

abap

cds

Is there any way to get current timestamp or current date ? SQL syntax is date.now() but it doesn't work in ABAP CDS. Is there any solution without parameters ?

like image 713
Mert Avatar asked Oct 31 '25 03:10

Mert


1 Answers

In 7.50 you have 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,
like image 189
Mikael G Avatar answered Nov 03 '25 21:11

Mikael G