Ansicht
Dokumentation

ABENSQL_DATE_TIME_CONVERSIONS - SQL DATE TIME CONVERSIONS

ABENSQL_DATE_TIME_CONVERSIONS - SQL DATE TIME CONVERSIONS

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.
SAP E-Book

- Date/Time Conversions

... TSTMP_TO_DATS( tstmp    = tstmp,
                   tzone    = tzone$[,
                   client   = client$]$[,
                   on_error = on_error$] )
  $| TSTMP_TO_TIMS( tstmp    = tstmp,
                   tzone    = tzone$[,
                   client   = client$]$[,
                   on_error = on_error$] )
  $| TSTMP_TO_DST(  tstmp    = tstmp,
                   tzone    = tzone$[,
                   client   = client$]$[,
                   on_error = on_error$] )
  $| DATS_TIMS_TO_TSTMP( date     = date,
                        time     = time,
                        tzone    = tzone$[,
                        client   = client$]$[,
                        on_error = on_error$] )
  $| TSTMPL_TO_UTCL( tstmpl = tstmpl$[,
                    on_error = on_error$],$[
                    on_initial = on_initial$] )
  $| TSTMPL_FROM_UTCL( utcl = utcl$[,
                      on_null = on_null$] )
  $| DATS_TO_DATN( dats = dats$[,
                  on_error = on_error$],$[
                  on_initial = on_initial$] )
  $| DATS_FROM_DATN( datn = datn$[,
                    on_null = on_null$] )
  $| TIMS_TO_TIMN( tims = tims$[,
                  on_error = on_error$] )
  $| TIMS_FROM_TIMN( timn = timn$[,
                    on_null = on_null$] )...


Variants:

1. ... TSTMP_TO_DATS( ... )

2. ... TSTMP_TO_TIMS( ... )

3. ... TSTMP_TO_DST( ... )

4. ... DATS_TIMS_TO_TSTMP( ... )

5. ... TSTMPL_TO_UTCL( ... )

6. ... TSTMPL_FROM_UTCL( ... )

7. ... DATS_TO_DATN( ... )

8. ... DATS_FROM_DATN( ... )

9. ... TIMS_TO_TIMN( ... )

10. ... TIMS_FROM_TIMN( ... )

Effect

The SQL functions described in variants 1 to 4 convert time stamps into dates or times, and vice versa. The SQL functions described in variants 5 to 10 convert time stamps, dates, and times between different types.

The arguments of the functions are specified as a comma-separated list in parentheses. A blank must be placed after the opening parenthesis and in front of the closing parenthesis. The functions have keyword parameters. Optional parameters can be assigned actual parameters when called. Non-optional parameters must be assigned actual parameters.

SQL expressions, in particular individual columns, type-compliant literals, SQL functions, host variables or host expressions can be specified as actual parameters.

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

Notes

  • The functions described in Variants 5 to 10 have keyword parameters and all of them have exactly one required parameter. When calling only the required parameter, then it can be handled like a positional parameter, that means it can be called without the formal parameter name.
  • Use of the functions described in Variants 1 to 4 enforces the strict mode from Release.
  • Use of the functions described in Variants 5 to 10 enforces the strict mode from Release .

Variant 1

... TSTMP_TO_DATS( ... )


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 for the formal 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 for the optional formal parameter client must have the built-in dictionary type CLNT and contain a valid client ID. The default value is the current 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 optional parameter on_error affects how errors are handled. The parameter for on_error must be an enumerated object with the enumerated type ON_ERROR from the class SQL_TSTMP_TO_DATS and the following enumerated constants can be passed:

  • SQL_TSTMP_TO_DATS=>FAIL, an error raises an exception (default)
  • SQL_TSTMP_TO_DATS=>SET_TO_NULL, an error returns the null value

Variant 2

... TSTMP_TO_TIMS( ... )


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 parameters tstmp, tzone, client, and on_error as to the function TSTMP_TO_DATS. Here, the class of the enumerated type of on_error is SQL_TSTMP_TO_TIMS.

The return value has the built-in data type TIMS.

Variant 3

... TSTMP_TO_DST( ... )


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 parameters tstmp, tzone, client, and on_error as to the function TSTMP_TO_DATS. Here, the class of the enumerated type of on_error is SQL_TSTMP_TO_DST.

The return value has the built-in data type CHAR with length 1.

Variant 4

... DATS_TIMS_TO_TSTMP( ... )


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 for the formal parameter date must have the built-in data type DATS and should contain a valid date. The actual parameter for the formal parameter time must have the built-in data type TIMS and should contain a valid time. The same applies to the parameters tzone, client, and on_error as to the function TSTMP_TO_DATS. Here, the class of the enumerated type of on_error is SQL_DATS_TIMS_TO_TSTMP.

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( ... )


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 optional parameter on_error affects how errors are handled:

The parameter for on_error must be an enumerated object with the enumerated type ON_ERROR from the class SQL_TSTMPL_TO_UTCL and the following enumerated constants can be passed:

  • SQL_TSTMPL_TO_UTCL=>C_ON_ERROR-FAIL, an error raises an exception (default)
  • SQL_TSTMPL_TO_UTCL=>C_ON_ERROR-SET_TO_NULL, an error returns the null value)
  • SQL_TSTMPL_TO_UTCL=>C_ON_ERROR-SET_TO_INITIAL, an error returns the initial value

The optional parameter on_initial affects how arguments with initial values are handled:

The parameter for on_initial must be an enumerated object with the enumerated type ON_INITIAL from the class SQL_TSTMPL_FROM_UTCL and the following enumerated constants can be passed:

  • SQL_TSTMPL_FROM_UTCL=>C_ON_INITIAL-FAIL, an initial value raises an exception
  • SQL_TSTMPL_FROM_UTCL=>C_ON_INITIAL-SET_TO_NULL, an initial value returns the null value
  • SQL_TSTMPL_FROM_UTCL=>C_ON_INITIAL-SET_TO_INITIAL, an initial value returns the initial value (default)

Variant 6

... TSTMPL_FROM_UTCL( ... )


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 should contain a valid time stamp.

The optional parameter on_null affects how null values as arguments are handled. The parameter for on_null must be an enumerated object with the enumerated type ON_NULL from the class SQL_TSTMPL_FROM_UTCL and the following enumerated constants can be passed:

  • SQL_TSTMPL_FROM_UTCL=>C_ON_NULL-FAIL, a null value raises an exception
  • SQL_TSTMPL_FROM_UTCL=>C_ON_NULL-SET_TO_NULL, a null value returns the null value
  • SQL_TSTMPL_FROM_UTCL=>C_ON_NULL-SET_TO_INITIAL, a null value returns the initial value (default)

Variant 7

... DATS_TO_DATN( ... )


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). Here, the class of the enumerated type of on_error and on_initial is SQL_DATS_TO_DATN.

Note

The same effect of the function DATS_TO_DATN can be achieved by casting.

Variant 8

... DATS_FROM_DATN( ... )


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). Here, the class of the enumerated type of on_null is SQL_DATS_FROM_DATN.

Note

The same effect of the function DATS_FROM_DATN can be achieved by casting.

Variant 9

... TIMS_TO_TIMN( ... )


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). Here, the class of the enumerated type of on_error is SQL_TIMS_TO_TIMN.

Note

The same effect of the function TIMS_TO_TIMN can be achieved by casting.

Variant 10

... TIMS_FROM_TIMN( ... )


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). Here, the class of the enumerated type of on_null is SQL_TIMS_FROM_TIMN.

Note

The same effect of the function TIMS_FROM_TIMN can be achieved by casting.

Example

Extracts date, time, and daylight saving time flag of the current UTC time stamp 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 TSTMPL_TO_UTCL and TSTMPL_FROM_UTCL convert time stamps between TIMESTAMPL and utclong format. The conversion functions DATS_TO_DATN and DATS_FROM_DATN convert dates between DATS and DATN. The conversion functions TIMS_TO_TIMN and TIMS_FROM_TIMN convert times between TIMS and TIMN. The program DEMO_SQL_DATE_TIME executes the statement and displays the result.






BAL_S_LOG - Application Log: Log header data   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.

Length: 23970 Date: 20240329 Time: 085827     sap01-206 ( 258 ms )