SAP CDS SESSION VAR APPLICATION V2



Get Example source ABAP code based on a different SAP table
  


• bs_instance_id ABAP_CDS_SESS_VAR_V2
• bs_zone_id ABAP_CDS_SESS_VAR_V2

ABAP_CDS_DDL - CDS View Entity, Application Session Variables

ABAP_SYNTAX
... $session.vname ...

What does it do?
Specifies an application session variable vname in an operand position in a SELECT statement of a CDS view entity. The variable must be prefixed by $session..
Application session variables are required for specific applications and they can be set by dedicated system programs using a special system class. The following application session variables exist: <(>vname<)>Value when accessed
bs_instance_idInstance ID of the current business service instance. The returned value has the data type SSTRING.
bs_zone_idZone ID of the current business service instance. The returned value has the data type SSTRING.

ABAP_PREREQUISITE
A CDS view entity that accesses an application session variable must be usable as replacement object. That implies that the respective CDS view entity must not have any input parameters.
ABAP_PREREQ_END



Latest notes:

From a technical perspective, session variables indicate global variables of the current database. Application session variables are set to their value by dedicated system programs using a special system class. Like ABAP system fields, they are modifiable from an ABAP program. However, they should not be changed in application programs. They should only be used for reads. Otherwise, important information for further program execution may be lost.
The annotation environment.systemField is relevant for built-in session variables, but not for application session variables.
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.
Application session variables are supported only in CDS view entities. However, it is possible to build a ABAP_CDS_V1_VIEW on top of a CDS view entity with application session variables. The information is passed on to the ABAP_CDS_V1_VIEW in this case.
NON_V5_HINTS
ABAP_HINT_END

ABAP_RESTRICTIONS
CDS view entities with application session variables cannot be used in AMDP, since AMDP does not support application session variables.
The ADT function Data Preview does not work for CDS view entities with application session variables.
ABAP_RESTR_END
BEGIN_SECTION SAP_ONLY



Example ABAP Coding

The following CDS view entity contains the application session variable bs_instance_id in its SELECT list. The following program sets a value for this session variable, using the ABAP class CL_OSQL_EXTERNAL_CONTEXT. The class must be used within a procedure, otherwise an exception occurs.
DDLS DEMO_CDS_APPLICATION_SESS_VAR
ABAP_CAUTION This program demonstrates the setting of application session variables for internal system purposes. You should not set or overwrite application session variables as shown in the example in application programs, since important information for further program execution may be lost.
ABEXA 01647
ABAP_EXAMPLE_END
END_SECTION SAP_ONLY