您好,登錄后才能下訂單哦!
ABAP透明表里的時間戳,數(shù)據(jù)類型為dec:
有個需求:計算這兩個時間戳之間的天數(shù)間隔,丟棄時間戳年-月-日8位后面的小時:分鐘:秒。
舉個例子:如果時間戳是20180918173132,丟棄173132,只保留20180918, 然后再計算天數(shù)間隔。
直接用CDS view的字符串操作函數(shù)substring是不行的,因為時間戳類型dec和substring期待的字符串類型不匹配。
解決方案:
先將時間戳字段類型從dec強制轉(zhuǎn)換成abap.dats:
@AbapCatalog.sqlViewName: 'zproday' @AbapCatalog.compiler.compareFilter: true @AccessControl.authorizationCheck: #CHECK@EndUserText.label: 'Day between'define view zdate_day_between as select from comm_product {key comm_product.product_id as prod_id, comm_product.product_guid as prod_guid, comm_product.valid_from as valid_from, comm_product.valid_to as valid_to,cast(substring(cast(valid_from as abap.char(32)),1,8) as abap.dats) as from_date,cast(substring(cast(valid_to as abap.char(32)),1,8) as abap.dats) as to_date}
然后再用CDS view標(biāo)準(zhǔn)的時間處理函數(shù)DATS_DAYS_BETWEEN:
@AbapCatalog.sqlViewName: 'zdbetw' @AbapCatalog.compiler.compareFilter: true @AccessControl.authorizationCheck: #CHECK@EndUserText.label: 'Day between'define view zc_date_day_between as select from zdate_day_between as host{key host.prod_guid, host.prod_id, host.from_date, host.to_date, DATS_DAYS_BETWEEN(host.from_date, host.to_date) as no_of_days }
測試結(jié)果:
要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。