ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  AMDP - ABAP Managed Database Procedures →  AMDP - Methods → 

[CLASS-]METHODS - AMDP OPTIONS

Quick Reference

Syntax

[CLASS-]METHODS meth ... AMDP OPTIONS [READ-ONLY]
                                      [CDS SESSION CLIENT clnt|CURRENT] ...


Extras:

1. ... READ-ONLY

2. ... CDS SESSION CLIENT clnt|CURRENT

Effect

The addition AMDP OPTIONS for METHODS and CLASS-METHODS statements can be used to declare attributes of AMDP methods of global classes or interfaces. After AMDP OPTIONS, at least one attribute must be specified.

If the addition AMDP OPTIONS is used in the declaration of a method, but the method is implemented as a normal ABAP method without the addition BY DATABASE PROCEDURE|FUNCTION, the attributes specified byAMDP OPTIONS are ignored. However, the following restrictions for AMDP methods apply to the method declaration:

A prerequisite for using this addition is that the global class or the interface must contain a tag interface IF_AMDP_MARKER_... for AMDP classes. AMDP OPTIONS cannot be used in local classes, for the constructors constructor or class_constructor, for event handlers declared with FOR EVENT, for redefinitions declared with REDEFINITION, or for AMDP function implementations for CDS table functions declared with FOR TABLE FUNCTION.

Addition 1

... READ-ONLY

Effect

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 by the syntax check or at runtime.

This attribute 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 both.

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.

Addition 2

... CDS SESSION CLIENT clnt|CURRENT

Effect

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 is supplied with a value when the AMDP method is called from ABAP. In the SAP HANA database this is the ABAP-specific session variable CDS_CLIENT. The value is determined as follows:

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:

A call can occur during a SELECT statement if it directly or indirectly accesses a CDS table function, because this is implemented as an AMDP function.

Notes

Whether the input parameter is used explicitly in self-programmed conditions or implicitly in CDS database views, this ensures that the data of the same client is accessed.

Example

The following implementation of an AMDP method accesses the CDS database view DEMO_CDS_PRJCT0A of a client-specific CDS view:

METHOD get_spfli_view BY DATABASE PROCEDURE FOR HDB
                      LANGUAGE SQLSCRIPT
                      USING demo_cds_prjct0a.
  connections  = select *
                        from DEMO_CDS_PRJCT0A;
ENDMETHOD.

The DDL source code that defines the actual CDS entity DEMO_CDS_SPFLI_CLIENT_0A looks like this:

@AbapCatalog.sqlViewName: 'DEMO_CDS_PRJCT0A'
@AccessControl.authorizationCheck: #NOT_ALLOWED
@ClientHandling.type: #CLIENT_DEPENDENT
@ClientHandling.algorithm: #SESSION_VARIABLE
define view demo_cds_spfli_client_0a
  as select from
    spfli
    {
      key spfli.carrid,
      key spfli.connid,
          spfli.cityfrom,
          spfli.cityto
    }

The 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 selected a client other than the session variable CDS_CLIENT, the results set would be empty. For this reason, accessing such a CDS database view in an AMDP method causes the syntax check to issue a warning by default. This warning can be bypassed by 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
  PUBLIC
  FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb .
    TYPES t_connections TYPE STANDARD TABLE OF demo_cds_prjct0a
                        WITH EMPTY KEY.
    METHODS get_spfli_view
      AMDP OPTIONS READ-ONLY
                   CDS SESSION CLIENT clnt
      IMPORTING VALUE(clnt)        TYPE sy-mandt
      EXPORTING VALUE(connections) TYPE t_connections
      RAISING   cx_amdp_error.

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 client in question is selected.