Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Write Accesses →  INSERT, UPDATE, MODIFY, DELETE - target →  INSERT, UPDATE, MODIFY, DELETE dbtab - CLIENT, CLIENTS 

UPDATE, USING CLIENT, CLIENTS

This example demonstrates client handling in the ABAP SQL statement UPDATE.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(rnd) = cl_abap_random_int=>create(
      seed = CONV i( sy-uzeit ) min = 1 max = 10 ).

    DELETE FROM demo_update USING ALL CLIENTS.

    INSERT demo_update CLIENT SPECIFIED FROM TABLE @( VALUE #(
        FOR j = 0 UNTIL j > 4
        FOR i = 1 UNTIL i > 4
          ( client = |{ CONV mandt( j * 100 ) ALPHA = IN }|
            id = substring( val = sy-abcde off = i - 1 len = 1 )
            col1 = rnd->get_next( )
            col2 = rnd->get_next( )
            col3 = rnd->get_next( )
            col4 = rnd->get_next( ) ) ) ).

    UPDATE demo_update USING CLIENT '100'
       SET col1 = col1 + 1000.

    TYPES clients TYPE RANGE OF mandt.
    UPDATE demo_update USING CLIENTS IN
                               @( VALUE clients( ( sign = 'I'
                                                  option = 'BT'
                                                  low = '200'
                                                  high = '300' ) ) )
       SET col2 = col2 + 1000.

    UPDATE demo_update USING CLIENTS IN T000
       SET col3 = col3 + 1000.

    UPDATE demo_update USING ALL CLIENTS
       SET col4 = col4 + 1000.

    SELECT client, id, col1, col2, col3, col4
           FROM demo_update USING ALL CLIENTS
           ORDER BY client, id
           INTO TABLE @DATA(result).
    cl_demo_output=>display( result ).

Description

The example demonstrates how the additions USING CLIENT and USING CLIENTS are used in the statement UPDATE and in other ABAP SQL statements.

  • First, the addition USING ALL CLIENTS of the statement DELETE is used to delete all data in all clients from the client-specific table DEMO_UPDATE.
  • The addition CLIENT SPECIFIED of the statement INSERT is used to write data with five different client IDs from a table constructed in a host expression into this database table.
  • The statement UPDATE with different variants of the USING addition is applied to the filled table:
  • USING CLIENT is used to modify the content of the column COL1 for the client 100.
  • USING CLIENTS IN @( ... ) modifies the content of the column COL2 for the clients 200 and 300 that meet the conditions of a ranges table constructed in a host expression.
  • USING CLIENTS IN T000 is used to modify the content of the column COL3 for all clients that also exist in the system table T000.
  • USING ALL CLIENTS is used to modify the content of the column COL4 for all clients.
In this example, the additions USING CLIENTS IN T000 and USING ALL CLIENTS can select different clients, since the validity of the client IDs is not checked when data is inserted. In real application tables, however, only client IDs from the table T000 should occur.
  • Finally, the addition USING ALL CLIENTS of the statement SELECT is used to read and display the data from all clients.