SAP CDS VIEW CLIENT HANDLING V1



Get Example source ABAP code based on a different SAP table
  



ABAP_CDS - Client Handling in CDS DDIC-Based Views
For a ABAP_CDS_V1_VIEW in ABAP CDS, the CDS annotation @ClientHandling can be used to specify client handling.
ITOC

Determining Client Dependency
The annotation @ClientHandling.type determines the client dependency of the view. The following values can be specified for the annotation:

<(>#INHERITED<)>
Default value. The client dependency of the 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 a client-independent view.

<(>#CLIENT_DEPENDENT<)>
The view is client-dependent. A prerequisite for this is that at least on of the data sources used in the view is client-dependent. If not, a syntax error occurs.

<(>#CLIENT_INDEPENDENT<)>
The view is a client-independent view. A prerequisite for this is that none of the data sources used in the view is client-dependent. If not, a syntax error occurs.



Latest notes:

CDS views for application data should usually be client-dependent.
Unlike the annotation @ClientDependent, the annotation @ClientHandling.type cannot be used to make a ABAP_CDS_V1_VIEW into a client-independent view if it contains client-dependent data sources.
If the annotation @ClientHandling.type is not specified, client dependency is derived implicitly from the client dependency of the data sources uses, as when specified with the value #INHERITED.
NON_V5_HINTS
The annotation @ClientHandling.type replaces the annotation @ClientDependent and should be used instead of this annotation.
ABAP_HINT_END

Determining Client Handling
The annotation @ClientHandling.algorithm determines how implicit client handling is performed. The following values can be specified for the annotation:

<(>#AUTOMATED<)>
Default value for the values #INHERITED and #CLIENT_DEPENDENT of the annotation @ClientHandling.type. Cannot be used together with its value #CLIENT_INDEPENDENT.
The value #AUTOMATED expands the joins of the ABAP_CDS_V1_VIEW implicitly as shown in the following table. In the case of outer joins, client-independent sides are made into client-dependent sides artificially using cross joins, which avoids null values. This applies to joins specified directly using JOIN and 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-The left side is replaced by a cross join of the client-independent data source with the DDIC database table T000 and a comparison of the client columns in the ON condition.--
Client-dependentClient-independent--The right side is replaced by a cross join of the client-independent data source with the DDIC database table T000 and the client columns are compared in the ON condition.-
Client-independentClient-independent--- -

<(>#SESSION_VARIABLE<)>
Cannot be used together with the value #CLIENT_INDEPENDENT of the annotation @ClientHandling.type.
The value #SESSION_VARIABLE expands the joins of the ABAP_CDS_V1_VIEW implicitly as shown in the following table. This applies to joins specified explicitly and directly using JOIN and 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 data 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.
If the session variable $session.client is evaluated in the view, it is not possible to access the data of different clients in a single read. This applies in the following cases:
When a client-dependent DDIC database table is a data source of the view or is a CDS view used as a data source and hence an implicit WHERE clause exists for the session variable.
When client-dependent and client-independent sides are joined in an outer join and there is an implicit ON condition for the session variable.
The addition USING of the statement SELECT for switching implicit client handling is allowed and the client specified here is used implicitly.
BEGIN_SECTION VERSION 5 OUT The obsolete addition CLIENT SPECIFIED is then not allowed.
END_SECTION VERSION 5 OUT

<(>#NONE<)>
Default value for the value #CLIENT_INDEPENDENT of the annotation @ClientHandling.type. Cannot be used together with its values INHERITED and #CLIENT_DEPENDENT. No implicit client handling takes place.



Latest notes:

If a view with the value #INHERITED of the annotation @ClientHandling.type is a client-independent view, no implicit client handling takes place and the values #AUTOMATED and #SESSION_VARIABLE are ignored.
If no annotation @ClientHandling.type is specified, the annotation @ClientHandling.algorithm can be specified with the values #AUTOMATED or #SESSION_VARIABLE for the default value #INHERITED.
If an annotation @ClientHandling.type is specified but an annotation @ClientHandling.algorithm is not specified, the value #AUTOMATED is set in #INHERITED and #CLIENT_DEPENDENT implicitly and the value #NONE is set in #CLIENT_INDEPENDENT, also implicitly.
If none of the annotations is specified, the default values #INHERITED for @ClientHandling.type and #AUTOMATED for @ClientHandling.algorithm apply.
The value #NONE can only be specified for views declared explicitly as client-independent views. If specified for views declared explicitly as client-dependent views using #CLIENT_DEPENDENT, self-programmed client handling would be required and this is not currently supported.
The values #AUTOMATED and #SESSION_VARIABLE produce the same result when a client-dependent CDS view is used. They modify the way client handling is implemented internally, but do not modify the definition of the view or, its use. The value #SESSION_VARIABLE can improve performance by concentrating on a single client.
NON_V5_HINTS
If the value #SESSION_VARIABLE is specified, the obsolete addition CLIENT SPECIFIED of the statement SELECT is forbidden in cases where the session variable $session.client is actually in use in the view in question. More specifically, specifying a client-dependent view in a CDS association does not necessarily mean that the session variable is used. The session variable is used only if the CDS association in the view is created with an implicit ON condition for the session variable.
The only exception to the latter is that the values #AUTOMATED and #SESSION_VARIABLE have an effect on the obsolete addition CLIENT SPECIFIED in ABAP SQL.
ABAP_HINT_END

Properties of Client-dependent ABAP_CDS_V1_VIEWS .
In AB_SQL reads, the client dependency of a CDS view has the following consequences for the CDS entity and any associated ABAP_CDS_MNG_VIEW :
CDS entity
The view fields of the CDS entity of a client-dependent CDS view do not cover a client column. A client column of a client-dependent CDS view specified explicitly in the SELECT list is also not a component of the structured data type represented by the CDS entity and is removed implicitly from the result set of a SELECT statement.
If SELECT is used to access a client-dependent CDS entity, the data of the current client or the client specified in the addition USING is read implicitly.
BEGIN_SECTION VERSION 5 OUT If the obsolete addition CLIENT SPECIFIED is specified, the column is added to the result set and is filled with the associated client ID for each row. Before this column can be used in the SELECT statement, a name must be assigned to it after the addition CLIENT SPECIFIED. If the name is not defined, no addressing is possible in a clause and no inline declarations can be made using @DATA$|@FINAL(...) after INTO. The defined name is also used in the case of INTO CORRESPONDING . If no name is defined, the client column is not transported.
END_SECTION VERSION 5 OUT
ABAP_CDS_MNG_VIEW
The view fields of a ABAP_CDS_MNG_VIEW of a client-dependent CDS view always cover a client column. This applies regardless of whether the client column is specified in the SELECT list.
If an obsolete access is made on the ABAP_CDS_MNG_VIEW using SELECT, the view is handled in accordance with regular implicit client handling, which itself can be defined using the addition USING.
The name of the client column of a ABAP_CDS_MNG_VIEW with activated client handling is defined in accordance with the following hierarchy: If the client column is specified in the SELECT list, its name or its alternative name is used. If the client column is not specified in the SELECT list, MANDT is used. If MANDT is already used as an (alternative) element name in the SELECT list, CLIENT is used. If neither MANDT or CLIENT is possible, a syntax error occurs.



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, whose client handling is defined using the annotation @ClientHandling.algorithm:#SESSION_VARIABLE, 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 produced 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

ABAP_EXAMPLE_ABEXA
CDS Views, Client Handling
ABAP_EXAMPLE_END