4

I have a simple CDS view. When I execute it, I have the error invalid format (return table) row number 1 property name.

I think I need to cast the date to string or char type, but there's this syntax error:

CAST DOGUM_TARIHI on type CHAR: Length information of target type is missing

Here is my code:

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
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Mert
  • 474
  • 2
  • 8
  • 21
  • I have edited your question to include the syntax error message I guess you have. Please edit it if it's incorrect. – Sandra Rossi Aug 22 '19 at 12:17

1 Answers1

4

So add this length information for the God's sake:

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

However, this only converts date as-is, without making it readable:

20190822 -> 20190822

If you want to make it readable according to format DD.MM.YYYY, make it like this:

@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';

This will make from 20190822 a date of 22.08.2019.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • 1
    I'd suggest to stay with `yyyymmdd` or `yyyy-mm-dd` as ISO-8601 is the only "real" datetime format to be used ( https://xkcd.com/1179/ ). If you're planning to apply filtering or sorting to the results read from the CDS you'll have a hard time using `DD.MM.YYYY`. By the way: I'd be interested in a way to return the CDS data as a proper datestring such that OData native datetime filters can be applied. I suspect it's actually not supported. – koks der drache Aug 26 '19 at 06:42
  • 1
    `I'd suggest to stay with yyyymmdd` it depends on what OP is going to do with dates, if it is just output then readable format is OK. What concerns native OData Edm.DateTime type I suppose it is not supported in ABAP CDS natively, but in HANA CDS [it does](https://help.sap.com/viewer/09b6623836854766b682356393c6c416/2.0.02/en-US/cf394efd3fb4400f9c09d10315028515.html) – Suncatcher Aug 26 '19 at 16:30
  • it would be nice if endusers learned `yyyy-mm-dd` too, then the _sane_ format would be the _readable_ format – András May 06 '22 at 10:40