‎2007 Oct 04 7:08 AM
Hello friends,
what is the difference between APPEND MODIFY and INSERT in ABAP.
Regards.
‎2007 Oct 04 7:10 AM
APPEND just adds a new record (always at the end).
INSERT inserts a new record where ever we specify ex: 2nd, 3rd or any place
MODIFY inserts a new record where ever we specify if the record is not there already.But if the record is already there, then it just modifies the record.
‎2007 Oct 04 7:10 AM
APPEND just adds a new record (always at the end).
INSERT inserts a new record where ever we specify ex: 2nd, 3rd or any place
MODIFY inserts a new record where ever we specify if the record is not there already.But if the record is already there, then it just modifies the record.
‎2007 Oct 04 7:11 AM
Hi
<b>Modify:</b>
If the value of key fields in the internal table matches with the key fields values in database table,modify will update the existing entry.Otherwise,it will insert new entry
<b>APPEND :</b>
IT IS USED TO GET THE RECORD FROM THE INTERNAL TABLE HEADER TO THE BODY AREA.
IT ALLOWS DUPLICATION
Append will move the record into the body of the internal table from the header
Where as Modify is to change/modify the record in itab
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
<b>Reward if usefull</b>
‎2007 Oct 04 7:12 AM
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.
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
INSERT itab
Syntax
INSERT line_spec INTO itab_position [result].
Effect
This statement adds one or more lines line_spec to a position itab_position of an internal table. The position can be specified using the table key or the table index. As of release 6.10, result can be used to set a reference as a field symbol or data reference to the inserted line when inserting a single line.
System Fields
sy-subrc Meaning
0 One or more lines were inserted.
4 No line was inserted because either a line of the same unique key already existed when inserting single lines using the table key or the specified index was greater than the current number of lines plus one when inserting the lines using the table index.
‎2007 Oct 04 7:12 AM
Hi
append : aads a new row to itab at the last line of the itab
modify : modifyies content of an existing row in an itab
inserts : inserts a new row at the defined position of the itab like if it has 10 lines and you want the new line to be inserted in the 4 th position the it is inserted and the next rows are moved 1 row down
reward if helpful
vivekanand
‎2007 Oct 04 7:13 AM
I presume you use these instruction with internal table
APPEND add the record at the end of the internal table (can result in problem if table is described as sorted and the record is not the last one)
INSERT insert the record into the internal table before the current position (should be used if sorted table)
MODIFY change a record into the internal table, record is explicitly given or implicitly in a LOOP AT
Regards
‎2007 Oct 04 7:15 AM
APPEND: a new record is inserted at the end of the table.
INSERT: new record is inserted as per sorting
MODIFY: to change the already existing records in the table
‎2007 Oct 04 7:15 AM
hi ashish,
APPEND - just add the record into internal table.
INSERT - Insert the records into database table and check the primary key.if already that records exist in database table then it throw dump.
MODIFY - Insert the records into database table and check the primary key.if already that records exist in database table it modifies the record and update.
Thanks,
Senthil kumar