Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between

Former Member
0 Likes
1,095

hi! all,

can anybody say me the difference between INSERT, UPDATE & MODIFY while using in Database Table .

Thanks ,

Nagulan

8 REPLIES 8
Read only

Former Member
0 Likes
938

Hi,

INSERT:

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.

UPDATE:

Effect

Updates values in a database table (see Relational Databases ). You can specify the name of the database table either directly in the form dbtab or 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".

MODIFY :

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.

The return code is set as follows:

SY-SUBRC = 0:

All lines were successfully inserted or updated.

SY-SUBRC = 4:

One or more lines could not be inserted or updated.

Reward if useful.....

Read only

Former Member
0 Likes
938

Hi,

MODIFY Command will modify a record if a record with the same key feilds exists else it will insert a new record.

UPDATE : If will modify a record in the data base , so a basic prerequisit is that a similar record with the same key must exist in the database table.

INSERT : This will insert a new record in the database , if a record with the same key already exists then an error will occure.

So it is genreally safer to use the MODIFY command.

Regards,

Omkar.

Read only

graghavendra_sharma
Contributor
0 Likes
938

INSERT:

Inserts new line(s) in a database table.

You cannot insert a line if a line with the same primary key already exists or if a UNIQUE index already has a line with identical key field values (with regard to this UNIQUE index).

UPDATE:

Updates values in a database table.

MODIFY

Inserts new lines or updates existing lines in a database table

Read only

Former Member
0 Likes
938

hi nagulan,

Whenever you need to create new records in the database table use INSERT. Whenever using INSERT be sure that a duplicate entry having the same values for the primary key fields are not present. Else it may throw a dump.

When you use MODIFY it makes a check for the matching key field values. If present it modifies the matching record, else it creates a new record in the database table.

reward points if helpful..

Read only

Former Member
0 Likes
938

Hi,

Insert is useful to Insert a new record into table. UPDATE is used for to modify/update the existing record. MODIFY is used to insert a new record or update an existing record which means if we use modify statement in our program first it checks with the data base for, is there any key exist with the same key what we try to modify. If the same key is found then it works like UPDATE , else (no key found) it works like INSERT.

Rgds,

Bujji

Read only

Former Member
0 Likes
938

Hi,

MODIFY means that the system first tries to INSERT a row in a table. If

this is not possible due to duplicate errors, an UPDATE is executed.

Performance is worse that performing a direct INSERT or UPDATE.

Therefore you should only use MODIFY if you do not know if a row already

exists. An alternative would be to first perform a SELECT SINGLE.

reward if helpful,

kushagra

Read only

Former Member
0 Likes
938

insert ... will only insert a new record ...

update : will only update the existing record...

modify : update + insert

will change the existing record or will add a new record based on the condition .

Reward Points if it is useful.

Regards,

K.Tharani.

Read only

Former Member
0 Likes
938

hi,

MODIFY Command will modify a record if a record with the same key feilds exists else it will insert a new record.

UPDATE : If will modify a record in the data base , so a basic prerequisit is that a similar record with the same key must exist in the database table.

INSERT : This will insert a new record in the database , if a record with the same key already exists then an error will occure.

So it is genreally safer to use the MODIFY command