DATS 到 ABAP CDS 视图中的字符串转换
DATS to string conversion in ABAP CDS view
我有一个简单的 CDS 视图。当我执行它时,出现错误 invalid format (return table) row number 1 property name
.
我想我需要将日期转换为字符串或字符类型,但存在语法错误:
CAST DOGUM_TARIHI on type CHAR: Length information of target type is missing
这是我的代码:
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
所以为了上帝的缘故添加这个长度信息:
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。
我有一个简单的 CDS 视图。当我执行它时,出现错误 invalid format (return table) row number 1 property name
.
我想我需要将日期转换为字符串或字符类型,但存在语法错误:
CAST DOGUM_TARIHI on type CHAR: Length information of target type is missing
这是我的代码:
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
所以为了上帝的缘故添加这个长度信息:
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。