AS ABAP Release 758, ©Copyright 2024 SAP SE. All rights reserved.
ABAP - Keyword Documentation → ABAP - Programming Language → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Operands and Expressions → ABAP SQL - SQL Expressions sql_exp → sql_exp - sql_func → ABAP SQL - Built-In Functions sql_func → sql_func - Special Functions → sql_func - Date Functions and Time Functions →sql_func - Time Functions
Syntax Forms
1. ... IS_VALID( date|time|utclong )
| EXTRACT_HOUR( time|utclong )
| EXTRACT_MINUTE( time|utclong )
| EXTRACT_SECOND( time|utclong ) ...
2. ... TIMS_IS_VALID( time ) ...
Effect
These SQL functions perform operations on times with arguments of the built-in data types
TIMN, TIMS,
and UTCLONG. The
first set covers generic functions and the second set covers one function depending on the data type
TIMS. The arguments
of the functions are specified in parentheses. A blank must be placed after the opening parenthesis and in front of the closing parenthesis.
SQL expressions of matching data types can be specified as actual parameters. If an actual parameter contains the
null value, every function
except IS_VALID and TIMS_IS_VALID returns a null value. IS_VALID and TIMS_IS_VALID return the value 0.
Generic Time Functions
Syntax
... IS_VALID( date|time|utclong )
| EXTRACT_HOUR( time|utclong )
| EXTRACT_MINUTE( time|utclong )
| EXTRACT_SECOND( time|utclong ) ...
1. ... IS_VALID( date|time|utclong ) ...
2. ... EXTRACT_HOUR( time|utclong ) ...
3. ... EXTRACT_MINUTE( time|utclong ) ...
4. ... EXTRACT_SECOND( time|utclong ) ...
Effect
These SQL functions perform operations with arguments of the built-in data types DATN, DATS, TIMN, TIMS, and UTCLONG.
Hint
All generic functions enforce the strict mode from ABAP release 7.56.
... IS_VALID( date|time|utclong ) ...
Effect
The generic function IS_VALID determines whether
The result has the data type INT4. A valid time and the initial value (for the data types TIMN and TIMS) produce the value 1 and all other input values (including the null value) produce the value 0.
Hint
The generic function IS_VALID is also available for date functions and time stamp functions.
Example
Applying the generic function to a time column of the DDIC database table DEMO_EXPRESSIONS.
FINAL(time1) = cl_demo_date_time=>get_utc_time( ).
...
DELETE FROM demo_expressions.
INSERT demo_expressions FROM @( VALUE #(
id = 'X'
tims1 = time1 ) ).
SELECT SINGLE
FROM demo_expressions
FIELDS tims1 AS time1,
is_valid( tims1 ) AS valid1
INTO @FINAL(result).
... EXTRACT_HOUR( time|utclong ) ...
Effect
The generic function EXTRACT_HOUR extracts the hour of a time or a time stamp. The actual parameter must have the built-in data type TIMN, TIMS, or UTCLONG.
The result of the function EXTRACT_HOUR has the data type INT4. The function returns the value 0 for initial input values. If no valid time is passed as a TIMS value, the function EXTRACT_HOUR raises a catchable exception of class CX_SY_OPEN_SQL_DB.
Hints
... EXTRACT_MINUTE( time|utclong ) ...
Effect
The generic function EXTRACT_MINUTE extracts the minute of a time or a time stamp. The actual parameter must have the built-in data type TIMN, TIMS, or UTCLONG.
The result of the function EXTRACT_MINUTE has the data type INT4. The function returns the value 0 for initial input values. If no valid time is passed as a TIMS value, the function EXTRACT_MINUTE raises a catchable exception of class CX_SY_OPEN_SQL_DB.
Hints
... EXTRACT_SECOND( time|utclong ) ...
Effect
The generic function EXTRACT_SECOND extracts the second of a time or a time stamp. The actual parameter must have the built-in data type TIMN, TIMS, or UTCLONG.
The result of the function EXTRACT_SECOND has the data type INT4. The function returns the value 0 for initial input values. If no valid time is passed as a TIMS value, the function EXTRACT_SECOND raises a catchable exception of class CX_SY_OPEN_SQL_DB.
Hints
Example
Applying the generic functions to time and time stamp columns of the DDIC database table DEMO_EXPRESSIONS.
DELETE FROM demo_expressions.
INSERT demo_expressions FROM @(
VALUE #( id = 'X' tims1 = cl_demo_date_time=>get_user_time( )
timn2 = cl_demo_date_time=>get_user_time( )
utcl1 = `2022-01-01T12:14:50` ) ).
SELECT SINGLE tims1, timn2, utcl1,
extract_hour( tims1 ) AS extract_hour,
extract_minute( timn2 ) AS extract_minute,
extract_second( utcl1 ) AS extract_second
FROM demo_expressions
INTO @FINAL(result).
Functions for TIMS
Syntax
... TIMS_IS_VALID( time ) ...
Effect
This SQL function performs operations with arguments of the built-in data type TIMS.
... TIMS_IS_VALID( time )
Effect
The function TIMS_IS_VALID determines whether the specification time contains a valid time in the format HHMMSS. The actual parameter must have the built-in data type TIMS. The result has the data type INT4. A valid time and the initial value produce the value 1 and all other input values (including the null value) produce the value 0.
Hint
The use of this function leads to the strict mode from ABAP release 7.53.
Example
Applying the time function to a time column of the DDIC database table DEMO_EXPRESSIONS. The class CL_DEMO_SQL_TIME_FUNCTIONS executes this access to the table and displays the result.
FINAL(time1) = cl_demo_date_time=>get_user_time( ).
...
DELETE FROM demo_expressions.
INSERT demo_expressions FROM @( VALUE #(
id = 'X'
tims1 = time1 ) ).
SELECT SINGLE
FROM demo_expressions
FIELDS tims1 AS time1,
tims_is_valid( tims1 ) AS valid1
INTO @FINAL(result).