Ansicht
Dokumentation

ABAPUPDATE_SOURCE - UPDATE SOURCE

ABAPUPDATE_SOURCE - UPDATE SOURCE

ABAP Short Reference   Vendor Master (General Section)  
This documentation is copyright by SAP AG.
SAP E-Book

UPDATE dbtab, source

Short Reference



... ${ ${SET set_expression1, set_expression2, ... $[WHERE sql_cond$] $[db_hints$]$}
    $| ${FROM ${@wa$|@( expr )$}$|${TABLE @itab$|@( expr )$}$}
            $[INDICATORS $[NOT$] SET STRUCTURE set_ind$] $} ...


Alternatives:

1. ... SET set_expression1, set_expression2, ... $[WHERE sql_cond$] $[db_hints$]

2. ... FROM @wa$|@( expr ) $[INDICATORS $[NOT$] SET STRUCTURE set_ind$]

3. ... FROM TABLE @itab$|@( expr ) $[INDICATORS $[NOT$] SET STRUCTURE set_ind$]

Effect

The specifications in source define which rows and columns are changed. Either individual columns are changed using the addition SET, or entire rows are overwritten using the addition FROM.

After FROM a non-table-like data object, or after TABLE an internal table, can be specified as a host variable or host expression. The content of these objects determines which rows are changed and which values are used to overwrite the rows.

After FROM, set indicators can be used to define individual fields within a row to be changed (instead of overwriting the entire content of a row).

Note

Host variables without the escape character @ are obsolete. The escape character @ must be specified in the strict modes of the syntax check from Release .

Alternative 1

... SET set_expression1, set_expression2, ... $[WHERE sql_cond$] $[db_hints$]


Additions

1. ... WHERE sql_cond

2. ... db_hints

Effect

After the addition SET, the changes are specified in a list of change expressions: set_expression1, set_expression2, ....

The content of primary key fields can be modified only if the affected DDIC database table is not linked with a search help. If these changes would create a row which would produce duplicate entries in the primary key or a unique secondary index of the DDIC database table, no rows are changed and sy-subrc is set to 4.

If the value of a column with type LRAW or LCHR is modified, the associated INT2 or INT4 field must also be given a value.

Notes

  • When a comma-separated list is used, the syntax check is performed in a strict mode, which handles the statement more strictly than the regular syntax check.
  • Instead of using commas, blanks can be used to separate change expressions in an obsolete form. Commas must be specified, however, in the strict modes of the syntax check from Release .

UPDATE, Use of SET

Addition 1

... WHERE sql_cond

Effect

The addition WHERE determines in which rows of the DDIC database table the changes are made. Those rows are change for which the logical expression sql_cond is true. The relational expressions of the logical expression sql_cond are subject to the restriction that no subqueries can be evaluated on the modified DDIC database table. If no WHERE condition is specified, all the rows in the target of the statement are modified by default. In a client-dependent target, these are the rows of the current client. Implicit client handling can be defined using the addition USING. The client column of a client-dependent target cannot be specified in the WHERE condition.

Notes

  • If the data source is accessed using generic table buffering, the buffered area must be specified completely in the WHERE condition. If not, buffering is bypassed.
  • If the data sources are accessed using single record buffering, the conditions joined using AND in the WHERE condition must be specified for all key fields of the primary key. If not, buffering is bypassed.

Example

Sets multiple columns in a row determined using a WHERE condition.

Addition 2

... db_hints

Effect

In this variant, database hints can be specified using db_hints.

Alternative 2

... FROM @wa$|@( expr ) $[INDICATORS $[NOT$] SET STRUCTURE set_ind$]


Effect

If a non-table-like work area is specified as a host variable @wa or host expression @( expr ), a row is searched in the DDIC database table whose primary key content is the same as that of the corresponding initial part of the work area. The work area must meet the prerequisites for use in statements.

  • If a work area that does not contain any reference variables for LOB handles is specified, the content of the work area is used unconverted and according to the structure of the DDIC database table or the view. The content of the work area is assigned to the rows found. The assignment takes place without conversion, from left to right according to the structure of the DDIC database table or the view.
  • When a LOB handle structure is specified, it must be structured exactly like the structure of the DDIC database table in accordance with the prerequisites. Work area components that are not LOB handle components are assigned directly to the corresponding column of the row found. In the case of a LOB handle component of a reader stream type, the reader is created. If the type is for a locator, the locator must exist and is used as a source. For details, see LOB handles.
  • When set indicators are specified with the addition INDICATORS and the work area does not contain any reference variables for LOB handles, it must be compatible with the structure of the DDIC database table. In the case of a LOB handle structure, the LOB handle components can be mapped to the data types STRING or RAWSTRING and are handled as described above.

If there is no row with the same content for the primary key in the database or if the change would produce a duplicate entry in a unique secondary index, the row is not changed and sy-subrc is set to 4.

Views whose fields are all key fields should not be written to using UPDATE FROM. For DDIC database views, this produces a syntax check warning and for DDIC projection views a syntax error or runtime error.

Notes

  • The work area wa should always be declared with reference to the DDIC database table or the DDIC view in the ABAP Dictionary. For the derivation of LOB handle structures, there are special additions of the statements TYPES and $[CLASS-$]DATA.
  • Exceptions due to invalid values can also be raised in compatible work areas. For example, components of the types d and t can contain invalid dates and times that are not accepted by columns of the types DATN and TIMN.
  • If the DDIC database table or DDIC view is specified statically, a short form can be specified outside of classes. This means that the work area specified using FROM wa can be omitted. The prerequisite is that a table work area dbtab for the corresponding DDIC database table or the DDIC view is declared using the statement TABLES. The system then adds the addition FROM dbtab implicitly to the statement UPDATE.

Example

Changing of the discount rate of customer with customer number '00017777' (in the current client) to 3 per cent.

Example

The same example as before but with an inline declaration and a host expression.

Alternative 3

... FROM TABLE @itab$|@( expr ) $[INDICATORS $[NOT$] SET STRUCTURE set_ind$]


Effect

If an internal table is specified as a host variable @itab or host expression @( expr ), the system processes all the rows of the internal table in accordance with the rules for the work area wa, with the exception that when specifying an internal table, locators are used as a source but writer streams cannot be created.

The row type of the internal table must meet the prerequisites for use in statements.

If there is no row with the same content of the primary key for a row of the internal table in the database, or if the change would produce a duplicate entry in a unique secondary index, the corresponding row is not changed and sy-subrc is set to 4. Processing then continues with the next row.

If the internal table is empty, no rows are changed. However, sy-subrc is still set to 0. The system field sy-dbcnt is set to the number of rows that are actually inserted.

Notes

  • When an internal table is used, package by package processing performs a read in parallel to an UPDATE on the same rows that partially shows the new status and partially shows the old status.
  • The statement UPDATE FROM TABLE changes all rows for which this is possible. If sy-subrc contains the value 4 after the statement has been executed, this does not mean that no rows were changed. It simply means that not all of the rows in the internal table could be respected.

Example

Reduction of the flight price for all of today's flights of an airline carrier in the DDIC database table SFLIGHT by the percentage percent. The new price is calculated in an internal table sflight_tab that is declared inline and the DDIC database table is changed by using the internal table as a source.

Example

The same example as above, but the new price is calculated in a host expression for the internal table.






rdisp/max_wprun_time - Maximum work process run time   General Data in Customer Master  
This documentation is copyright by SAP AG.

Length: 15629 Date: 20240416 Time: 145058     sap01-206 ( 257 ms )