SAP SELECT CLIENT ABAP Statements Get Example source ABAP code based on a different SAP table
ABAP Statement
VERSION 5 OUT
ID SELECT-USING-CLIENT
• CLIENT SELECT
• CLIENTS SELECT
• USING CLIENT SELECT FROM
• USING CLIENTS IN SELECT FROM
• USING ALL CLIENTS SELECT FROM
• T000 SELECT FROM
SELECT>, USING CLIENT>, CLIENTS> Short Reference > ABAP_SYNTAX ... ${ USING ${ CLIENT clnt $} $| ${ CLIENTS IN @client_range_tab $} $| ${ CLIENTS IN T000 $} $| ${ ALL CLIENTS $} $} ...> ABAP_VARIANTS: 1 ... USING CLIENT clnt> 2 ... USING $[ALL$] CLIENTS $[IN$] ...> What does it do? The optional addition USING> in the FROM >> clause of a query> switches implicit client handling> from the current client to other clients. The variant USING CLIENT> replaces the current client with the specified client in client handling. The variant USING $[ALL$] CLIENTS $[IN$]> selects the data of any number of other clients instead of the current client. When a single data source is specified, the addition USING> must be inserted directly after data_source>> in the join condition. When a join expression is specified, the addition must be inserted after the last addition ON > of the join condition. Client handling can be switched exactly once for each query> and is applied to all client-dependent data sources specified there. These include: Join expressions, the addition USING> cannot be used for individual data sources. Conditions sql_cond>, the addition USING> cannot be specified in subqueries> here. Client handling can, however, be switched in subqueries defined using WITH>> and in queries joined using UNION>>, INTERSECT>>, or EXCEPT>>. If the data source is specified statically, the addition can be specified only if at least one client-dependent data source is used. Otherwise a syntax error occurs. The addition USING> cannot be used to access a CDS entity> that is linked with a CDS role> and for which CDS access control> is performed: If the addition USING> is used in a statically known way to access a CDS entity defined without the annotation AccessControl.authorizationCheck:#NOT_ALLOWED> and the addition WITH PRIVILEGED ACCESS>> is not used in the FROM>> clause, a syntax check error occurs. If the addition USING CLIENT> is used to access a CDS entity linked with a CDS role> and for which CDS access control is performed, an exception is raised. The addition USING> is not allowed when accessing ABAP_CDS_V2_VIEWS >, because client handling is done implicitly for ABAP_CDS_V2_VIEWS > and cannot be manipulated. For more details, see ABAP CDS - Client Handling in CDS View Entities>. Latest notes: If the data source is specified dynamically after FROM>>, the addition USING> in SELECT> can always be specified. No exception is raised if no client-dependent tables or views are used, and the addition is ignored instead. The addition USING> can also be used for writes>. Each client represents a self-contained unit, which means that implicit client handling should never be disabled in application programs. If data has to be accessed in a different client, USING> should be used instead of the obsolete addition CLIENT SPECIFIED>, since all necessary conditions are set implicitly and accessing client-dependent CDS entities is also easier. CDS access control> does not work for client-independent access. For this reason, the addition USING > can only be used when accessing CDS entities for which access control is disabled using the annotation AccessControl.authorizationCheck:#NOT_ALLOWED> or using the addition WITH PRIVILEGED ACCESS>> in the FROM>> clause. The addition WITH PRIVILEGED ACCESS> > only works on the CDS entity specified in the FROM>> clause. If a path expression> is used to access a CDS entity in the current query and if a CDS access control is enabled for this entity, the addition USING> cannot be used. As an alternative to USING>, the addition CLIENT SPECIFIED>> can be specified outside ABAP_STRICT_777 strict mode from ABAP_RELEASE ABAP_777 / . This addition disables implicit client handling completely and is completely obsolete in queries. See also the associated security note> and the programming guideline> . NON_V5_HINTS The addition USING> is not allowed in the obsolete short form> of SELECT>. ABAP_HINT_END ABAP_VARIANT_1 ... USING CLIENT clnt> What does it do? The addition USING CLIENT> modifies automatic client handling> in AB_SQL for the current query> so that the client ID from clnt> is used instead of the current client ID. The client specified in clnt> is used in all places where, in SELECT> statements, the current client is implicitly used in implicit client handling. An implicit condition is created for this client and, in joins, the client columns of the client-dependent data sources involved are compared for equality. If it is known statically that the data sources data_source>> are not client-dependent, the addition USING CLIENT> cannot be specified. clnt> expects a data object of the type c> with length 3 and containing a client ID. A literal or a host variable> can be specified. If specified, the system field sy-mandt> would be ignored and cannot be specified directly for clnt>. When accessing CDS entities>, the session variable (CDS view entity>, ABAP_CDS_V1_VIEW >) client> is set to the client ID specified in clnt> while the current SELECT> statement is executed. The following restrictions apply: When CDS views> are accessed, the session variable client> is set to a value other than the current client only if it is needed to evaluate the view on the database. When CDS table functions> are accessed, the session variable is always set to the value specified by USING >. If multiple queries> that access client-dependent> CDS views are accessed, and the type of client handling is defined by the annotation @ClientHandling.algorithm:#SESSION_VARIABLE>> in these views, the session variable client> must be the set to the same value in each of these queries. The runtime error SAPSQL_DIFFERENT_CLIENT_VALUES> occurs if USING CLIENT> is used to specify a different client ID in one of these queries. This situation can occur in the statement WITH>> or when using UNION>>, INTERSECT >>, or EXCEPT>>. On SAP HANA databases>, USING CLIENT > sets the ABAP-specific session variable> CDS_CLIENT> accordingly. Latest notes: If the addition USING CLIENT> is used, the statement SELECT> functions as if the current user were logged on with the client ID specified in clnt>. If clnt> contains a client ID for a nonexistent client, the statement SELECT> is executed with this ID and the result set is empty. If the addition USING CLIENT> is used, the syntax check is performed in a ABAP_STRICT_740_SP05 strict mode / , which handles the statement more strictly than the regular syntax check. NON_V5_HINTS ABAP_HINT_END Example ABAP Coding Reading of all customers in client 800> from a client-dependent DDIC database table. ABEXA 00592 ABAP_EXAMPLE_END ABAP_VARIANT_2 ... USING $[ALL$] CLIENTS $[IN$] ...> ABAP_ALTERNATIVES: 1 ... USING CLIENTS IN @client_range_tab> 2 ... USING CLIENTS IN T000> 3 ... USING ALL CLIENTS> What does it do? The additions USING $[ALL$] CLIENTS $[IN$]> modify implicit AB_SQL client handling so that the data of all clients specified by the addition is read and not just the data from the current client. The additions modify the implicit WHERE> condition for the client column passed to the database when it is accessed. They do not modify the equality condition for the client columns of client-dependent data sources in joins. When CDS entities> are accessed, the additions USING $[ALL$] CLIENTS $[IN$]> do not set the session variable client>. They cannot be used when accessing the following CDS entities>: CDS entities in which an input parameter> is annotated with the annotation @Environment.systemField:#CLIENT>>. ABAP_CDS_V1_VIEWS > in which the view annotation @ClientHandling.algorithm:#SESSION_VARIABLE>> is specified and the session variable> $session.client>> is evaluated implicitly. CDS views that use the session variable client>. The additions USING $[ALL$] CLIENTS $[IN$]> cannot be specified together with the following path expressions>: Path expressions in any positions in which CDS associations> and CTE associations> occur whose association target> is client-dependent. Path expressions in the FROM>> clause in which CDS associations> and CTE associations> occur whose association source> is client-dependent. Latest notes: The additions USING $[ALL$] CLIENTS $[IN$]> replaced the obsolete addition CLIENT SPECIFIED>> in all cases where it disabled implicit client handling to make it possible to access more than one client. Unlike CLIENT SPECIFIED>, USING $[ALL$] CLIENTS $[IN$]> preserves client handling in joins. If the addition USING CLIENTS> is used, the syntax check is performed in ABAP_STRICT_777 strict mode from ABAP_RELEASE ABAP_777 / . NON_V5_HINTS ABAP_HINT_END ABAP Alternative 1 ... USING CLIENTS IN @client_range_tab> What does it do? This addition modifies implicit client handling in AB_SQL for the current query so that, instead of the current client, the data of all clients is selected whose client IDs meet the conditions in a ranges tables> client_range_tab>. If the ranges table is empty, the data of all clients is selected. For client_range_tab>, an internal table can be specified as a host variable> or a host expression> whose row structure matches the structure of a ranges table. The columns low> and high> must have the type c> with length 3. Latest notes: The conditions of the ranges table are transformed to implicit WHERE > conditions and passed to the database system. In the case of joins, the client columns of the client-dependent data sources involved are still checked for equality implicitly. ABAP_HINT_END Example ABAP Coding Selection of the data of all clients whose client IDs meet the conditions of ranges table constructed in a host expression with the value operator> VALUE>>. ABEXA 00593 ABAP_EXAMPLE_END ABAP Alternative 2 ... USING CLIENTS IN T000> What does it do? This addition modifies implicit client handling in AB_SQL for the current query so that, instead of the current client, the data of all clients is selected implicitly, whose client IDs are in the column MANDT> of the system table T000> >. Latest notes: The DDIC database table T000> contains the potential client IDs> in AS ABAP>. Client columns of application tables should contain only those client IDs specified in T000>. This is not, however, checked by AB_SQL . Implicit checks on the content of the DDIC database table T000> are implemented internally by passing a WHERE> condition with a corresponding subquery to the database system. In the case of joins, the client columns of the client-dependent data sources involved are still checked for equality implicitly. NON_V5_HINTS ABAP_HINT_END Example ABAP Coding See below. ABAP_EXAMPLE_END ABAP Alternative 3 ... USING ALL CLIENTS> What does it do? This addition modifies implicit client handling in AB_SQL for the current query so that, instead of the data of the current client, all data is selected regardless of the content of the client column. Latest notes: The addition USING ALL CLIENTS> does not pass an implicit WHERE> for the client column to the database system. In the case of joins, the client columns of the client-dependent data sources involved are still checked for equality implicitly. The addition USING ALL CLIENTS> replaces the addition CLIENT SPECIFIED>> without specifying a WHERE> condition for the client column. NON_V5_HINTS ABAP_HINT_END Example ABAP Coding For the table SFLIGHT>, this example checks whether a selection of all data without a condition for the client column has the same result as a selection of the client from the system table T000>. ABEXA 00594 ABAP_EXAMPLE_END Return to menu