3

我有一个简单的 CDS 视图。当我执行它时,我有错误invalid format (return table) row number 1 property name

我想我需要将日期转换为字符串或字符类型,但是有这个语法错误:

CHAR 类型上的 CAST DOGUM_TARIHI:缺少目标类型的长度信息

这是我的代码:

define view ZUMBS_CDS008
as select from zumhr_ddl001 as hr  {
    personel_numarasi,
    personel_adi,
    cast(dogum_tarihi as abap.char) as te33     //<== error at this line
} group by personel_numarasi,personel_adi,dogum_tarihi
4

1 回答 1

3

所以为了上帝的缘故添加这个长度信息:

cast(dogum_tarihi as abap.char(8)) as te33 

但是,这只会按原样转换日期,而不会使其可读:

20190822 -> 20190822

如果要根据格式 DD.MM.YYYY 使其可读,请像这样:

@AbapCatalog.sqlViewName: 'zcds_sql_usr02'
@EndUserText.label: 'test CDS view'
define view zcds_usr02 as select from usr02 
{
    usr02.bname,
    usr02.gltgb,
    cast(usr02.gltgb as abap.char(10)) as casted,
    concat(
     concat(substring( usr02.gltgb, 7, 2 ), '.'), 
     concat(substring( usr02.gltgb, 5, 2 ), concat('.', substring( usr02.gltgb, 1, 4 )))
     ) as readable
}
where usr02.gltgb <> '00000000';

这将使20190822的日期为22.08.2019

于 2019-08-22T20:14:29.900 回答