UPDATE

Variants:




1. UPDATE  dbtab      SET f1 ... fn. or
   
UPDATE (dbtabname) SET f1 ... fn.


2. UPDATE  dbtab      FROM wa. or
   
UPDATE (dbtabname) FROM wa.


3. UPDATE  dbtab      FROM TABLE itab. or
   
UPDATE (dbtabname) FROM TABLE itab.


4. UPDATE  dbtab. or
   
UPDATE *dbtab.


Effect

Updates values in a database table (see Relational Databases ). You can specify the name of the database table either directly in the form dbtabor at runtime as contents of the field dbtabname. In both cases, the table must be known to the ABAP Dictionary. Normally, lines are updated only in the current client. Data can only be updated using a view if the view refers to a single table and was created in the ABAP Dictionary with the maintenance status "No restriction".

UPDATE belongs to the Open SQL command set.

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs.See Open SQL and Unicode.

Notes

  1. Authorization checks (see The SAP Authorization Concept) are not supported by the UPDATE statement. You must include these in the program yourself.


  2. Changes to lines made with the UPDATE command only become final after a database commit (see Logical Unit of Work (LUW)). Prior to this, any database update can be canceled by a database rollback (see Programming Transactions).


  3. In the dialog system, you cannot rely on the locking mechanism used by the database system (see Database Locking) to synchronize simultaneous access to the same database by several users. Therefore, it is often necessary to use SAP's locking mechanism (see SAP Locking).


  4. You cannot change the primary key when you UPDATE a table for which a synchronous matchcode is defined.


Variant 1

UPDATE  dbtab      SET f1 ... fn. or
UPDATE (dbtabname) SET f1 ... fn.

Extras:

1. ... WHERE condition

2. ... CLIENT SPECIFIED

3. ... CONNECTION con

Effect

Updates values in a database table. If there is no WHERE clause, all lines (in the current client) are updated. If a WHERE condition is specified, only thoserecords which satisfy the WHERE condition are updated.

The SET clause f1 ... fn identifies the columns to be updated and assigns values to them. Four types of SET statements fi are supported:

f = g
In all selected lines, the database table column specified by f receives the value of g. g can be an ABAP field, a literal, or a field descriptor. In the latter case, the contents of the column to which g points are copied into the line of the table that you are updating.
f = f + g
In all selected lines, the contents of g are added to the value in the database table column determined by f. g can be an ABAP field, a literal, or a field descriptor. The NULL value remains unchanged. This statement can only be applied to a numeric field.
f = f - g
In all selected lines, the content of g is subtracted from the value in the database table column determined by f. g can be an ABAP field, a literal, or a field descriptor. The NULL value remains unchanged. This statement can only be applied to a numeric field.
(source_text)
For all selected lines, the program executes the SET statements that are specified dynamically in the source_text variable as ABAP-Quelltext source text. You can specify any SET statement that you could specify statically.

Example

Changing the discount to 3 percent for all customers in the current client:

UPDATE scustom SET discount = '003'.

Example

The same example using a dynamic SET condition:

DATA: tabname     TYPE STRING,
      set_clause  TYPE STRING.

tabname    = 'SCUSTOM'.
set_clause = 'DISCOUNT = ''003'' '.

UPDATE (tabname) SET (set_clause).

When the command has been executed, the system field SY-DBCNT contains the number of updated lines.

System values

SY-SUBRC = 0:
At least one line was updated,
SY-SUBRC = 4:
No line was updated because either no line could be selected or the change would have generated lines with primary keys that already existed.

Note

  1. With pooled and cluster tables, an UPDATE cannot change any primary key field.
    dbtab FROM TABLE itab. or
    UPDATE (dbtabname) FROM TABLE itab.

    Extras:

    1. ... CLIENT SPECIFIED

    2. ... CONNECTION con

    Effect

    Mass update of several lines in a database table. Here, the primary key for identifying the lines to be updated and the values to be changed are taken from the lines of the internal table itab. The lines of the internal table must satisfy the same conditions as the work area wa in addition 1 to variant 2.

    The system field SY-DBCNT contains the number of updated lines, i.e. the number of lines in the internal table itab which have key values corresponding to lines in the database table.

    The Return Code is set as follows:

    SY-SUBRC = 0:
    All lines from itab could be used to update the database table.
    SY-SUBRC = 4:
    At least one line of the internal table itab in the database table had no line with the same primary key. The other lines of the database table were updated.

    Note

    If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.

    Addition 1

    ... CLIENT SPECIFIED

    Effect

    As with the variant UPDATE dbtab SET ....

    Addition 2

    ... CONNECTION con

    Effect

    As with the variant UPDATE dbtab SET ....


    Variant 4

    UPDATE  dbtab.
    UPDATE *dbtab.


    Extras:

    1. ... CLIENT SPECIFIED

    2. ... CONNECTION con

    The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.See Cannot Use Short Forms and Cannot Use an Asterisk To Indicate a Work Area.

    Note

    This variant is obsolete.

    Effect

    These are the SAP-specific forms of variant 2. They have the same effect as variant 2, except that you do not declare the work area explicitly. Instead, the program uses the table work area dbtab or *dbtab, declared in a TABLES statement.

    is thus equivalent to:

    After the statement has been executed, the system field SY-DBCNT contains the number of updated lines (0 or 1).

    Example

    Changing the discount for the customer whose customer number is '00017777' to 3 percent (in the current client):



    TABLES SCUSTOM.

    SCUSTOM-ID       = '00017777'.
    SCUSTOM-DISCOUNT = '003'.
    UPDATE SCUSTOM.

    Note

    If a work area is not declared explicitly, the values for the line to be updated are also taken from the table work area, dbtab, if the statement is included in a FORM or FUNCTION , in which the table work area is obscured by a formal parameter or a local variable with the same name.

    The Return Code is set as follows:

    SY-SUBRC = 0:
    The specified line was updated.
    SY-SUBRC = 4:
    The system could not update any line, since there is no line in the table with the specified primary key.

    Addition 1

    ... CLIENT SPECIFIED

    Effect

    As with the variant UPDATE dbtab SET ....

    Addition 2

    ... CONNECTION con

    Effect

    As with the variant UPDATE dbtab SET ....


    Exceptions


    Runtime Error: SAPSQL_SET_MISSING_VALUE


    Runtime Error: SAPSQL_SET_NOT_PLUS_MINUS

    Additional help