In the ABAP language you are used to system fields like sy-mandt, sy-uname, sy-langu for environment information. For date and time, you use the good old german ones, sy-uzeit and sy-datum, or you use time stamps (GET TIME STAMP and co.). Some of that convenience is available in ABAP CDS now too.
If a SAP HANA Database serves as the central database of an AS ABAP, you have access to the following three global session variables:
The ABAP runtime environment fills these database variables with values that correspond to the contents of the above mentioned system fields. You can access the session variables natively, that is in EXEC SQL, ADBC and AMDP, using the built-in function SESSION_CONTEXT. Example for AMDP:
METHOD get_session_variables_amdp
BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT.
...
That's not new for ABAP 7.50.
New for ABAP 7.50:
You can access these session variables in an ABAP CDS View. And not only for a SAP HANA Database but for all supported databases! The syntax is
Simple example:
@AbapCatalog.sqlViewName: 'DEMO_CDS_SESSVAR'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_session_variables
$session.client as system_client,
$session.system_language as system_language }
Please note, that for other databases than SAP HANA the contents of these variables is only defined when you access the CDS view with Open SQL.
While session variables are a convenient way to access the information contained within they are - well - global variables. And you know the bad reputation of global variables. What's the alternative? Passing the information from AS ABAP to appropriate parameters of CDS Views and CDS table functions. In order to facilitate that for you, a new ABAP annotation @Environment.systemField was introduced for CDS view and function parameters with ABAP 7.50. The possible values are the enumeration values:
If you access a CDS view or CDS table function with parameters annotated as such in Open SQL, you can (and for #CLIENT you even must) leave away the explicit parameter passing. Open SQL implicitly passes the contents of the respective system fields for you!
@AbapCatalog.sqlViewName: 'DEMO_CDS_SYST'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_system_fields
@Environment.systemField : #CLIENT
@Environment.systemField : #SYSTEM_DATE
@Environment.systemField : #SYSTEM_TIME
@<Environment.systemField : #SYSTEM_LANGUAGE,
@<Environment.systemField : #USER
as select from demo_expressions
SELECT *
FROM demo_cds_system_fields( )
INTO TABLE @DATA(result).
The parameters are passed implicitly. This replaces
SELECT *
FROM demo_cds_system_fields( p_datum = @SY-datum,
p_uzeit = @SY-uzeit,
p_langu = @SY-langu,
p_uname = @SY-uname )
INTO TABLE @DATA(result).
A value for p_mandt cannot be passed explicitly any more.
The implicit parameter passing is for your convenience and only available in Open SQL. If you use CDS entities with parameters within CDS entities you have to pass parameters explicitly again. You might pass the above mentioned session variables then.
Did you notice that you can implicitly pass values for system date and time from AS ABAP to CDS entities but that there are no session variables for those (at least not in release 7.50)?
Instead, with ABAP 7.50 a new set of built-in date and time functions is available in ABAP CDS.
An important one is TSTMP_CURRENT_UTCTIMESTAMP(), that returns the current time stamp. Others check values and calculate with dates and times, as e.g. dats_days_between.
The following example shows how the current date and time can be extracted from a time stamp using string functions:
substring( cast( tstmp_current_utctimestamp() as abap.char(17) ), 1, 8 )
substring( cast( tstmp_current_utctimestamp() as abap.char(17) ), 9, 6 )
Smells like a workaraound? More functionality for date and time handling in ABAP CDS is still in development!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |