Difference Between Modify and Update Statement

What is the difference between Modify and Update statement and when do we use which statement?

MODIFY - Will update the table, if the data already exists, if NOT inserts new rows.

UPDATE - Will update the table, errors out if the data is not found.

In case of MODIFY the sy-subrc is always 0 so you would't know whether the data is actually updated or not.

INSERT - Inserting Data in Database Tables 

Variants: 
1. INSERT INTO dbtab [CLIENT SPECIFIED] VALUES wa. 
INSERT INTO (dbtabname) [CLIENT SPECIFIED] VALUES wa. 

2. INSERT dbtab [CLIENT SPECIFIED] FROM TABLE itab.
or
INSERT (dbtabname) [CLIENT SPECIFIED] FROM TABLE itab.

3. INSERT dbtab [CLIENT SPECIFIED]. oder INSERT *dbtab [CLIENT SPECIFIED]. oder INSERT (dbtabname) [CLIENT SPECIFIED] ... . 

Effect Adds new records to a database table (see relational database). You can specify the name of the database table either directly in the program in the form dbtab or at runtime as the contents of the field dbtabname. In either case, the database table must be declared in the ABAP Dictionary. You can only insert data using a view if the view refers to a single table and has the maintenance status "No restriction" in the ABAP Dictionary. 

By default, data is only inserted in the current client. 

However, if you use the CLIENT SPECIFIED addition, you can switch off the automatic client handling. This enables you to enter data for any client in a cross-client table, not just in the client in which you are logged on. In this case, the client field is treated like a normal field to which you can assign a value in the work area. 

MODIFY - Change a database table 

Variants: 

1. MODIFY dbtab. or
MODIFY *dbtab. or
MODIFY (dbtabname) ... .. 

2. MODIFY dbtab FROM TABLE itab. or
MODIFY (dbtabname) FROM TABLE itab. 

3. MODIFY dbtab VERSION vers. or
MODIFY *dbtab VERSION vers. 

Effect Inserts new lines or updates existing lines in a database table (s. relational database). If a line with the specified primary key already exists, an UPDATE is executed.
Otherwise, an INSERT is performed. You can specify the name of the database table either in the program itself in the form MODIFY dbtab ... or at runtime as the contents of the field dbtabname in the form MODIFY (dbtabname) ... . In both cases, the database table must be defined in the ABAP Dictionary.

Normally, records are inserted or updated only in the current client. Data can only be inserted or 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". 

MODIFY belongs to the Open SQL command set. 

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

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.