Ansicht
Dokumentation

ABENCDS_DATE_TIME_CONVERSIONS_V1 - CDS DATE TIME CONVERSIONS V1

ABENCDS_DATE_TIME_CONVERSIONS_V1 - CDS DATE TIME CONVERSIONS V1

ROGBILLS - Synchronize billing plans   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

- DDIC-Based View, Date/Time Conversions

... TSTMP_TO_DATS(tstmp,tzone,clnt,on_error)
  $| TSTMP_TO_TIMS(tstmp,tzone,clnt,on_error)
  $| TSTMP_TO_DST(tstmp,tzone,clnt,on_error)
  $| DATS_TIMS_TO_TSTMP(date,time,tzone,clnt,on_error)
  $| TSTMPL_TO_UTCL(tstmpl,on_error,on_initial)
  $| TSTMPL_FROM_UTCL(utcl,on_null)
  $| DATS_TO_DATN(dats,on_error,on_initial)
  $| DATS_FROM_DATN(date,on_null)
  $| TIMS_TO_TIMN(tims,on_error)
  $| TIMS_FROM_TIMN(time,on_null) ...


Variants:

1. ... TSTMP_TO_DATS(tstmp,tzone,clnt,on_error)

2. ... TSTMP_TO_TIMS(tstmp,tzone,clnt,on_error)

3. ... TSTMP_TO_DST(tstmp,tzone,clnt,on_error)

4. ... DATS_TIMS_TO_TSTMP(date,time,tzone,clnt,on_error)

5. ... TSTMPL_TO_UTCL(tstmpl,on_error,on_initial)

6. ... TSTMPL_FROM_UTCL(utcl,on_null)

7. ... DATS_TO_DATN(dats,on_error,on_initial)

8. ... DATS_FROM_DATN(date,on_null)

9. ... TIMS_TO_TIMN(tims,on_error)

10. ... TIMS_FROM_TIMN(time,on_null)

Effect

In a , these functions perform conversions between date, time, and time stamp formats.

The functions have positional parameters to which actual parameters need to be assigned when called. There are currently no optional parameters. Suitable fields of a data source, literals, parameters, path expressions, built-in functions, or expressions can all be specified as actual parameters. Only literals can be passed to the parameters on_error, on_initial, and on_null. If an actual parameter contains the null value, every function returns a null value.

The conversions follow the ABAP-specific rules for time zones. The associated DDIC database tables must be filled correctly.

Notes

  • To carry out conversions that are not yet supported by built-in CDS conversion functions, an option is to use the respective HANA functions in AMDP or Native SQL.
  • Literals in date and time conversion functions:
  • In functions 1 to 3, the parameter tstmp cannot be specified as literal. This is only possible indirectly, by using a cast expression. For example, this can be specified for tstmp:

cast('20200102122334' as abap.dec(15,0))
  • In functions 5 and 6, the parameter tstmpl cannot be specified as literal. Casting isn't possible either.

  • In functions 7 and 8, the parameters dats and datn can be specified as character literals.

  • In functions 9 and 10, the parameters tims and timn can be specified as character literals.

Variant 1

... TSTMP_TO_DATS(tstmp,tzone,clnt,on_error)


Effect

The function TSTMP_TO_DATS extracts the local date for the time zone specified in tzone from a time stamp in the argument tstmp.

The actual parameter tstmp must have the built-in data type DEC with length 15 and no decimal places and contain a valid time stamp in the format YYYYMMDDHHMMSS. tzone expects an actual parameter of the type CHAR with length 6, either initial or containing a valid time zone. If an initial time zone is specified, no time shift is calculated. The actual parameter clnt must have the built-in dictionary type CLNT and must contain a valid client ID. This client ID is used in the evaluation of the system tables of the rules for time zones. The return value has the built-in data type DATS.

The actual parameter on_error controls error handling. It must have the built-in data type CHAR with the length 10 and must have one of the following values:

  • "FAIL" (an error raises an exception)
  • "NULL" (an error returns the null value)
  • "INITIAL" (an error returns the initial value)

The pattern is case-sensitive. Any incorrectly specified values raise an exception.

Variant 2

... TSTMP_TO_TIMS(tstmp,tzone,clnt,on_error)


Effect

The function TSTMP_TO_TIMS extracts the local time for the time zone specified in tzone from a time stamp in the argument tstmp.

The same applies to the actual parameters tstmp, tzone, clnt, and on_error as to the function TSTMP_TO_DATS. The return value has the built-in data type TIMS.

Variant 3

... TSTMP_TO_DST(tstmp,tzone,clnt,on_error)


Effect

The function TSTMP_TO_DST extracts the daylight saving time marker for the time zone specified in tzone from a time stamp in the argument tstmp. This is "X" if the time stamp for the time zone is in the daylight saving time, otherwise it is initial.

The same applies to the actual parameters tstmp, tzone, clnt, and on_error as to the function TSTMP_TO_DATS. The return value has the built-in data type CHAR with length 1.

Variant 4

... DATS_TIMS_TO_TSTMP(date,time,tzone,clnt,on_error)


Effect

The function DATS_TIMS_TO_TSTMP constructs a time stamp from a local date specified in date and a local time specified in time in the time zone specified in tzone. The daylight saving time is respected implicitly.

The actual parameter date must have the built-in data type DATS and should contain a valid date. The actual parameter time must have the built-in data type TIMS and should contain a valid time. The same applies to the actual parameters tzone, clnt, and on_error as to the function TSTMP_TO_DATS.

The return value has the built-in data type DEC with length 15 and represents an ABAP-specific time stamp in a packed number.

Variant 5

... TSTMPL_TO_UTCL(tstmpl,on_error,on_initial)


Effect

The function TSTMPL_TO_UTCL converts a time stamp tstmpl from the ABAP Dictionary type TIMESTAMPL to the built-in dictionary type UTCLONG.

The actual parameter for the formal parameter tstmpl must have the built-in data type DEC with length 21 and 7 decimal places and contain a valid time stamp in the format YYYYMMDDHHMMSSMMMUUUN.

The same applies to the actual parameter on_error as to the function TSTMP_TO_DATS.

The actual parameter on_initial defines the way arguments with initial values are handled. It must have the built-in data type CHAR with the length 10 and must have one of the following values:

  • "FAIL" (an initial value raises an exception)
  • "NULL" (an initial value returns the null value)
  • "INITIAL" (an initial value returns the initial value)

The pattern is case-sensitive. Any incorrectly specified values raise an exception.

Note

The function TSTMPL_TO_UTCL is a purely technical type conversion and does not involve any time zone calculations.

Variant 6

... TSTMPL_FROM_UTCL(tstmpl,on_null)


Effect

The function TSTMPL_FROM_UTCL converts a time stamp utcl from the built-in dictionary type UTCLONG to the ABAP Dictionary type TIMESTAMPL. It is the counterpart to variant 5.

The actual parameter for the formal parameter utcl must have the built-in data type UTCLONG and it should contain a valid time stamp.

The actual parameter on_null defines the way null values as arguments are handled. It must have the built-in data type CHAR with the length 10 and must have one of the following values:

  • "FAIL" (a null value raises an exception)
  • "NULL" (a null value returns the null value)
  • "INITIAL" (a null value returns the initial value)

The pattern is case-sensitive. Any incorrectly specified values raise an exception.

If the parameter utcl is initial, 0 is returned.

Note

The function TSTMPL_FROM_UTCL is a purely technical type conversion and does not involve any time zone calculations.

Variant 7

... DATS_TO_DATN(dats,on_error,on_initial)


Effect

The function DATS_TO_DATN converts a date dats from the built-in ABAP Dictionary data type DATS to the built-in ABAP Dictionary type DATN.

The actual parameter for the formal parameter dats must have the built-in data type DATS and should contain a valid date in the format YYYYMMDD. The same applies to the actual parameters on_error and on_initial as to the function TSTMPL_TO_UTCL (variant 5, see above).

Note

DATN is a newer dictionary type which represents a real date type in a database. DATS, by contrast, is an older dictionary type. It is instantiated on a database as a character-like field. DATS and DATN are not interchangeable and a conversion is necessary to use certain functions.

Variant 8

... DATS_FROM_DATN(date,on_null)


Effect

The function DATS_FROM_DATN converts a date date from the built-in ABAP Dictionary data type DATN to the built-in ABAP Dictionary type DATS. It is the counterpart to variant 7.

The actual parameter for the formal parameter date must have the built-in data type DATN and must contain a valid date in the format YYYYMMDD. The same applies to the actual parameter on_null as to the function TSTMPL_FROM_UTCL (variant 6, see above).

Note

DATN is a newer dictionary type which represents a real date type in a database. DATS, by contrast, is an older dictionary type. It is instantiated on a database as a character-like field. DATS and DATN are not interchangeable and to use certain functions, a conversion is necessary.

Variant 9

... TIMS_TO_TIMN(tims,on_error)


Effect

The function TIMS_TO_TIMN converts a time tims from the ABAP Dictionary type TIMS to the ABAP Dictionary type TIMN.

The actual parameter for the formal parameter tims must have the built-in data type TIMS and contain a valid time in the format HHMMSS. The same applies to the actual parameter on_error as to the function TSTMP_TO_DATS (variant 1, see above).

Note

TIMN is a newer dictionary type which represents a real date type in a database. TIMS, by contrast, is an older dictionary type. It is instantiated on a database as a character-like field. TIMS and TIMN are not interchangeable and to use certain functions, a conversion is necessary.

Variant 10

... TIMS_FROM_TIMN(time,on_null)


Effect

The function TIMS_FROM_TIMN converts a time time from the ABAP Dictionary type TIMN to the ABAP Dictionary type TIMS. It is the counterpart to variant 9.

The actual parameter for the formal parameter time must have the built-in data type TIMN and contain a valid time in the format HHMMSS. The same applies to the actual parameter on_null as to the function TSTMPL_FROM_UTCL (variant 6, see above).

Note

TIMN is a newer dictionary type which represents a real date type in a database. TIMS, by contrast, is an older dictionary type. It is instantiated on a database as a character-like field. TIMS and TIMN are not interchangeable and to use certain functions, a conversion is necessary.

Example

In the following CDS view, the date, the time, and the daylight saving time marker of the current UTC time stamp are extracted using the conversion functions TSTMP_TO_DATS, TSTMP_TO_TIMS, and TSTMP_TO_DST. The values of the columns DATS1 and TIMS1 of the DDIC database table DEMO_EXPRESSIONS are combined into a time stamp by the conversion function DATS_TIMS_TO_TSTMP. The conversion functions described in variants 5 to 10 convert time stamps, dates, and times between different types. The program DEMO_CDS_DATE_TIME accesses the view and displays the result.






General Material Data   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.

Length: 25894 Date: 20240329 Time: 030325     sap01-206 ( 293 ms )