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: 

Difference between modify , append and update

Former Member
0 Kudos

Hi,

Give me diffference between modify , append and update?

If possible give me with example.

Thanks & regards

venkravi

1 ACCEPTED SOLUTION

prasanth_kasturi
Active Contributor

hi,

modify it behaves as both update and insert.

if record is there it behaves as update or like insert.

update it changes the already updated record. its only for database tables

append : it add new record as thel ast row

regards

prasnth

Edited by: prasanth kasturi on May 15, 2008 2:57 PM

13 REPLIES 13

Former Member
0 Kudos

Hi

0 Kudos

Jagadish Raj Kumar Avidi, i think each time you only post 'Hi' without any contents and later find your answer and edit it. If if continues, we will be forced to inform about this.

0 Kudos

Mind ur own business

0 Kudos

OK. I will let u know my business soon.

Former Member
0 Kudos

Hi.

INSERT

The INSERT statement inserts one or more rows specified in source in the database table specified in target. The two variants with INTO and VALUES or without INTO with FROM behave identically, with the exception that you cannot specify any internal tables in source after VALUES.

1.The inserted rows are finally included in the table in the next database commit. Up until this point, they can still be removed by a database rollback.

2.The statement INSERT sets a database lock until the next database commit or rollback. If used incorrectly, this can lead to a deadlock.

3.The number of rows that can be inserted in the tables of a database within a database LUW is limited, since a database system can only manage a limited amount of locks and data in the rollback area.

MODIFY

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

System fields

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

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

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

Append

This statement appends one or more rows line_spec to an internal index table itab. If itab is a standard table, you can use SORTED BY to sort the table in a specified way. Use result when appending a single row as of release 6.10 to set a reference to the appended row in the form of a field symbol or a data reference

1.When using only the statement APPEND with addition SORTED BY to fill an internal table, this rule results in an internal table that contains no more than the number of rows specified in its definition after INITIAL SIZE and that is sorted in descending order by component comp (ranking).

Update

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.

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

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

prasanth_kasturi
Active Contributor

hi,

modify it behaves as both update and insert.

if record is there it behaves as update or like insert.

update it changes the already updated record. its only for database tables

append : it add new record as thel ast row

regards

prasnth

Edited by: prasanth kasturi on May 15, 2008 2:57 PM

prasanth_kasturi
Active Contributor
0 Kudos

hi,

modify it behaves as both update and insert.

if record is there it behaves as update or like insert.

update it changes the already updated record

append : it add new record as the last row

regards

prasanth

Former Member
0 Kudos

Hi,

APPEND

Simply adds record at the end of the internal table....

COLLECT:COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .

If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields,the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.

If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .

After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.

COLLECT can create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or compression are unimportant, or two values with identical default key field values could not possibly occur in your particular task, you should use APPEND instead. However, for a unique or compressed dataset which is also efficient, COLLECT is the statement to use.

If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that the internal table will actually be unique or compressed, as described above and COLLECT will run very efficiently.

If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.

see the doc

MODIFY

... FROM { {wa} | {TABLE itab} }.

1. ... FROM wa

2. ... FROM TABLE itab

A wa data object that is not table-type or an itab internal table can be specified after FROM. On the one hand the content of the data objects determines whether the line(s) are inserted or changed, and on the other hand, which values are inserted or used for changes.

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

Regards,

Shiva Kumar

Former Member
0 Kudos

Hi,

Append means it append record as last row of the table.

Modify used for if record exist then it modifies that record otherwise ( if record is not there in table ) it inserts that record into table.

Update it updated the record.

Reward if useful

Narasimha

Former Member
0 Kudos

Hi,

Syntax Diagram

MODIFY itab

Syntax

MODIFY { itab_line | itab_lines }.

Effect

This statement changes the content of one or several itab_line or itab_lines lines that can be specified using the table key or the table index.

System fields

sy-subrc Meaning

0 At least one line was changed.

4 No lines were changed, since no suitable line was found for the insertion using the table key, or the specified index was greater than the current number of lines for the insertion using the table index.

Note

Apart from using the MODIFY statement, the content of an individual table line can be changed using assignments to field symbols and dereferenced data references that point to the table line.

Exceptions

Non-Catchable Exceptions

Cause: Illegal dynamic specification of a line component

Runtime Error: ITAB_ILLEGAL_COMPONENT

Cause: Illegal key component in the TRANSPORTING list.

Runtime Error: ITAB_ILLEGAL_TRANSP_COMP

Syntax Diagram

APPEND

Syntax

APPEND line_spec TO itab [SORTED BY comp] [result].

Addition:

... SORTED BY comp

Effect

This statement appends one or more rows line_spec to an internal index table itab. If itab is a standard table, you can use SORTED BY to sort the table in a specified way. Use result when appending a single row as of release 6.10 to set a reference to the appended row in the form of a field symbol or a data reference.

For the individual table types, appending is done as follows:

To standard tables, rows are appended directly and without checking the content of the internal table.

To sorted tables, rows are appended only if they correspond to the sort sequence and do not create duplicate entries with unique table key. Otherwise, an untreatable exception is triggered.

To hashed tables, no rows can be appended.

The APPEND statement sets sy-tabix to the table index of the last appended row.

Addition

... SORTED BY comp

Effect

This addition is allowed only if you specify a workarea wa and if you use a standard table, where wa must be compatible to the row type of the table. You can specify component comp as shown in section Specifying Components, however, you can access only one single component and no attributes of classes using the object component selector.

The statement is executed in two steps:

Starting at the last row, the table is searched for a row, in which the value of component comp is greater than or equal to the value of component comp of wa. If such a row exists, the workarea wa is included after this row. If no such row exists, the workarea wa is included before the first row. The table index of all rows following the included rows increases by one.

If the number of rows before the statement is executed is greater than or equal to the number specified in the definition of the internal table in the INITIAL SIZE addition, the newly-created last row is deleted.

Note

When using only the statement APPEND with addition SORTED BY to fill an internal table, this rule results in an internal table that contains no more than the number of rows specified in its definition after INITIAL SIZE and that is sorted in descending order by component comp (ranking).

The SORT statement should usually be used instead of APPEND SORTED BY.

Example

Creating a ranking of the three flights of a connection showing the most free seats.

PARAMETERS: p_carrid TYPE sflight-carrid,

p_connid TYPE sflight-connid.

DATA: BEGIN OF seats,

fldate TYPE sflight-fldate,

seatsocc TYPE sflight-seatsocc,

seatsmax TYPE sflight-seatsmax,

seatsfree TYPE sflight-seatsocc,

END OF seats.

DATA seats_tab LIKE STANDARD TABLE OF seats

INITIAL SIZE 3.

SELECT fldate seatsocc seatsmax

FROM sflight

INTO seats

WHERE carrid = p_carrid AND

connid = p_connid.

seats-seatsfree = seats-seatsmax - seats-seatsocc.

APPEND seats TO seats_tab SORTED BY seatsfree.

ENDSELECT.

Exceptions

Non-Catchable Exceptions

Cause: Including a row with identical key (target table defined with UNIQUE)

Runtime Error: ITAB_DUPLICATE_KEY_IDX_OP

Cause: Violation of the sorting sequence due to an APPEND to a sorted table

Runtime Error: ITAB_ILLEGAL_SORT_ORDER:

Cause: Unallowed index value (<= 0) for a FROM, TO, or INDEX specification

Runtime Error: TABLE_INVALID_INDEX

Syntax Diagram

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.

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

Modify-Inserts new record if the record doesnot exist

and updates if a record exist in case of data base table.

In case of internal table modifies the content if record exist and sets sy-subrc to 4 if record does't exist.

APPEND-Used only for internal tables to append the record at end.

UPDATE-Updates the data base table if record exist and sets sy-subrc to 4 if record doesnot exist.

INSERT-Will always inserts the record. In case of internal table u have to specify the position and in case of database table record should not exit with same primary key. If exist u will get dump.

In all cases record existance will be checked based on the primary key of the database/Internal table.

Thanks,

Vinod.

Former Member
0 Kudos

APPEND used to insert line in Internal table.

Modify/Update is used to modify the internal table and Database table.

While updating database table Modify & Update works a little different.

Modify search whether the specific row (Key) exits, if exist then update it otherwise insert a new row.

Insert search the key, if it exists then do not exist then return sy-subrc 0, otherwise update the value of that row.

Former Member
0 Kudos

UPDATE is used to update the database table,

But MODIFY acts as UPDATE statement which will update the database table and internal table as well when record already exits, and it acts as INSERT statement when there is no record in the table.