Skip to Content

Open SQL supports an automatic client handling. By default only the data of the current client are taken into account, when you access client dependent data sources with Open SQL.

What are client dependent data sources?

 

  • A database table or classic view defined in the ABAP Dictionary is client dependent if the first column is a client column with the built-in dictionary type CLNT.
  • The client dependency and client handling of CDS entities (CDS views and CDS table functions) is defined by annotations. With release 7.51 a new annotation @CLientHandling is introduced for that. The previous annotation @ClientDependent becomes obsolete.

CDS Views

For CDS views you use the annotation @CLientHandling in order to define the client dependency and how client handling is done internally. For that you can specify the following two sub annotations:

@ClientHandling.type: #INHERITED | #CLIENT_DEPENDENT | #CLIENT_INDEPENDENT

Determines the client dependency.

 

  • With the value #INHERITED (default) the client dependency of the view is determined by the data sources used. If one of the data sources used in the view is client dependent, the view is client dependent. If none of the data sources used in the view is client dependent, the view is client independent.
  • With the value #CLIENT_DEPENDENT the view is client dependent. At least one of the data sources must be client dependent.
  • With the value #CLIENT_INDEPENDENT the view is client independent. None of the data sources can be client dependent.
@ClientHandling.algorithm #AUTOMATED | #SESSION_VARIABLE | #NONE

Determines the client handling.

 

  • If the value #AUTOMATED (default for client dependent views) is specified, the ON conditions of the view and other clauses are implicitly extended by conditions for the client columns of the underlying data sources. If a client independent data source as the left side of a left outer join is joined with a client dependent data source on the right side, the left side is replaced by a cross join of the client independent data source with the database table T000 containing all clients. This makes the left side client dependent artificially and avoids NULL values.
  • If the value #SESSION_VARIABLE is specified, additionally to the above extensions implicit WHERE conditions are added, that select the client that is currently stored in the session variable $session.client. During an Open SQL access this session variable contains the current client or the one set by the USING CLIENT addition. The result is the same as for #AUTOMATED but the performance can be better.
  • The value #NONE is possible for client independent views only and it is their default.

If you don’t specify @CLientHandling explicitly, it is the same as

@ClientHandling.type:#INHERITED
@ClientHandling.algorithm:#AUTOMATED

A client-specific CDS view has no client column. If you use Open SQL SELECT to access a client-specific CDS view, the data of the current client or the client specified in the addition USING CLIENT is read implicitly.

The following is an example for a simple client dependent projection view.

@AbapCatalog.sqlViewName: 'DEMO_CDS_PRJCTN0' 
@AccessControl.authorizationCheck: #NOT_REQUIRED 
@ClientHandling.type: #CLIENT_DEPENDENT 
@ClientHandling.algorithm: #AUTOMATED 
define view demo_cds_spfli_client_0 
  as select from 
    spfli 
    { 
      key spfli.carrid, 
      key spfli.connid, 
          spfli.cityfrom, 
          spfli.cityto 
    } 

The structure of this client dependent CDS view does not comprise a client column. An Open SQL SELECT for that view reads the data from the current client but the result set does not contain the client fields.

CDS Table Functions

Compared to CDS views the definition of client dependency and client handling for CDS table functions is simpler:

@ClientHandling.type:  #CLIENT_DEPENDENT 
Switches client dependency on (default).
@ClientHandling.type:  #CLIENT_INDEPENDENT 

Switches client dependency off.

 

  • For a client dependent table function, the element list must have an explicit client field as its first element. This field is a column of return value of the associated AMDP function implementation but it is not a component of the structured data type of the CDS entity. When a client-specific CDS table function is accessed with Open SQL SELECT, only those rows are selected from the result set that belong to the current client or the client specified in the addition USING CLIENT. The Native SQLScript implementation of the AMDP function must ensure that all required data is made available.
  • A client independent 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 normal column of the return value of the associated AMDP unction implementation and also a regular component of the structured data type of the CDS entity. When a client independent CDS table function is accessed using Open SQL SELECT, a column of the type CLNT does not have a special meaning and is handled like any other element.

The following is an example for a client dependent CDS table function.

ClientHandling.type: #CLIENT_DEPENDENT 
define table function DEMO_CDS_GET_SCARR_SPFLI_INPCL 
  with parameters 
    @Environment.systemField: #CLIENT 
    clnt   :abap.clnt, 
    carrid :s_carr_id 
  returns 
  { 
    client   :s_mandt; 
    carrname :s_carrname; 
    connid   :s_conn_id; 
    cityfrom :s_from_cit; 
    cityto   :s_to_city; 
  } 
  implemented by method 
    CL_DEMO_AMDP_FUNCTIONS_INPCL=>GET_SCARR_SPFLI_FOR_CDS; 

It has an input parameter CLNT of the type CLNT with the annotation @Environment.systemField:#CLIENT.  The current client is passed to this parameter implicitly in an Open SQL SELECT. The implementation in the AMDP method GET_SCARR_SPFLI_FOR_CDS of the associated AMDP class CL_DEMO_AMDP_FUNCTIONS_INPCL can use this input parameter to restrict the result set to the current client.

Obsolete Client Handling

The previous annotation

@ClientDependent : true | false 

is obsolete now.

For CDS views, the value true works mainly like

@ClientHandling.type:#INHERITED
@ClientHandling.algorithm:#AUTOMATED

and the value false works mainly like

@ClientHandling.type:#CLIENT_INDEPENDENT
@ClientHandling.algorithm:#NONE

For CDS table functions, the values true and false work like

@ClientHandling.type: #CLIENT_DEPENDENT |  #CLIENT_INDEPENDENT

The new annotation @CLientHandling with its sub annotations was introduced because it offers more possibilities compared to @ClientDependent, which it replaces. Only for CDS views, there is a small difference: You can use @ClientDependent:false to define client independent views that contain client dependent data sources. But this is usually not such a good idea. Especially when the CDS database view is accessed instead of the CDS entitiy, unexpected behavior can occur. Therefore, the restriction of the new annotation can be seen as a cleanup.

For more information, see

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply