SAP CDS SESSION VAR BUILTIN V2



Get Example source ABAP code based on a different SAP table
  


• user ABAP_CDS_SESS_VAR_V2
• client ABAP_CDS_SESS_VAR_V2
• system_language ABAP_CDS_SESS_VAR_V2
• system_date ABAP_CDS_SESS_VAR_V2
• user_timezone ABAP_CDS_SESS_VAR_V2
• user_date ABAP_CDS_SESS_VAR_V2

ABAP_CDS_DDL - CDS View Entity, Built-In Session Variables

ABAP_SYNTAX
... $session.vname ...

What does it do?
Specifies a built-in session variable vname in an operand position in a SELECT statement of a CDS view entity. The variable must be prefixed by $session..
Session variables have a predefined name and provide context-dependent information. The following built-in session variables exist: <(>vname<)>Value when accessed
userCurrent user name, nominal value of the ABAP system field sy-uname . The returned value has the data type CHAR.
clientCurrent client. The default value is the nominal value of the ABAP system field sy-mandt. In reads with an AB-SQL statement with the addition USING CLIENT and in calls of an AMDP method from ABAP in whose declaration the addition AMDP OPTIONS CDS SESSION CLIENT is specified, it is the value specified here. The returned value has the data type CLNT, length 3.
system_language Text environment language of the current ABAP_ISESS , nominal value of the ABAP system field sy-langu. The returned value has the data type LANG, length 1.
system_dateCurrent system date of the AS ABAP, nominal value of the ABAP system field sy-datum. The returned value is of data type DATS, length 8.
user_timezoneUser time zone, nominal value of the ABAP system field sy-zonlo. The returned value has the data type CHAR, length 6.
user_dateCurrent user date, nominal value of the ABAP system field sy-datlo. The returned value is of data type DATS, length 8.



Latest notes:

From a technical perspective, session variables indicate global variables of the current database that are set to their value when the CDS view entity is used in AB_SQL . If AB_SQL is not used to access a CDS view entity with session variables, the content of the variables is undefined (with the exception of the SAP HANA database).
For input parameters of CDS view entities annotated with the annotation environment.systemField, AB_SQL automatically passes the values of the session variables. It is generally preferable to use this type of local input parameter.
In existing CDS view entities without corresponding input parameters, session variables can be passed to the input parameters of CDS view entities or CDS table functions used there.
In CDS view entities, client handling takes place implicitly by using the session variable client.
NON_V5_HINTS
On an SAP HANA database used as a standard AS ABAP database, the ABAP-specific session variables are called APPLICATIONUSER, CDS_CLIENT, LOCALE_SAP, and SAP_SYSTEM_DATE. They exist and are set independently of ABAP CDS and AB_SQL . They can be accessed using the database function SESSION_CONTEXT.
A further ABAP-specific session variable CLIENT in the SAP HANA database always contains the current client of the ABAP session and is not modified by the AB-SQL addition USING CLIENT or by ABAP calls of an AMDP method in whose declaration the addition AMDP OPTIONS CDS SESSION CLIENT is specified. The HANA session variable CLIENT does not have a corresponding variable in ABAP CDS.
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The following CDS view entity contains all possible session variables in the SELECT list.
BEGIN_SECTION VERSION 5 OUT The class CL_DEMO_CDS_SESSION_VARIS_VE uses AB_SQL to access the view entity. The class asks you of you want to use the addition USING CLIENT.
DDLS DEMO_CDS_SESSION_VARIABLES_VE
END_SECTION VERSION 5 OUT
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
The following CDS view entity DEMO_CDS_SELECT_T100_VE accesses the CDS view entity DEMO_CDS_SELECT_T100_LANGU_VE, which contains a language input parameter to which the annotation environment.systemField with the value system_language is assigned. Unlike in AB_SQL , there is no implicit pass of the actual parameter to the input parameter here and the corresponding session variable $session.system_language is passed instead. The class CL_DEMO_CDS_T100_VE uses AB_SQL to access both view entities and the result is identical. When DEMO_CDS_SELECT_T100_LANGU_VE is accessed, the value of the system field sy-langu is passed implicitly to the input parameter. When DEMO_CDS_SELECT_T100 is accessed, the session variable $session.system_language is filled with this value.
DDLS DEMO_CDS_SELECT_T100_VE
DDLS DEMO_CDS_SELECT_T100_LANGU_VE
ABAP_EXAMPLE_END