ABAPMETHODS_AMDP_OPTIONS - METHODS AMDP OPTIONSGeneral Material Data CPI1466 during Backup
This documentation is copyright by SAP AG.
[CLASS-]METHODS, AMDP OPTIONS
[CLASS-]METHODS meth ... AMDP OPTIONS $[READ-ONLY$]
$[CDS SESSION CLIENT clnt$|CURRENT$] ...
The addition AMDP OPTIONS for METHODS and CLASS-METHODS statements can be used to declare properties of AMDP methods of global classes or interfaces. After AMDP OPTIONS, at least one property must be specified.
If the addition AMDP OPTIONS is used in the declaration of a method, but the method is implemented as a regular ABAP method without the addition BY DATABASE PROCEDURE|FUNCTION, the properties specified by AMDP OPTIONS are ignored. However, the following restrictions for AMDP methods apply to the method declaration:
- If there is no RETURNING parameter, the restrictions for AMDP procedure implementations apply.
- If there is a RETURNING parameter, the restrictions described for AMDP function implementations also apply.
A prerequisite for using this addition is that the global class or the interface must contain a
AMDP classes. AMDP OPTIONS cannot be used in local classes, for the
constructor or class_constructor, for
event handlers declared with FOR EVENT, for
redefinitions declared with REDEFINITION, or for
AMDP function implementations for
functions declared with FOR TABLE FUNCTION.
If the option READ-ONLY is specified, only reads of database tables are allowed in the implementation of the database procedure or database function. Only database procedures or database functions of other AMDP methods that are also marked as READ-ONLY can be called. This is checked during the syntax check or at runtime.
This property can also be specified using the addition OPTIONS in the implementation of an AMDP method with METHOD meth BY DATABASE PROCEDURE|FUNCTION. It applies when specified either in the declaration or in the implementation of the method, or in both places.
The option READ-ONLY must be specified at least once in the implementation of an
AMDP function or an
L procedure. If the addition AMDP
OPTIONS is used in the declaration of a method with a RETURNING parameter, the option READ-ONLY must already be specified in the declaration.
... CDS SESSION CLIENT clnt$|CURRENT
If the option CDS SESSION CLIENT is used, the session variable of the database that can be addressed in the CDS DDL of the ABAP CDS under the name $session.client (CDS view entity, ) is supplied with a value when the AMDP method is called from ABAP. On the SAP HANA database this is the ABAP-specific session variable CDS_CLIENT. The value is determined as follows:
- The name of an input parameter of the current method can be specified for clnt. Its type must be compatible with the built in type CLNT in the ABAP Dictionary. The session variable is set to the value passed to this parameter during the call, or to the value of the replacement parameter declared with DEFAULT.
- If CURRENT is specified, the session variable is set to its default value, that is, to the nominal value of the ABAP system field sy-mandt or the client of the current logon. In this case there can be no input parameters with the name current.
The session variable is only set when the AMDP method is called from ABAP. If the associated database procedure or function is called from another AMDP method or from a database procedure or function that is not managed by AMDP, the session variable is not affected.
If the database procedure or function of an AMDP method that is declared with the option CDS SESSION CLIENT is called from an AMDP procedure or function implementation or during a SELECT statement, the following rules apply:
- AMDP method as call target
- The implementation of an AMDP method that is declared with the addition CURRENT can only be called in implementations of methods with the addition CURRENT, and not during the execution of a SELECT statement with the addition USING CLIENT.
- The implementation of an AMDP method declared with clnt can only be called in implementations of methods where the addition CURRENT or clnt is specified, and during the execution of a SELECT statement with the addition USING CLIENT.
- The implementation of an AMDP method that is declared without any additions can be called by any implementations and during the execution of any SELECT statements.
- AMDP method as caller
- The implementation of an AMDP method that is declared with the addition CURRENT can call any implementations.
- The implementation of an AMDP method declared with clnt cannot call any implementations of methods where CURRENT is specified.
- The implementation of an AMDP method that is declared without any additions can only call other implementations of this type.
If an AMDP method accesses the CDS-managed DDIC view of a , whose client handling is defined by the annotation @ClientHandling.algorithm: #SESSION_VARIABLE, it must be declared with the option CDS SESSION CLIENT. If not, a syntax error occurs.
- The option CDS SESSION CLIENT is mainly required if an AMDP method accesses the CDS-managed DDIC view of a , whose client handling is determined by the annotation @ClientHandling.algorithm: #SESSION_VARIABLE. In such DDIC database views, the session variable belonging to $session.client is usually evaluated in comparisons with a client column. If the option CDS SESSION CLIENT is not used when calling AMDP methods or the addition USING CLIENT in , the default value for the session variable would be the nominal value of the ABAP system field sy-mandt. By setting the session variable when an AMDP method is called, the CDS-managed DDIC views that are used select the data of the required client. If, in the implementation of the AMDP method, there is a separate selection of a client ID when the CDS-managed DDIC view is accessed that does not match the value of the session variable, the result set is empty.
- If CDS SESSION CLIENT is used for an AMDP method, the AMDP framework sets the session variable belonging to $session.client exactly once when this method is called from ABAP. The following recommendations apply:
- The value of the input parameter marked with clnt should be handled as a constant and should not be changed when executing the implementation, so that it always matches the value of the session variable. When calling other implementations of AMDP methods that are declared with CDS SESSION CLIENT, only the client ID that matches the value of the session variable should be passed.
- The value of the session variable should not be overwritten using database methods.
- This ensures that explicit use of the input parameter in self-programmed conditions and implicit use in CDS-managed DDIC views accesses the data of the same client.
- The rules for reciprocal callability of AMDP methods declared with the option CDS SESSION CLIENT support the previous point:
- In a call chain that leads to a method with the addition CURRENT, the session variable that belongs to $session.client can only have the nominal value of the ABAP system field sy-mandt.
- In a call chain that leads to a method that specifies clnt, the session variable that belongs to $session.client can have a value defined explicitly by clnt.
- In AMDP methods that do not access a CDS-managed DDIC view of a , whose client handling is defined by the annotation @ClientHandling.algorithm: #SESSION_VARIABLE, the option CDS SESSION CLIENT can be used to set $session.client to a particular value, but this is generally not necessary. Instead of accessing the session variables for the client ID in the implementation, these should be passed to an input parameter and this should then be used (see the executable example).
Client handling is defined using the annotation @ClientHandling.algorithm: #SESSION_VARIABLE. For this reason, the version of the view in the database contains the following WHERE condition (in this case for the SAP HANA database):
WHERE ( "SPFLI"."MANDT" = SESSION_CONTEXT( 'CDS_CLIENT') )
This WHERE condition applies each time the view is accessed. If the SELECT statement in the above AMDP method had its own WHERE condition for the client column MANDT and this would select a client other than the session variable CDS_CLIENT, the result set would be empty. For this reason, accessing such a CDS-managed DDIC view in an AMDP method causes a syntax check warning by default. This warning can be bypassed using the addition AMDP OPTIONS CDS SESSION CLIENT when declaring the method in the class CL_DEMO_AMDP_SESSION_CLIENT:
CLASS cl_demo_amdp_session_client DEFINITION
TYPES t_connections TYPE STANDARD TABLE OF demo_cds_prjct0a
WITH EMPTY KEY.
AMDP OPTIONS READ-ONLY
CDS SESSION CLIENT clnt
IMPORTING VALUE(clnt) TYPE sy-mandt
EXPORTING VALUE(connections) TYPE t_connections
When the method is called from ABAP, the session variable CDS_CLIENT is set to the value passed to the input parameter clnt. The program DEMO_AMDP_SESSION_CLIENT calls the AMDP method and it is possible to enter different values for the client ID. The data of the relevant client is selected.
BAL_S_LOG - Application Log: Log header data Vendor Master (General Section)
This documentation is copyright by SAP AG.
Length: 20081 Date: 20231003 Time: 054900 sap01-206 ( 293 ms )