Ansicht
Dokumentation

ABENSQL_TIMESTAMP_FUNC - SQL TIMESTAMP FUNC

ABENSQL_TIMESTAMP_FUNC - SQL TIMESTAMP FUNC

Vendor Master (General Section)   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.
SAP E-Book

- Time Stamp Functions

Generic time stamp functions

1. ... IS_VALID( date$|time$|utclong )
    $| EXTRACT_YEAR( date$|utclong )
    $| EXTRACT_MONTH( date$|utclong )
    $| EXTRACT_DAY( date$|utclong )
    $| EXTRACT_HOUR( time$|utclong )
    $| EXTRACT_MINUTE( time$|utclong )
    $| EXTRACT_SECOND( time$|utclong )
    $| DAYNAME( date$|utclong )
    $| MONTHNAME( date$|utclong )
    $| WEEKDAY( date$|utclong )
    $| DAYS_BETWEEN( ${date1$|utclong1$},${date2$|utclong2$} )
    $| ADD_DAYS( ${date$|utclong$},days )
    $| ADD_MONTHS( ${date$|utclong$},months ) ...


Functions for UTCLONG

2. ... UTCL_CURRENT( )
    $| UTCL_ADD_SECONDS( utclong,seconds )
    $| UTCL_SECONDS_BETWEEN( utclong1,utclong2 ) ...


Functions for TIMESTAMP

3. ... TSTMP_IS_VALID( tstmp )
    $| TSTMP_CURRENT_UTCTIMESTAMP( )
    $| TSTMP_SECONDS_BETWEEN( tstmp1   = tstmp1,
                             tstmp2   = tstmp2$[,
                             on_error = on_error$] )
    $| TSTMP_ADD_SECONDS( tstmp    = tstmp,
                         seconds  = seconds$[,
                         on_error = on_error$] ) ...




Effect

These SQL functions perform operations on time stamps. The first set covers generic functions, the second set covers functions depending on the built-in data type UTCLONG, and the third set covers functions depending on the data element TIMESTAMP.

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. Optional parameters can be assigned actual parameters when called. Non-optional parameters must be assigned actual parameters.

SQL expressions of matching data types can be specified as actual parameters. Only enumerated constants of specific classes can be passed to the parameter on_error for the TIMESTAMP functions TSTMP_SECONDS_BETWEEN and TSTMP_ADD_SECONDS. If an actual parameter contains the null value, every function except IS_VALID and TSTMP_IS_VALID returns a null value.

Generic Time Stamp Functions

... IS_VALID( date$|time$|utclong )
  $| EXTRACT_YEAR( date$|utclong )
  $| EXTRACT_MONTH( date$|utclong )
  $| EXTRACT_DAY( date$|utclong )
  $| EXTRACT_HOUR( time$|utclong )
  $| EXTRACT_MINUTE( time$|utclong )
  $| EXTRACT_SECOND( time$|utclong )
  $| DAYNAME( date$|utclong )
  $| MONTHNAME( date$|utclong )
  $| WEEKDAY( date$|utclong )
  $| DAYS_BETWEEN( ${date1$|utclong1$},${date2$|utclong2$} )
  $| ADD_DAYS( ${date$|utclong$},days )
  $| ADD_MONTHS( ${date$|utclong$},months ) ...


Effect

These SQL functions perform operations with arguments of the built-in data types DATN, DATS, TIMN, TIMS, and UTCLONG.

Note

For more information about the generic functions

  • IS_VALID, EXTRACT_YEAR, EXTRACT_MONTH, EXTRACT_DAY, DAYNAME, MONTHNAME, WEEKDAY, DAYS_BETWEEN, ADD_DAYS, and ADD_MONTHS see date functions or for
  • IS_VALID, EXTRACT_HOUR, EXTRACT_MINUTE, and EXTRACT_SECOND see time functions.
  • All generic functions enforce strict mode from Release .

Functions for UTCLONG

... UTCL_CURRENT( )
  $| UTCL_ADD_SECONDS( utclong,seconds )
  $| UTCL_SECONDS_BETWEEN( utclong1,utclong2 ) ...


Variants:

1. ... UTCL_CURRENT( )

2. ... UTCL_ADD_SECONDS( ... )

3. ... UTCL_SECONDS_BETWEEN( ... )

Effect

These SQL functions perform operations with arguments of the built-in data type UTCLONG.

Note

The use of the functions UTCL_CURRENT( ), UTCL_ADD_SECONDS, and UTCL_SECONDS_BETWEEN enforces the strict mode from Release .

Variant 1

... UTCL_CURRENT( )


Effect

This function generates a UTC time stamp from the system time and the system date of AS ABAP in accordance with POSIX. The return value has the built-in dictionary type UTCLONG.

All columns of a query have the same time stamp.

Example

Selects column CARRID from table SCARR and returns a time stamp for each row. The time stamp is generated only once for the query and, therefore, all rows have the same time stamp.

Variant 2

... UTCL_ADD_SECONDS( ... )


Effect

The function UTCL_ADD_SECONDS adds seconds seconds to a time stamp utclong. It has two positional parameters. The actual parameter for the formal parameter utclong must have the built-in dictionary type UTCLONG and contain a valid time stamp in the format YYYYMMDDHHMMSSMMMUUUN. An invalid time stamp produces an error. The actual parameter for the formal parameter seconds must have either the built-in data type INT4 or the data type DEC with length 21 and 7 decimal places. Any negative values are subtracted. If the result is invalid, an error occurs.

The result is of type UTCLONG.

Variant 3

... UTCL_SECONDS_BETWEEN( ... )


Effect

The function UTCL_SECONDS_BETWEEN calculates the difference between two specified time stamps utcl1 and utcl2 in seconds. It has two positional parameters. The actual parameters for the formal parameters utcl1 and utcl2 must have the built-in dictionary type UTCLONG and contain a valid time stamp in the format YYYYMMDDHHMMSSMMMUUUN. Any invalid time stamps produce an error. If utcl2 is greater than utcl1, the result is positive. If the values are identical, the result is 0. In all other cases, the result is negative.

The result is of type DEC with length 21 and 7 decimal places.



Functions for TIMESTAMP

... TSTMP_IS_VALID( tstmp )
  $| TSTMP_CURRENT_UTCTIMESTAMP( )
  $| TSTMP_SECONDS_BETWEEN( tstmp1   = tstmp1,
                           tstmp2   = tstmp2$[,
                           on_error = on_error$] )
  $| TSTMP_ADD_SECONDS( tstmp    = tstmp,
                       seconds  = seconds$[,
                       on_error = on_error$] ) ...


Variants:

1. ... TSTMP_IS_VALID( ... )

2. ... TSTMP_CURRENT_UTCTIMESTAMP( )

3. ... TSTMP_SECONDS_BETWEEN( ... )

4. ... TSTMP_ADD_SECONDS( ... )

Effect

These SQL functions perform operations with arguments of the data element TIMESTAMP.

Note

The use of the functions TSTMP_IS_VALID, TSTMP_CURRENT_UTCTIMESTAMP( ), TSTMP_SECONDS_BETWEEN, and TSTMP_ADD_SECONDS enforces the strict mode from Release .

Variant 1

... TSTMP_IS_VALID( ... )


Effect

The function TSTMP_IS_VALID determines whether an argument tstmp contains a valid time stamp in the format YYYYMMDDHHMMSS. It has one positional parameter. The actual parameter must have the built-in data type DEC with length 15 and no decimal places. The result has the data type INT4. A valid time stamp produces the value 1 and all other input values (including the null value) produce the value 0.

Variant 2

... TSTMP_CURRENT_UTCTIMESTAMP( )


Effect

The function TSTMP_CURRENT_UTCTIMESTAMP returns a UTC time stamp in accordance with the POSIX standard. The result has the data type DEC with length 15 and no decimal places.

Note

  • If the function TSTMP_CURRENT_UTCTIMESTAMP is used more than once within an statement, it cannot be guaranteed that every call within a database access produces the same result. Hence, later calls can produce later time stamps.

Variant 3

... TSTMP_SECONDS_BETWEEN( ... )


Effect

The function TSTMP_SECONDS_BETWEEN calculates the difference between two specified time stamps, tstmp1 and tstmp2 in seconds. All parameters are keyword parameters. The actual parameters for the formal parameters tstmp1 and tstmp2 must have the built-in data type DEC with length 15 and no decimal places and contain valid time stamps in the format YYYYMMDDHHMMSS. Any invalid time stamps produce an error. If tstmp2 is greater than tstmp1, the result is positive. In the reverse case, it is negative.

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_SECONDS_BETWEEN and the following enumerated constants can be passed:

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

Variant 4

... TSTMP_ADD_SECONDS( ... )


Effect

The function TSTMP_ADD_SECONDS adds seconds seconds to a time stamp tstmp. All parameters are keyword parameters. 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. An invalid time stamp produces an error. The actual parameter for the formal parameter seconds must also have the built-in data type DEC with length 15 and no decimal places. Negative values are subtracted. If the result is invalid, an error occurs.

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_ADD_SECONDS and the following enumerated constants can be passed:

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

Example

Applies the time stamp functions to columns of the DDIC database table DEMO_EXPRESSIONS. The program DEMO_SQL_TIMESTAMP_FUNCTIONS executes this access to the table and represents the result. The column NUM1 of the DDIC database table is given a value that is added to a time stamp in the column TIMESTAMP1 as seconds. The difference is calculated between this sum and a time stamp retrieved on the database by the function TSTMP_CURRENT_UTCTIMESTAMP. A delay wait can be integrated between the time stamp in the ABAP program and the time stamp created on the database. The number of seconds specified as type-compliant literal in the variable pack is added to the time stamp utcl, which has the type UTCLONG. Finally, the difference in seconds between two time stamps of type UTCLONG is calculated. Since utcl1 is greater than utcl2, the result is negative.






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

Length: 19941 Date: 20240419 Time: 180620     sap01-206 ( 229 ms )