AMDP does not support automatic
client handling. When accessing client-specific database tables or views in an AMDP method, the
required client ID must be selected explicitly. Therefore, the parameter interface of an AMDP method
must usually contain an input parameter for the client ID, and this must be used in a WHERE condition. Exceptions to this rule are explained in the note below.
Notes
Using an input parameter for the client ID is particularly advisable for
AMDP function implementations of
client-specific CDS table functions. In
Open SQL reads, only the data of the current client or clients specified using USING CLIENT in the results set is respected by default. Selecting this
precise data in the function implementation is recommended both for performance reasons and for making sure that the correct data is read.
In SQLScript implementations, the built-in
function SESSION_CONTEXT can be used to access the
ABAP-specific session variablesCLIENT
and CDS_CLIENT of the SAP HANA database too. In a call from ABAP, these variables contain a client ID:
CLIENT always contains the nominal value of the ABAP system field sy-mandt.
CDS_CLIENT contains the same value as CLIENT
by default, but can be modified during the execution of an Open SQL statement by the addition USING CLIENT and in an AMDP method call from ABAP by the addition AMDP OPTIONS CDS SESSION CLIENT.
Access of this type should be used only if it is verifiable that an AMDP method is called only from
ABAP and accesses exactly the data of this client ID. In other cases, the result is undefined. Therefore,
it is usually recommended to use an input parameter to pass the required client ID to AMDP functions and use it as an access condition.
An exception to this rule is when reading CDS database views of
client-specific CDS views whose client handling
is defined by the annotation @ClientHandling.algorithm:#SESSION_VARIABLE. A database view of this type usually evaluates the
session variable of
the database that is mapped to the CDS session variable
$session.client. In a SAP HANA database this is the HANA session variable CDS_CLIENT. If, in the implementation of an AMDP method, a WHERE
condition selects a client ID other than that contained in the session variable CDS_CLIENT,
the results set is empty in this case. For this reason, if this type of CDS database view is accessed
in an AMDP method, the syntax check issues a warning and an exception of the class CX_AMDP_CDS_CLIENT_MISMATCH
is raised in the call. The session variable must be set to the required value in the implementation
of the AMDP method, instead of a WHERE condition for the client ID. The
addition AMDP OPTIONS CDS SESSION
CLIENT can be used for this purpose in the declaration of the method with METHODS OR CLASS-METHODS.
This addition prevents the warning before the syntax check and the exception. However, this is only significant for general
AMDP procedure implementations, which are called in the same way as normal methods in ABAP. In an
AMDP function implementation that is used as a
CDS table function
in the Open SQL statement SELECT,
the session variable can be set with the addition USING
CLIENT. See the example for the option SESSION CLIENT.
Example
The executable example of how to implement an SQLScript procedure
demonstrates explicit client handling using an input parameter and using the ABAP-specific session variable CLIENT.