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

modify and update commands

Former Member
0 Likes
5,509

hi,

Plz tell me the differences between MODIFY and UPDATE Statements.IS IT NECESSARY TO USE UPDATE Statement AFTER MODIFY Statemant. Thanx in advance

hi,

Plz tell me the differences between MODIFY and UPDATE Statements.IS IT NECESSARY TO USE UPDATE Statement AFTER MODIFY Statemant. Thanx in advance

7 REPLIES 7
Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
3,589

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.

Cheers,

SImha.

Note: Please mark all the helpful answers.

Read only

Former Member
0 Likes
3,589

'Insert' will add a new record or a new row into the database table.

'Update' will modify a record in the DB table.

'Modify' it is a combination of both insert and update...

Also check these links

Read only

Former Member
0 Likes
3,589

Update Statement will modify the existing record ..

where as

Modify statement will modify the existing record if the record exists .. else creates a new record..

REgards,

Santosh

Read only

Former Member
0 Likes
3,589

Hi,

MODIFY will insert record if the row is not there in the table.

UPDATE will not insert record if the row is not there in the table. It will return sy-subrc to 4.

In UPDATE you can update specific fields using SET addition.

No it is not necessary to use UPDATE after MODIFY statement..

Thanks,

Naren

Read only

Former Member
0 Likes
3,589

hi

good

UPDATE->

Bundling using Function Modules for Updates

If you call a function module using the statement CALL FUNCTION ... IN UPDATE TASK, the function module is flagged for execution using a special update work process. This means that you can write the Open SQL statements for the database changes in the function module instead of in your program, and call the function module at the point in the program where you would otherwise have included the statements. When you call a function module using the IN UPDATE TASKaddition, it and its interface parameters are stored as a log entry in a special database table called VBLOG.

The function module is executed using an update work process when the program reaches the COMMIT WORKstatement. After the COMMIT WORKstatement, the dialog work process is free to receive further user input. The update work process is responsible for the update part of the SAP LUW. The statement COMMIT WORKcloses the SAP LUW for the dialog part of the program and starts the update. The SAP LUW is complete once the update process has committed or rolled back all of the database changes. Bundling using function modules is called Update.

http://help.sap.com/saphelp_nw2004s/helpdata/en/41/7af4bfa79e11d1950f0000e82de14a/content.htm

MODIFY->

To modify the lines of a completed list from within the program, use the MODIFY LINE statement. There are two ways to specify the line you want to modify:

· Explicitly:

MODIFY LINE n INDEX idx

.

You can refer to the line most recently read:

MODIFY CURRENT LINE .

This statement modifies the line most recently read by means of line selection (F2) or read by the READ LINE statement.

Apart from the ones described above, the modificationsaddition contains several other possibilities to modify the line. For more information on this and on the individual additions of the MODIFY LINEstatement , refer to the keyword documentation.

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dba4b235c111d1829f0000e829fbfe/content.htm

2ND Q->

IT IS NOT NECESSARY.

THANKS

MRUTYUN

Read only

Former Member
0 Likes
3,589

Hi,

I have the following statement in my program:

MODIFY ZDBTABLE FROM INTERNAL_TABLE.

ZDBTABLE has two records. There are two records in INTERNAL_TABLE as well. I expect the MODIFY statement to change last field of all records in database table. It only changes one record - the last record only. Why?

Thanks in advance.

Read only

0 Likes
3,589

In your statement below,

MODIFY ZDBTABLE FROM INTERNAL_TABLE.

Here do INTERNAL_TABLE delcared with header line? If yes it is considering the header line data.

To consider the whole table, try like below.

MODIFY ZDBTABLE FROM TABLE

INTERNAL_TABLE.

Below is the effect of this.

If an internal table is specified, the system processes all lines in the internal table according to the rules for the work area. The line type of the internal table has to meet the requirements for use in Open SQL statements.

If the change to a line in the internal table would lead to a double entry in a unique secondary index, the corresponding line is not inserted and sy-subrc is set to 4. If the internal table is empty, sy-subrc is set to 0. The sy-dbcnt system field is always set to the number of lines that were actually processed.