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: 

Hi

Former Member
0 Kudos
173

HI

WHAT IS THE DIFFERENCE BETWEEN MODIFY AND UPDATE

1 ACCEPTED SOLUTION

Former Member
0 Kudos
138

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.

Update Modify Insert stmts we use when we want to do some change / Insertion

(1) to database table from internal table or

(2) from work area to internal table.

( AA ) Update

If the intended record in the internal table is found in databse table means it will just update that record.

syntax to update database table from itab:::::

UPDATE dbtab FROM TABLE itab

Changes to lines made with the UPDATE command only becomefinal after a database commit

Without using internal table we can update database table directly as shown below:::::::::::::::::::::

TABLES SFLIGHT.

UPDATE SFLIGHT SET SEATSOCC = SEATSOCC + 3

WHERE CARRID = 'LH' AND

CONNID = '0400' AND

FLDATE = '19950228'.

( BB ) Modify is used to insert new record if the record doesnt exist in datbase table.system check this on primary key basis.

If the intended record in the internal table is found in databse table means it will just update that record.So here its equal to UPDATE stmt.

For changes to database table we use syntax as below ::::

MODIFY DatabaseTable FROM TABLE itab.

For changes to Internal table we use syntax as below ::::

MODIFY itab FROM wa INDEX idx.

http://TRANSPORTING f1 ... fn WHERE cond.

( CC ) Insert stmt is used to insert New records into databse table from internal table or to internal table from work area.

By default, data is only inserted in the current client. However, ifyou use the CLIENT SPECIFIED addition, you can switch off theautomatic client handling.

You cannot insert a table line if the table alreadycontains a record with the same primary key.

Syntax::::::::::

INSERT INTO dbtab CLIENT SPECIFIED VALUES wa.

or

INSERT (dbtabname) CLIENT SPECIFIED FROM TABLE itab.

Example

Adding customer "Robinson" to client 002:

TABLES SCUSTOM.

SCUSTOM-MANDT = '002'.

SCUSTOM-ID = '12400177'.

SCUSTOM-NAME = 'Robinson'.

SCUSTOM-POSTCODE = '69542'.

SCUSTOM-CITY = 'Heidelberg'.

SCUSTOM-CUSTTYPE = 'P'.

SCUSTOM-DISCOUNT = '003'.

SCUSTOM-TELEPHONE = '01234/56789'.

INSERT INTO SCUSTOM CLIENT SPECIFIED VALUES SCUSTOM.

Reward if useful.....

9 REPLIES 9

Former Member
0 Kudos
138

Hi,

Check out these related threads

[]

[]

Former Member
0 Kudos
138

hi,

MODIFY: it is nothing but it 'll check for values if the record exist then it 'll modify else it will create new record.

The sy-subrc 'll be always 0 for this.

UPDATE: it is nothing but it 'll change the record only if it is available else it won't do anythng.

Thanks.

Arunprasad.P

Former Member
0 Kudos
138

hi,

refer to the thread

With Modify Option, If the current record is already available in the database, it will update the Changes. If it not available it will insert as a new record.

INSERT - Add a new record into the database table.

MODIFY - If record is available it modifies otherwise it wont modify.

UPDATE - If record is available its update the record otherwise it creates a new record.

insert-used to insert the records modify-used for alter the table field names update-used for modify the data

insert:Insert a set of new data’s into database table., update:Chance the existing data field in data base table., modify:If the record is present then you how to Update the data’s otherwise,Insert the new data.,

Regards,

sreelakshmi

Former Member
0 Kudos
138

Hi

UPDATE dbtab

UPDATE target source.

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.

The changes are definitively copied to the database with the next database commit. Until that point, they can still be undone using a database rollback.

MODIFY dbtab

MODIFY target FROM source.

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.

The changes are transferred finally to the database table with the next database commit. Up to that point, they can be reversed using a database rollback.

Former Member
0 Kudos
138

Hi,

Hi,

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. oder

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.

with regards,

sowjanyagosala.

Former Member
0 Kudos
138

hi,

MODIFY: Modify will insert a new row if the data doesnot exits.

UPDATE: it updates the record which isalredy there and errors out if no data is found but it will not create any new rows.

0 Kudos
138

Modify statement:

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 All lines were inserted or changed.

4 At least one line could not be processed as 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.

Note

The changes are finally transferred to the database table with the next database commit. Up to that point, they can be reversed with a database rollback.

The MODIFY statement sets a database lock until the next database commit or database rollback; incorrect usage can result in a deadlock kommen kann.

The number of rows that can be inserted into or changed in the tables of a database within a database LUW is restricted database-specifically by the fact that a database system can only manage a limited amount of locks and data in the rollback area.

+update statement+

UPDATE dbtab

Syntax

UPDATE target source.

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.

Note

The changes are definitively copied to the database with the next database commit. Until that point, they can still be undone using a database rollback

The statement UPDATE sets a database lock up to the next database commit or rollback, which may lead to a deadlock if used incorrectly.

For the specific database, the number of rows that can be changed within a database LUW in the database table is restricted by the fact that a database system can only manage a certain amount of data in the rollback area and from locks.

Former Member
0 Kudos
139

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.

Update Modify Insert stmts we use when we want to do some change / Insertion

(1) to database table from internal table or

(2) from work area to internal table.

( AA ) Update

If the intended record in the internal table is found in databse table means it will just update that record.

syntax to update database table from itab:::::

UPDATE dbtab FROM TABLE itab

Changes to lines made with the UPDATE command only becomefinal after a database commit

Without using internal table we can update database table directly as shown below:::::::::::::::::::::

TABLES SFLIGHT.

UPDATE SFLIGHT SET SEATSOCC = SEATSOCC + 3

WHERE CARRID = 'LH' AND

CONNID = '0400' AND

FLDATE = '19950228'.

( BB ) Modify is used to insert new record if the record doesnt exist in datbase table.system check this on primary key basis.

If the intended record in the internal table is found in databse table means it will just update that record.So here its equal to UPDATE stmt.

For changes to database table we use syntax as below ::::

MODIFY DatabaseTable FROM TABLE itab.

For changes to Internal table we use syntax as below ::::

MODIFY itab FROM wa INDEX idx.

http://TRANSPORTING f1 ... fn WHERE cond.

( CC ) Insert stmt is used to insert New records into databse table from internal table or to internal table from work area.

By default, data is only inserted in the current client. However, ifyou use the CLIENT SPECIFIED addition, you can switch off theautomatic client handling.

You cannot insert a table line if the table alreadycontains a record with the same primary key.

Syntax::::::::::

INSERT INTO dbtab CLIENT SPECIFIED VALUES wa.

or

INSERT (dbtabname) CLIENT SPECIFIED FROM TABLE itab.

Example

Adding customer "Robinson" to client 002:

TABLES SCUSTOM.

SCUSTOM-MANDT = '002'.

SCUSTOM-ID = '12400177'.

SCUSTOM-NAME = 'Robinson'.

SCUSTOM-POSTCODE = '69542'.

SCUSTOM-CITY = 'Heidelberg'.

SCUSTOM-CUSTTYPE = 'P'.

SCUSTOM-DISCOUNT = '003'.

SCUSTOM-TELEPHONE = '01234/56789'.

INSERT INTO SCUSTOM CLIENT SPECIFIED VALUES SCUSTOM.

Reward if useful.....

Former Member
0 Kudos
138

Hi

Below is the main deff...

MODIFY - If record is available it modifies otherwise it wont modify.

UPDATE - If record is available its update the record otherwise it creates a new record.