Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Write Accesses →  UPDATE dbtab →  UPDATE dbtab - source →  UPDATE dbtab - set_expression 

UPDATE, Use of SET

The example demonstrates how the addition SET of the statement UPDATE is used.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    CONSTANTS id TYPE demo_update-id VALUE 'X'.

    DELETE FROM demo_update WHERE id = @id.
    INSERT demo_update FROM @( VALUE demo_update( id = id
                                  col1 = 100
                                  col2 = 100
                                  col3 = 100
                                 col4 = 100 ) ).

    DATA(num)   = 200.
    DATA(diff)  = 10.
    DATA(token) = `col4 = col4 - demo_update~col1`.
    UPDATE demo_update
           SET col1 = @num,
               col2 = col2 + @diff,
               col3 = col3 - @diff,
              (token)
           WHERE ID = @id.

    SELECT SINGLE *
           FROM demo_update
           INTO @DATA(wa).
    cl_demo_output=>display( wa ).

Description

It modifies the content of four columns of a row of the database table DEMO_UPDATE:

  • The column COL1 is assigned the value 200.
  • The value of the column COL2 is raised by 10.
  • The value of the column COL3 is reduced by 10.
  • The value of the column COL4 is reduced dynamically by the value of the column COL1 before the statement is executed.