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: 

REGARDING "modify and update"

Former Member
0 Kudos

Dear experts,

can u please tell me whats the basic difference between Update statements.

Regards

Prakash

6 REPLIES 6

Former Member
0 Kudos

Refer

Former Member
0 Kudos

hi,

modify: Modify existing record or if no record is there inserts a fresh record.

Update: updates the existing record.

To insert or change a single line in a database table, use the following:

MODIFY <target> FROM <wa> .

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.

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. SY-SUBRC is always set to 0.

A shortened form of the above statement is:

MODIFY <dbtab>.

In this case, the contents of the table work area <dbtab> are inserted into the database table with the same name. You must declare this table work area using the TABLES statement. In this case, it is not possible to specify the name of the database table dynamically. Table work areas with the same name as the database table (necessary before Release 4.0) should no longer be used for the sake of clarity.

Inserting or Changing Lines

To insert lines into a database table regardless of whether there is already a line in the table with the same primary key, use the following:

MODIFY <target> <lines>.

If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like INSERT, 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.

For performance reasons, you should use MODIFY only if you cannot distinguish between these two options in your ABAP program.

You can add or change one or more lines <lines> in a database table <target>. You can only insert or change lines in an ABAP Dictionary view if it only contains fields from one table, and its maintenance status is defined as Read and change. You may specify the database table <target> either statically or dynamically.

Specifying a Database Table

To specify the database table statically, enter the following for <target>:

MODIFY <dbtab> [CLIENT SPECIFIED] <lines>.

where <dbtab> is the name of a database table defined in the ABAP Dictionary.

To specify the database table dynamically, enter the following for <target>:

MODIFY (<name>) [CLIENT SPECIFIED] <lines>.

where the field <name> contains the name of a database table defined in the ABAP Dictionary.

You can use the CLIENT SPECIFIED addition to disable automatic client handling.

Inserting or Changing Single Lines

To insert or change a single line in a database table, use the following:

MODIFY <target> FROM <wa> .

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.

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. SY-SUBRC is always set to 0.

A shortened form of the above statement is:

MODIFY <dbtab>.

In this case, the contents of the table work area <dbtab> are inserted into the database table with the same name. You must declare this table work area using the TABLES statement. In this case, it is not possible to specify the name of the database table dynamically. Table work areas with the same name as the database table (necessary before Release 4.0) should no longer be used for the sake of clarity.

Inserting or Changing Several Lines

To insert or change several lines in a database table, use the following:

MODIFY <target> FROM TABLE <itab> .

Those lines of the internal table <itab> for which there is not already a line in the database table with the same primary key are inserted into the table. Those lines of the internal table <itab> for which there is already a line in the database table with the same primary key overwrite the existing line in the database table. The same rules apply to the line type of <itab> as to the work area <wa> described above.

SY-SUBRC is always set to 0. SY-DBCNT is set to the number of lines in the internal table.

Modify : This statement creates a new record if the mentionedrecord does not exist in the database table ( works same as INSERT ), and it it modifies the record (By comparing the key fields of the work area )if the record exists in the database table.

Works for INTERNAL TABLES also....

Update: It updates the record in the database table

by comparing the key fields with the required information. ( it will not work for Internal tables )

Former Member
0 Kudos

<b>UPDATE target source. </b>

Effect:

The statement UPDATE changes the content of one or more lines of the database table specified in target. The entries in source determine which columns of which lines are changed, and how they are changed.

System fields

The statement UPDATE sets the values of the system fields sy-subrc and sy-dbcnt.

sy-subrc Meaning

0 At least one line has been changed.

4 At least one line was not able to be changed, either because no appropriate line was found, or because the change would generate a line that leads to double entries in the primary key or a unique secondary index in the database table.

The statement UPDATE sets sy-dbcnt to the number of changed lines.

<b>MODIFY dbtab </b>

Syntax

MODIFY target FROM source.

Effect

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

System fields

The MODIFY statement sets the values of the sy-subrc and sy-dbcnt system fields.

sy-subrc Meaning

0 At least one line is inserted or changed.

4 At least one line could not be processed since there is already a line with the same unique name secondary index in the database table.

The MODIFY statement sets sy-dbcnt to the number of processed lines.

Regards,

Pavan.

Former Member
0 Kudos

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

go through this link...

<b>Reward points</b>

Regards

Former Member
0 Kudos

hi,

update is native sql statement which can be used for databses directly and on internal tables in sap.

update generally used for modifications. for ex when u want to change the existing record in a table we go for update. if that record isn't found then it changes nothing.

modify is used for internal tables only.

modify [ insert + update] -> means if existing record for change in not found then it creates a new reord with given data or if existing data is found then it changes with new contents.

if helpful reward some points.

With Regards,

Suresh.A

Former Member
0 Kudos

Hi prakash,

MODIFY for Database Tables

Inserts or changes lines in database tables.

Syntax

MODIFY <dbtab> FROM <wa>.

MODIFY <dbtab> FROM TABLE <itab>.

Works like INSERT for database tables if there is not yet a line in the table with the same primary key. Works like UPDATE if a line already exists with the same primary key.

MODIFY for All Internal Tables

Changes the contents of lines in any type of internal table.

Syntax

MODIFY TABLE <itab> FROM <wa> [TRANSPORTING <f1> <f 2>...].

Copies the work area <wa> into the line of the internal table with the same table key as <wa>. You can use the TRANSPORTING addition to specify the exact components that you want to change.

MODIFY <itab> FROM <wa> TRANSPORTING <f1> <f 2>... WHERE <logexp>.

Copies the work area <wa> into the lines of the internal table for which the logical expression is true. The first operand in each comparison of the logical expression must be a component of the line structure.

MODIFY for Index Tables

Changes the contents of lines in index tables.

Syntax

MODIFY <itab> FROM <wa> [INDEX <idx>] [TRANSPORTING <f1> <f 2>...].

Copies the work area <wa> into the line of the internal table with index <idx>. If you omit the INDEX addition, you can only use the statement within a LOOP. This changes the current line.

MODIFY for Lists

Changes a line of a list.

Syntax

MODIFY LINE <n> [INDEX <idx>] [OF CURRENT PAGE|OF PAGE <p>]

|CURRENT LINE

LINE FORMAT <option1> <option2>...

FIELD VALUE <f1> [FROM <g1>] <f2> [FROM <g2>]...

FIELD FORMAT <f1> <options1> <f2> <options2>

Changes either line <n> on the current or specified list (or page), or the last line to be chosen. The exact nature of the change is specified in the additions.

MODIFY SCREEN

Changes the table SCREEN.

Syntax

MODIFY SCREEN...

Like changing an internal table. This statement allows you to change the attributes of fields on the current screen.

UPDATE

Modifies lines in database tables.

Syntax

UPDATE <dbtab> SET <si> = <f>

|<si> = <s i> + <f>

|<si> = <s i> - <f> [WHERE <cond>].

Sets the value in <si> to <f>, increases it by <f>, or decreases it by <f> for all selected lines. The WHERE addition determines the lines that are updated. If you omit the WHERE addition, all lines are updated.

Syntax

UPDATE <dbtab> FROM <wa>.

UPDATE <dbtab> FROM TABLE <itab>.

Overwrites the line with the same primary key as <wa> with the contents of <wa>, or all lines with the same primary key as a line in the internal table <itab> with the corresponding line of itab. The work area <wa> or the lines of the table <itab> must have at least the same length and the same alignment as the line structure of the database table.

Use this link.....

http://publib.boulder.ibm.com/infocenter/wbihelp/v6rxmx/index.jsp?topic=/com.ibm.wbia_adapters.doc/d...

If useful reward points.

Thanks

Sanket.