SAP CDS V2 VIEW CLIENT HANDLING



Get Example source ABAP code based on a different SAP table
  



ABAP_CDS - Client Handling in CDS View Entities
For a CDS view entity, client handling is done implicitly and automatically by filtering the client session variable $session.client.
You cannot manipulate this. Client handling annotations are not available.
ITOC

Determining Client Dependency
The client dependency of a view is determined by the data sources used:
If one of the data sources used in the view is client-dependent, the view is client-dependent.
If none of the data sources used in the view is client-dependent, the view is client-independent.

Determining Client Handling
If a CDS view entity is client-dependent, the client handling is performed by filtering the client session variable $session.client. The session variable algorithm expands the joins of the view entity implicitly as shown in the following table. This applies to joins specified explicitly using JOIN, as well as to instances of joins created when using SQL path expressions. Left SideRight SideINNER JOIN LEFT OUTER JOINRIGHT OUTER JOINCROSS JOIN
Client-dependentClient-dependentCompares the client columns in the ON conditionCompares the client columns in the ON conditionCompares the client columns in the ON condition Transforms the cross join to an inner join using an ON condition for the client columns
Client-independentClient-dependent-Compares the client column with the value of the session variable $session.client in the ON condition--
Client-dependentClient-independent--Compares the client column with the value of the session variable $session.client in the ON condition-
Client-independentClient-independent--- -
In addition, when client-dependent database tables are accessed, WHERE clauses with comparisons of the client columns with the session variable $session.client are added to the view implicitly. If only client-dependent CDS entities are accessed, however, no clauses are added.
It is not possible to access the data of different clients in a single read.
The addition USING of the statement SELECT for switching implicit client handling is not allowed for CDS view entities.
BEGIN_SECTION VERSION 5 OUT The obsolete addition CLIENT SPECIFIED is not allowed either.
END_SECTION VERSION 5 OUT

ABAP_EXAMPLE_VX5
The following CDS view entity DEMO_CDS_CLIENT_HANDLING defines different kinds of joins (left outer join, inner join, and right outer join) between a client-independent database table ( T000 ) and a client-dependent database table ( DEMO_SALES_ORDER). It also defines and uses an association between the same client-independent database table (T000 ) and the same client-dependent database table (DEMO_SALES_ORDER ).
DDLS DEMO_CDS_CLIENT_HANDLING
The image below shows the SQL statement that is generated on the SAP HANA database. For the left outer join, an ON condition is added that compares the client field of the database table DEMO_SALES_ORDER with the current client. The current client is determined using the built-in SAP HANA function SESSION_CONTEXT ('CDS_CLIENT') , which is the equivalent to the session variable $session.client in ABAP CDS. In the same way, a WHERE clause is added that compares the client of the database table with the current client.
IMAGE ABDOC_CLIENT_HANDLING.png 628 457
ABAP_EXAMPLE_END

Properties of Client-Dependent CDS View Entities
Since client handling is performed completely implicitly in CDS view entities, a client field is not allowed in the SELECT list of a view entity. The result set of an AB_SQL read on a CDS view entity can never contain a client column either.



Latest notes:

NON_V5_HINTS
When client-dependent views are accessed via Native SQL or in an AMDP method, only the database object is accessed. The client ID must be specified as usual and only data in the current client should be accessed.
When the database object of a client-dependent CDS view entity is accessed using Native SQL or AMDP, note the following:
The session variable $session.client is usually used implicitly in the view. This is guaranteed only on SAP HANA databases used as standard AS ABAP databases under the name CDS_CLIENT. On other platforms, the existence and content of the session variable are not guaranteed outside of an AB-SQL access, and this can produce unexpected behavior or programs may crash.
No separate WHERE condition can be used that selects a client other than the session variable and the database-specific variant of the session variable $session.client must have the required value in Native SQL or AMDP reads. Outside an AB-SQL access, it contains the current client by default. The last point is particularly important for client handling in general AMDP procedure implementations on the SAP HANA database, which are called like regular methods in ABAP. When a database object is accessed, the value of the corresponding HANA session variable CDS_CLIENT must be set explicitly using the addition AMDP OPTIONS CDS SESSION CLIENT in the declaration of the AMDP method. If not, a syntax error occurs. In an AMDP function implementation that is used as a CDS table function in AB_SQL , however, the HANA session variable CDS_CLIENT is filled with the content defined there.
ABAP_HINT_END