ABAP Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions → ABAP CDS - DDL for Data Definitions → ABAP CDS - DEFINE VIEW → ABAP CDS - SELECT → ABAP CDS - SELECT, Operands and Expressions
ABAP CDS - session_variable
Other versions:
7.31 | 7.40 | 7.54
Syntax
... $session.vname ...
Effect
Specifies a session variable
vname
in an operand position in a SELECT statement of a
CDS view. The variable is
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 ABAP SQL. This also applies to CDS views that are used as data sources in other CDS views. The following session variables exist:
vname | Valued when accessed using ABAP SQL |
---|---|
user | Current user name, nominalvalue of the ABAP system field sy-uname |
client | Current client. The defaultvalue is the nominal value of the ABAP system field sy-mandt . In reads with an ABAP SQL statement (with the addition USING CLIENT ) and in calls of anAMDP method from ABAP (inwhose declaration the addition AMDP OPTIONS CDS SESSION CLIENT is specified, the value specified here. |
system_language | Text environment language of the currentinternal session,nominal value of the ABAP system field sy-langu |
system_date | Current system dateof the AS ABAP, nominal value of the ABAP system field sy-datum |
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 ABAP SQL. If ABAP 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).
- 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 ABAP 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 ABAP 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.
- For input parameters of CDS views annotated with the special annotation environment.systemField, ABAP 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.
- When the ABAP SQL statement
SELECT
is used to access a CDS view that uses the session client client, the additionUSING CLIENT
can be used and is respected in the session variable for the duration of the ABAP SQL statement. The additionsUSING [ALL] CLIENTS [IN]
plus the obsolete additionCLIENT SPECIFIED
cannot be used.
- In the CDS database view of a CDS 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-specific views that access the session variable client directly can be buffered.
Example
The following CDS view contains the possible session variables in the SELECT
list. The program DEMO_CDS_SESSION_VARIABLES uses ABAP SQL to access the
view and fills the session variables with the associated values. Here, it is possible to define whether USING CLIENT
is used or not.
@AccessControl.authorizationCheck: #NOT_ALLOWED
define view demo_cds_session_variables
as select from
demo_expressions
{
id,
$session.user as system_user,
$session.client as system_client,
$session.system_language as system_language,
$session.system_date as system_date
}
Example
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 ABAP 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 program
DEMO_CDS_T100 uses ABAP 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.
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_select_t100
as select from
demo_cds_select_t100_langu( p_langu: $session.system_language )
{
*
}
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_select_t100_langu
with parameters
@Environment.systemField:#SYSTEM_LANGUAGE
p_langu : lang
as select from
t100
{
*
}
where
sprsl = :p_langu
and arbgb = 'SABAPDEMOS'