Application Development 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: 

Performance between MODIFY / UPDATE

Former Member
0 Kudos

Dear SDN's,

I would like to know differences in usage of below statements.

  1. MODIFY <dbtab> FROM <wa>.

  2. UPDATE <dbtab>

SET <col> = <value>

WHERE <keycol> = <Keycolumn Value>.

The <dbtab> has been constantly updating through background job and as well thru' front-end.

Regards,

Ramki.

1 ACCEPTED SOLUTION

gopi_narendra
Active Contributor
0 Kudos

The statement UPDATE changes the content of one or more lines of the database table specified in target.

The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.

So comparing thsi its always suggested to use <b>MODIFY</b>

Regards

- Gopi

4 REPLIES 4

gopi_narendra
Active Contributor
0 Kudos

The statement UPDATE changes the content of one or more lines of the database table specified in target.

The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.

So comparing thsi its always suggested to use <b>MODIFY</b>

Regards

- Gopi

anversha_s
Active Contributor
0 Kudos

hi,

<b> modify statemnt</b> will modify a record if there is record having the same key like that of record in work area.

<i>Same like above in the case of data base table</i>

if there is no record in itab with key of work area record, it will insert a new record in itab.

look this sample code.

loop at itab into wa.

wa-field1 = data1.

wa-field2 = data2.

wa-field 3= data3.

modify itab from wa transporting field1 field2 field3 where key_field = wa-keyfield. "there shuld not be any chang in key field.

endloop.

<b>update</b>

never use update statements in standard SAP tables.

try to use modfy maximaum

rgds

anver

if hlped pls mark points

Former Member
0 Kudos

Hi Ramakrishna,

If your requirement is to just change the existing value (modifying) then use UPDATE which would be faster than MODIFY , as MODIFY will do few checks before updating a values as it will check the database entry and if it exists it will update other wise it will create new entry .simply

MODIFY = INSERT + UPDATE.

<u><i>See this lines from ABAPHELP.</i></u>

<b>Automatic definition of INSERT and UPDATE is expensive. You should therefore use MODIFY only if you cannot define the INSERT and UPDATE cases yourself in the program.</b>

Regards,

Raghav

Former Member
0 Kudos

Read below info.

If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like IINSERT - that is, the line is added.

If the database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE - that is, the line is changed.

<b>For performance reasons, you should use MODIFY only if you really cannot distinguish between these two options in your program.</b>

The contents of the work area wa are written to the database table dbtab. The work area wa must be a data object with at least the same length and alignment as the line structure of the database table. The data is placed in the database table according to the line structure of the table, and regardless of the structure of the work area. It is a good idea to define the work area with reference to the structure of the database table.

MODIFY target FROM wa.

If the database table does not already contain a line with the same primary key as specified in the work area, a new line is inserted.

If the database table does already contain a line with the same primary key as specified in the work area, the existing line is overwritten.

If the line could not be processed – for example, because a line with the same unique secondary index exists in the database – sy-subrc is set to 4, otherwise to 0.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3ac8358411d1829f0000e829fbfe/content.htm

Update

Authorization checks are not supported by the UPDATE statement. You must include these in the program yourself.

Changes to lines made with the UPDATE command only become final after a database commit.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/update.htm

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers