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
Cross-Client CDS Table Functions
This example demonstrates cross-client 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_nocl( clnt = @sy-mandt,
carrid = @carrid )
INTO TABLE @DATA(result1)
##db_feature_mode[amdp_table_function].
cl_demo_output=>write( result1 ).
SELECT *
FROM demo_cds_get_scarr_spfli_clnt( clnt = @sy-mandt,
carrid = @carrid )
INTO TABLE @DATA(result2)
##db_feature_mode[amdp_table_function].
cl_demo_output=>display( result2 ).
Description
This example program accesses two cross-client CDS table functions.
- The CDS table function DEMO_CDS_GET_SCARR_SPFLI_NOCL does not have any elements of the type CLNT.
define table function DEMO_CDS_GET_SCARR_SPFLI_NOCL
with parameters
clnt :abap.clnt,
carrid :s_carr_id
returns
{
carrname :s_carrname;
connid :s_conn_id;
cityfrom :s_from_cit;
cityto :s_to_city;
}
implemented by method
CL_DEMO_AMDP_FUNCTIONS_NOCL=>GET_SCARR_SPFLI_FOR_CDS;
- The CDS table function DEMO_CDS_GET_SCARR_SPFLI_CLNT has one element client of the type CLNT.
define table function DEMO_CDS_GET_SCARR_SPFLI_CLNT
with parameters
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_CLNT=>GET_SCARR_SPFLI_FOR_CDS;
Both CDS table functions have an input parameter clnt of the type CLNT
without the annotation @Environment.systemField.
The client ID of the current client is passed explicitly to this parameter by the statement
SELECT
. The implementations in the AMDP method GET_SCARR_SPFLI_FOR_CDS
of the associated AMDP classes CL_DEMO_AMDP_FUNCTIONS_NOCL or CL_DEMO_AMDP_FUNCTIONS_CLNT
use this input parameter in their WHERE conditions to read the data of
the current client only. Both results sets have the same number of rows and are distinguished only by the extra client column of the function DEMO_CDS_GET_SCARR_SPFLI_CLNT.
Note
In both table functions, the input field for the client ID could also be annotated with the predefined
value #CLIENT
using the annotation @Environment.systemField
to stop the client ID from being passed explicitly by SELECT
s.