Ansicht
Dokumentation

ABAPSELECT_CLIENT - SELECT CLIENT

ABAPSELECT_CLIENT - SELECT CLIENT

ROGBILLS - Synchronize billing plans   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.
SAP E-Book

SELECT, USING CLIENT, CLIENTS

Short Reference



... ${ USING ${ CLIENT clnt $}
          $| ${ CLIENTS IN @client_range_tab $}
          $| ${ CLIENTS IN T000 $}
          $| ${ ALL CLIENTS $} $} ...


Variants:

1. ... USING CLIENT clnt

2. ... USING $[ALL$] CLIENTS $[IN$] ...

Effect

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 annotationAccessControl.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 , because client handling is done implicitly for and cannot be manipulated. For more details, see ABAP CDS - Client Handling in CDS View Entities.

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 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 strict mode from Release. This addition disables implicit client handling completely and is completely obsolete in queries.

Variant 1

... USING CLIENT clnt


Effect

The addition USING CLIENT modifies automatic client handling in 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, ) 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.

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 strict mode, which handles the statement more strictly than the regular syntax check.

Example

Reading of all customers in client "800" from a client-dependent DDIC database table.

Variant 2

... USING $[ALL$] CLIENTS $[IN$] ...


Alternatives:

1. ... USING CLIENTS IN @client_range_tab

2. ... USING CLIENTS IN T000

3. ... USING ALL CLIENTS

Effect

The additions USING $[ALL$] CLIENTS $[IN$] modify implicit 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 views that use the session variable client.

The additions USING $[ALL$] CLIENTS $[IN$] cannot be specified together with the following path expressions:

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 strict mode from Release .

Alternative 1

... USING CLIENTS IN @client_range_tab


Effect

This addition modifies implicit client handling in 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.

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.

Example

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.

Alternative 2

... USING CLIENTS IN T000


Effect

This addition modifies implicit client handling in 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.

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 .
  • 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.

Example

See below.

Alternative 3

... USING ALL CLIENTS


Effect

This addition modifies implicit client handling in 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.

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.

Example

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.






Addresses (Business Address Services)   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 21235 Date: 20240328 Time: 112813     sap01-206 ( 274 ms )