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

Other versions: 7.31 | 7.40 | 7.54

Syntax


... dbtab |view|(target_syntax)  [client_handling] ... 

Alternatives

1. ... dbtab|view

2. ... (target_syntax)

Effect

In the modifying ABAP SQL statements INSERT, UPDATE, MODIFY, and DELETE, these elements specify which database table or view is accessed statically or dynamically. Optional additions client_handling define client handling. Only views whose key fields are located together at the beginning of the view can be accessed.


Note

Write access to tables or classic views with replacement objects is still performed on the database table or the classic view and lead to a syntax warning.

Alternative 1

... dbtab|view

Effect

dbtab can be a database table defined in ABAP Dictionary and view can be a classic view .

Only views that refer to a single database table, and whose status in ABAP Dictionary permits changes can be specified. No external views or CDS entities can be specified.


Note

The database table or view must be specified using the exact name defined for it in ABAP Dictionary. More specifically, it cannot be prefixed with the name for the database schema. An ABAP SQL statement always accesses the database schema assigned to the current database user name. In cases where the standard connection or a service connection is used, this is the ABAP database schema. In cases where a secondary connection is used, this is the database schema assigned to the database user defined in the secondary connection. Here, each access assumes that the database table or view exists under this exact name in the current AS ABAP ABAP Dictionary, regardless of the connection.


Example

Specifies (statically) a database table in different modifying ABAP SQL statements.

DELETE FROM demo_expressions. 

INSERT demo_expressions FROM TABLE @( VALUE #( 
  ( id = 'X' num1 = 1 num2 = 10 ) 
  ( id = 'Y' num1 = 2 num2 = 20 ) 
  ( id = 'Z' num1 = 3 num2 = 30 ) ) ). 

UPDATE demo_expressions 
  SET num2 = num2 + demo_expressions~num1 
  WHERE id = 'X'. 

MODIFY demo_expressions FROM @( VALUE #( 
  id = 'Y' num1 = 20 num2 = 200 ) ). 

DELETE FROM demo_expressions WHERE id = 'Z'. 

SELECT id, num1, num2 
       FROM demo_expressions 
       INTO TABLE @DATA(itab). 
cl_demo_output=>display( itab ). 

Alternative 2

... (target_syntax)

Effect

Instead of specifying an object statically, a parenthesized data object target_syntax can be specified that must contain the name of the database table or the view when the statement is executed. A character-like data object or a standard table with a character-like row type can be specified for the data object target_syntax. The syntax in target_syntax is not case-sensitive. Invalid syntax raises a handleable exception from the class CX_SY_DYNAMIC_OSQL_ERROR.

Security Note

If used wrongly, dynamic programming techniques can present a serious security risk. Any dynamic content that is passed to a program from the outside must be checked thoroughly or escaped before being used in dynamic statements. This can be done using the system class CL_ABAP_DYN_PRG or the predefined function escape. See SQL Injections Using Dynamic Tokens.


Note

When specified dynamically, ABAP SQL statements can contain the comment characters * and " as follows:

  • In a dynamic token specified as a character-like data object, all content is ignored from the first comment character ".
  • In a dynamic token specified as an internal table, all rows are ignored that start with the comment character *. In the row, all content is ignored from the first comment character ".


Example

Specifies (dynamically) a database table in a DELETE statement to delete all rows of the current client. A check is made to verify whether the object entered is in a particular package and any exceptions are handled.

DATA(dbtab) = `demo_update`. 
cl_demo_input=>request( CHANGING field = dbtab ). 
TRY. 
    dbtab = 
      cl_abap_dyn_prg=>check_table_name_str( 
        val = to_upper( dbtab ) 
        packages = 'SABAPDEMOS' ). 
  CATCH cx_abap_not_a_table cx_abap_not_in_package. 
    cl_demo_output=>display( 'Object must be in package SABAPDEMOS' ). 
    LEAVE PROGRAM. 
ENDTRY. 

TRY. 
    DELETE FROM (dbtab). 
    cl_demo_output=>display( |Deleted { sy-dbcnt } lines| ). 
  CATCH cx_sy_dynamic_osql_semantics. 
    cl_demo_output=>display( 'Deletion failed' ). 
ENDTRY.

Continue

INSERT, UPDATE, MODIFY, DELETE dbtab - CLIENT, CLIENTS