SAP CDS SESSION VARIABLE V1



Get Example source ABAP code based on a different SAP table
  


• $session variable ABAP_CDS_SELECT_V1
• user ABAP_CDS_SESSION_VAR
• client ABAP_CDS_SESSION_VAR
• system_language ABAP_CDS_SESSION_VAR
• system_date ABAP_CDS_SESSION_VAR
• user_timezone ABAP_CDS_SESSION_VAR
• user_date ABAP_CDS_SESSION_VAR

ABAP_CDS_DDL - DDIC-Based View, session_variable

ABAP_SYNTAX
... $session.vname ...

What does it do?
Specifies a session variable vname in an operand position in a SELECT statement of a ABAP_CDS_V1_VIEW . The variable must be prefixed by $session.. The prefix and the variable are case-sensitive. $session.vname, $Session.Vname, and $SESSION.VNAME can all be used. No other spellings are allowed.
Session variables have a predefined name and are set to a predefined value when the CDS view is used in AB_SQL . This also applies to CDS views that are used as data sources in other CDS views. The following session variables exist: <(>vname<)>Value when accessed using AB_SQL
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, 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 has the 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 is used in AB_SQL . If AB_SQL is not used to access a CDS view with session variables, the content of the variables is undefined (with the exception of the SAP HANA database).
For input parameters of CDS views annotated with the special annotation environment.systemField, AB_SQL can pass the values of the session variables specified here automatically too. It is generally preferable to use this type of local input parameter.
In existing CDS views without corresponding input parameters, session variables can be passed to the input parameters of CDS views or CDS table functions used there.
In the ABAP_CDS_MNG_VIEW of a ABAP_CDS_V1_VIEW whose client handling is set by the annotation @ClientHandling.algorithm: #SESSION_VARIABLE, the value of the session variable client is used in WHERE conditions for the client column.
A CDS view that accesses a session variable directly or using a view cannot usually be buffered. Only client-dependent views that access the session variable client directly can be buffered.
NON_V5_HINTS
The obsolete addition CLIENT SPECIFIED cannot be used either.
On a 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 and 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.
When the AB-SQL statement SELECT is used to access a CDS view that uses the session client client, the addition USING CLIENT can be used and sets the value of the session variable client for the duration of the AB-SQL statement. The additions USING $[ALL$] CLIENTS $[IN$] cannot be used.
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The following CDS view contains the possible session variables in the SELECT list.
BEGIN_SECTION VERSION 5 OUT The class CL_DEMO_CDS_SESSION_VARIABLES uses AB_SQL to access the view and fills the session variables with the associated values. It is possible to define whether USING CLIENT is used or not.
END_SECTION VERSION 5 OUT
DDLS DEMO_CDS_SESSION_VARIABLES
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
The following CDS view DEMO_CDS_SELECT_T100 accesses a further CDS view DEMO_CDS_SELECT_T100_LANGU with 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 uses AB_SQL to access both views and the result is identical. When DEMO_CDS_SELECT_T100_LANGU 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
DDLS DEMO_CDS_SELECT_T100_LANGU
ABAP_EXAMPLE_END