Skip to content

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

Client-Specific CDS Table Functions

This example demonstrates client-specific CDS table functions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    IF NOT cl_abap_dbfeatures=>use_features(
          EXPORTING
            requested_features =
              VALUE #( ( cl_abap_dbfeatures=>amdp_table_function ) ) ).
      cl_demo_output=>display(
        `System does not support CDS table functions` ).
      RETURN.
    ENDIF.

    DATA carrid TYPE s_carr_id VALUE 'LH'.
    cl_demo_input=>request( CHANGING field = carrid ).
    carrid = to_upper( carrid ).

    SELECT *
           FROM demo_cds_get_scarr_spfli( carrid = @carrid )
           INTO TABLE @DATA(result1)
           ##db_feature_mode[amdp_table_function].
    cl_demo_output=>write( result1 ).

    SELECT *
           FROM demo_cds_get_scarr_spfli_inpcl( carrid = @carrid )
           INTO TABLE @DATA(result2)
           ##db_feature_mode[amdp_table_function].
    ASSERT result2 = result1.

    SELECT *
           FROM demo_cds_get_scarr_spfli( carrid = @carrid )
                CLIENT SPECIFIED demo_cds_get_scarr_spfli~client
           WHERE client = @sy-mandt
           INTO TABLE @DATA(result3)
           ##db_feature_mode[amdp_table_function].
    cl_demo_output=>display( result3 ).

Description

This example program accesses two client-specific CDS table functions.

  • The CDS table function DEMO_CDS_GET_SCARR_SPFLIdoes not have any input parameters of the type CLNT. The implementation in the AMDP method GET_SCARR_SPFLI_FOR_CDS of the associated AMDP class CL_DEMO_AMDP_FUNCTIONS reads the data of all clients. Only the current client is selected here in SELECTs.
@ClientHandling.type: #CLIENT_DEPENDENT
@AccessControl.authorizationCheck:#NOT_ALLOWED
define table function DEMO_CDS_GET_SCARR_SPFLI
  with parameters
    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=>GET_SCARR_SPFLI_FOR_CDS;
  • The CDS table function DEMO_CDS_GET_SCARR_SPFLI_INPCL has one input parameter CLNT of the type CLNT. The annotation @Environment.systemField is assigned to this parameter with the predefined value #CLIENT. The client ID of the current client is passed to this parameter implicitly in SELECT. The implementation in the AMDP method GET_SCARR_SPFLI_FOR_CDS of the associated AMDP class CL_DEMO_AMDP_FUNCTIONS_INPCL uses the input parameter to restrict the results set to the current client.
@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;

The result of the accesses performed without the addition CLIENT SPECIFIED is the same for both CDS table functions. If the obsolete addition CLIENT SPECIFIED is used to access the CDS table function without an input parameter for the client, the results set has an extra client column and the current client must be selected explicitly in the WHERE condition. The obsolete addition CLIENT SPECIFIED cannot be specified for the CDS table function with an input parameter for the client.