Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Reads →  WITH →  WITH Examples 

WITH, Client Handling

This example demonstrates client handling in the statement WITH.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA client TYPE scarr-mandt.
    cl_demo_input=>request( CHANGING field = client ).

    WITH
      +cte AS ( SELECT mandt, carrid, carrname
                       FROM scarr USING ALL CLIENTS )
      SELECT *
             FROM +cte
             WHERE mandt = @client
             INTO TABLE @DATA(result).

    cl_demo_output=>display( result ).

Description

In the subquery of the common table expression +cte, the addition USING ALL CLIENTS is used to access the client-specific database table SCARR. This means data is read from all clients. The client column is part of the SELECT list.

The main query of the WITH statement reads the common table expressions. A restriction to one specific client is specified. The client column can be specified after WHERE since the results set of +cte is not client-specific. The column MANDT is not used as a client column.