ABAP Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions → ABAP CDS - Table Functions
ABAP CDS - Client Handling in CDS Table Functions
The CDS annotation @ClientHandling.type can be used to switch client dependency on and off for a CDS table function in ABAP CDS.
- The value #CLIENT_DEPENDENT switches client dependency on.
- The value #CLIENT_INDEPENDENT switches client dependency off.
Client dependency is switched on by default. The client dependency of a CDS table function has the following consequences for the CDS entity and the associated AMDP function implementation:
- Client-Specific CDS Table Function
- The element list of a client-specific CDS table function must have an explicit client field with the built-in dictionary type CLNT as its first element. The client field is a column of the tabular return value of the associated AMDP function implementation and is not a component of the structured data type represented by the CDS entity.
- When a client-specific CDS table function is accessed using
SELECT without the obsolete addition
CLIENT SPECIFIED, only those rows are selected implicitly from the results set of the function
that contain the ID of the current client or the client specified in the addition
USING CLIENT
in the client field.
- A CDS table function is always implemented in the associated AMDP method in platform-specific SQL. The implementation must ensure that all required data is made available. Particularly in the ON conditions of joins, client columns must be used correctly.
- For performance reasons, it is best to restrict the results set of the function to the required
clients at the implementation stage. This usually involves passing the client ID in question to an input
parameter of the function. Here, it is advisable to use an input parameter of the dictionary type CLNT,
which needs to be annotated with the annotation
@Environment.systemField and the predefined value
#CLIENT. In this case,
SELECT
passes the correct client ID implicitly.
- Note that if the ABAP-specific
session variables CLIENT and CDS_CLIENT are accessed in the implementation of a
CDS table function,
the addition
USING CLIENT
of the ABAP SQL statementSELECT
only acts on the session variableCDS_CLIENT. If the AMDP function is used in an AMDP method called from ABAP, there is no equivalent forUSING CLIENT
.
- If the obsolete addition CLIENT
SPECIFIED is specified, the column is added to the results 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 additionCLIENT SPECIFIED
. If the name is not defined, no addressing is possible in a clause and no inline declarations can be made using@DATA(...)
afterINTO
. The defined name is also used in the case ofINTO CORRESPONDING
. If no name is defined, the client column is not transported.
- Cross-Client CDS Table Function
- The element list of a cross-client CDS table function does not need to have an explicit client field with the built-in dictionary type CLNT. If the first element has the type CLNT, it does not function as a client field. Instead, it is a column of the tabular return value of the associated AMDP function implementation and also a regular component of the structured data type represented by the CDS entity.
- When a cross-client CDS table function is accessed using SELECT, an element of the type CLNT does not have a special meaning and is handled like any other element.
- The annotation @Environment.systemField: #CLIENT cannot be used in the parameter list of a cross-client CDS table function.
Other versions:
7.31 | 7.40 | 7.54
Notes
- CDS table functions for application data should usually be client-specific.
- The annotation @ClientHandling.type with the values #CLIENT_DEPENDENT and #CLIENT_INDEPENDENT replaces the annotation @ClientDependent with the values true and false and should be used instead of this annotation.
Example
The following client-specific CDS table function reads the ABAP-specific session variables CLIENT and CDS_CLIENT. The first element mandt of the element list is the client field. The other two elements return the read values. An input parameter clnt with the built-in dictionary type CLNT transfers the client ID and, as prescribed, is given the annotation @Environment.systemField:#CLIENT.
@AccessControl.authorizationCheck:#NOT_ALLOWED
define table function DEMO_CDS_GET_CLIENT_VARIABLES
with parameters
@Environment.systemField : #CLIENT
clnt : syst_mandt
returns
{
mandt :mandt;
client :mandt;
cds_client :mandt;
}
implemented by method
CL_DEMO_AMDP_CLIENT_VARIABLES=>GET;
The AMDP function implementation is as follows:
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
declare client_tab table( mandt "$ABAP.type( mandt )",
client "$ABAP.type( mandt )",
cds_client "$ABAP.type( mandt )" );
client_tab.mandt[1] := clnt;
client_tab.client[1] := session_context('CLIENT');
client_tab.cds_client[1] := session_context('CDS_CLIENT');
RETURN :client_tab;
ENDMETHOD.
The first row of a local table client_tab
with the type of the tabular return
value is supplied with the session variables. The client field is set to the value of the input parameter
clnt
and the table is returned. The program DEMO_AMDP_CLIENT_VARIABLES
accesses the CDS table function using SELECT
and the addition USING
CLIENT, and attempts to use a client ID other than that of the current client in the table
T000. The client ID specified with USING CLIENT
is passed implicitly
to the input parameter clnt and fills the client field of the return value with this ID, so that it is respected by
implicit client handling. If a client ID
other than that of the current client is used, the values of the session variables CLIENT and CDS_CLIENT are different.
Executable Examples
Continue
ABAP CDS - Obsolete Client Handling in Table Functions