Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Data Definitions →  ABAP CDS - Views →  ABAP CDS - Client Handling in CDS Views 

CDS Views, Client Handling

This example demonstrates how client-specific CDS views are handled.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(out) = cl_demo_output=>new( ).

    out->next_section( 'Data Types' ).

    out->write(
      name = 'Client dependent, no client field, CDS entity'
      data = CAST cl_abap_structdescr(
                    cl_abap_typedescr=>describe_by_name(
                      'DEMO_CDS_SPFLI_CLIENT_0' )
                        )->components ).

    out->write(
      name = 'Client dependent, no client field, database view'
      data = CAST cl_abap_structdescr(
                    cl_abap_typedescr=>describe_by_name(
                      'DEMO_CDS_PRJCTN0' )
                        )->components ).

    out->write(
      name = 'Client dependent, client field, CDS entity'
      data = CAST cl_abap_structdescr(
                    cl_abap_typedescr=>describe_by_name(
                      'DEMO_CDS_SPFLI_CLIENT_1' )
                        )->components ).

    out->write(
      name = 'Client dependent, client field, database view'
      data = CAST cl_abap_structdescr(
                    cl_abap_typedescr=>describe_by_name(
                      'DEMO_CDS_PRJCTN1' )
                        )->components ).

    out->next_section( 'SELECT Statements' ).

    SELECT *
           FROM demo_cds_spfli_client_0
           ORDER BY carrid, connid
           INTO TABLE @DATA(result1)
           UP TO 1 ROWS.
    out->write(
      name = 'Client dependent, no client field, CDS entity'
      data = result1 ).

    SELECT *
           FROM demo_cds_prjctn0
           ORDER BY carrid, connid
           INTO TABLE @DATA(result2)
           UP TO 1 ROWS.
    out->write(
      name = 'Client dependent, no client field, database view'
      data = result2 ).

    SELECT *
           FROM demo_cds_spfli_client_0
                CLIENT SPECIFIED demo_cds_spfli_client_0~myclient
           WHERE myclient = @sy-mandt
           ORDER BY carrid, connid
           INTO TABLE @DATA(result3)
           UP TO 1 ROWS.
    out->write(
      name = 'Client dependent, no client field, CDS entity,' &
             ' CLIENT SPECIFIED'
      data = result3 ).

    SELECT *
           FROM demo_cds_spfli_client_1
           ORDER BY carrid, connid
           INTO TABLE @DATA(result4)
           UP TO 1 ROWS.
    out->write(
      name = 'Client dependent, client field, CDS entity'
      data = result4 ).

    out->display( ).

Description

The program accesses the following CDS views:

@AbapCatalog.sqlViewName: 'DEMO_CDS_PRJCTN0'
@AccessControl.authorizationCheck: #NOT_ALLOWED
@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
    }
@AbapCatalog.sqlViewName: 'DEMO_CDS_PRJCTN1'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@ClientHandling.type: #CLIENT_DEPENDENT
@ClientHandling.algorithm: #AUTOMATED
define view demo_cds_spfli_client_1
  as select from
    spfli
    {
      key spfli.mandt,
      key spfli.carrid,
      key spfli.connid,
          spfli.cityfrom,
          spfli.cityto
    }    

The view DEMO_CDS_SPFLI_CLIENT_0 is a regular client-specific CDS view in which the client column is not specified in the SELECT list. The view DEMO_CDS_SPFLI_CLIENT_1 is used to demonstrate the behavior in rare cases where the client column is specified in the SELECT list of a client-specific CDS view.

RTTI is used to read the components of the associated data types:

  • The structure of the client-specific CDS entity without client column in the SELECT list does not have a client column.
  • The database view of the client-specific CDS view without client column in the SELECT list has a client column.
  • Nevertheless, the structure of the client-specific CDS entity with client column in the SELECT list does not have a client column.
  • The database view of the client-specific CDS view with client column in the SELECT list has a client column.

The statement SELECT is used to make the following accesses:

  • Regular access to a client-specific CDS entity without client column in the SELECT list. The data from the current client is read. The results set does not have a client column.
  • Regular access to a database view of the client-specific CDS entity without client column in the SELECT list. The data from the current client is read. The results set has a client column.
  • Access to a client-specific CDS entity without client column in the SELECT list using the obsolete addition CLIENT SPECIFIED. The data of the client specified in the WHERE condition is read. A name myclient must be defined for this. The results set has a client column with this name.
  • Regular access to a database view of the client-specific CDS entity with client column in the SELECT list. The data from the current client is read. The results set does not have a client column.

The similar program DEMO_CDS_CLIENT_HANDLING_SV accesses CDS views in which the annotation @ClientHandling.algorithm: #SESSION_VARIABLE is used instead of @ClientHandling.algorithm: #AUTOMATED. The results are shown in exactly the same way as here, however access using the obsolete addition CLIENT SPECIFIED is not possible since the session variable $session.client is evaluated implicitly in the views.


Note

The accesses to the database views of the CDS shown here are for demonstration purposes only. This way of accessing CDS views is obsolete and only the CDS entities should now be accessed.