SAP CDS FUNC CLIENT HANDLING Get Example source ABAP code based on a different SAP table
SAP Help
VERSION 5 IN
ABAP_CDS - Client Handling in CDS Table Functions The
CDS annotation> @ClientHandling.type>> can be used to enable and disable client dependency> for a CDS table function in ABAP CDS. The value #CLIENT_DEPENDENT> enables client dependency. The value #CLIENT_INDEPENDENT> disables client dependency. Client dependency is enabled 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-Dependent CDS Table Function The element list> of a client-dependent 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-dependent CDS table function is accessed using SELECT>> BEGIN_SECTION VERSION 5 OUT without the obsolete addition CLIENT SPECIFIED>>, END_SECTION VERSION 5 OUT only those rows are selected implicitly from the result 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-dependent 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 result 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 AB-SQL statement SELECT>> only acts on the session variable CDS_CLIENT>. If the AMDP function is used in an AMDP method called from ABAP, there is no equivalent for USING CLIENT>. 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 Client-Independent CDS Table Function The element list> of a client-independent 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 client-independent 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 client-independent CDS table function. Latest notes: CDS table functions for application data should usually be client-dependent. NON_V5_HINTS 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. ABAP_HINT_END ABAP_EXAMPLE_VX5 The following client-dependent 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>. DDLS DEMO_CDS_GET_CLIENT_VARIABLES The AMDP function implementation is as follows: METH CL_DEMO_AMDP_CLIENT_VARIABLES=>GET The first line 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. BEGIN_SECTION VERSION 5 OUT The class CL_DEMO_AMDP_CLIENT_VARIS>> 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. END_SECTION VERSION 5 OUT ABAP_EXAMPLE_END ABAP_EXAMPLES_ABEXA Client-Dependent CDS Table Functions > Client-Independent CDS Table Functions> ABAP_EXAMPLE_END