SAP Knowledge Base Article - Public

2887459 - Timestamp field represented as decimal in Custom CDS View

Symptom

When creating a Custom CDS View with a timestamp field, the date and time are a decimal number and not a date/time field. 

Environment

SAP S/4HANA Cloud Public Edition

Reproducing the Issue

  1. Create a Custom CDS View 
  2. Add the date/time field
  3. When you preview the Custom CDS View, the DateTime field is represented as a number with decimals instead of a timestamp.

Cause

This is standard behavior. The field is coming in a decimal format. 

Resolution

It will be necessary to convert the data format. For that, we recommend you to create a Calculated Field. 

You can use the following functions: 

CAST - Returns the date 

cast( cast( DateTimeFieldName as ABAP.SSTRING( Length ) ) as ABAP.DATS )

TSTMP_TO_DATS - Returns the date 

TSTMP_TO_DATS(cast( <CDS View>.<CDS view field> as ABAP.DEC( 15, 0 ) ),abap_user_timezone($session.user,$session.client,'NULL'),$session.client,'NULL')

TSTMP_TO_TIMS - Returns the time 

TSTMP_TO_TIMS(cast( <CDS View>.<CDS view field> as ABAP.DEC( 15, 0 ) ),abap_user_timezone($session.user,$session.client,'NULL'),$session.client,'NULL')

*tstmp must have data type DEC (length 15) and no decimal places.

**The function also contains a timezone parameter: "tzone expects an actual parameter of the type CHAR with length 6, either initial or containing a valid time zone".

***ABAP_USER_TIMEZONE returns the user time zone of the AS ABAP for the user..

Kindly note that if you only "Preview" the CDS view, the data that you'll see is the raw data and therefore it will not be formatted as "MM/DD/YYYY" for example. Try to preview the data in Customer Data Browser app and it will be formatted. 

See Also

For more information, check the following documentations:

Keywords

timestamp, decimal format, date, time, datetime, dats, tims, cast, TSTMP_TO_TIMS, TSTMP_TO_DATS, decimal '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' , KBA , BC-SRV-APS-GKE , Generic CDS Key User Editor , BW-BEX-OT-ODP , Query Runtime for Operational Data Provisioning , MM-PUR-SVC-SES , Service Entry Sheet for Service Procurement , Problem

Product

SAP S/4HANA Cloud 1911 ; SAP S/4HANA Cloud 2002 ; SAP S/4HANA Cloud 2005 ; SAP S/4HANA Cloud 2008 ; SAP S/4HANA Cloud 2011 ; SAP S/4HANA Cloud 2102