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

difference between append and modify statements?

Former Member
0 Likes
4,865

Hi all,

can anyone explain the difference between modify and append statements?

can anyone explain me with an real time scenario.

thanxs

hari

13 REPLIES 13
Read only

Former Member
0 Likes
3,072

Hi

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 points for useful Answers</b>

Regards

Anji

Read only

Former Member
0 Likes
3,072

hi

append will append new records in the tables

while modify will modify the existing rows/records

in the tables

regards

ravish

<b>plz dont forget to reward points if helpful</b>

Read only

Former Member
0 Likes
3,072

Hi,

Modify:

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

APPEND :

IT IS USED TO GET THE RECORD FROM THE INTERNAL TABLE HEADER TO THE BODY AREA.

IT ALLOWS DUPLICATION

Regards

Read only

Former Member
0 Likes
3,072

hi hari,

append statement is used to append or create a record into the internal table.

modify statement is used to modify or change an existing record of the internal table.

usually both are used with the work area.

eg. modify

LOOP AT itab INTO itab_wa.

SELECT COUNT(*) FROM bkpf INTO itab_wa-entrycount

WHERE bukrs = itab_wa-bukrs.

MODIFY itab FROM itab_wa.

ENDLOOP.

eg . append

itab-col1 = 'A'.

itab-col2 = '10'.

APPEND itab .

itab-col1 = 'B'.

itab-col2 = '20'.

APPEND itab .

Regards,

Roshani

Read only

Former Member
0 Likes
3,072

<b>APPEND </b>

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 addition INITIAL SIZE, the newly created last row is deleted.

<b>Note </b>

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

<b>Example </b>

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.

<b>MODIFY itab </b>

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.

MODIFY itab - itab_line

Syntax

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

[TRANSPORTING comp1 comp2 ... ] [result].

Extras:

1. ... TABLE itab

2. ... itab INDEX idx

3. ... TRANSPORTING comp1 comp2 ...

Effect

With these additions, the MODIFY statement assigns a line specified by itab_line to the content of the wa work area. The line can be specified using the table key or the table index. For the variant with the TABLE addition, the line is specified using the table key. For the variant with the INDEX addition, it is specified using the table index. The latter is only possible for index tables.

TRANSPORTING can be used to restrict the comp components to be modified. result can be used when you change an individual line after Release 6.10 to set a reference in the form of a field symbol or a data reference to the changed line.

In the case of access using the table key, index access to sorted tables and when the TRANSPORTING addition is used, the wa work area must be compatible with the line type of the internal table. Only in the case of insertion using the table index in standard tables without the TRANSPORTING addition can wa be incompatible with the line type of the internal table, and is converted to the line type according to the conversion rules.

Note

Apart from classes, the FROM wa specification can be left out if the internal table has an itab header line with the same name. The statement then uses the header line as a work area implicitly.

Addition 1

... TABLE itab

Effect

The line to be changed is determined by the fact that the content of the table key matches the content of the corresponding components in the wa work area. For tables with a key that is not unique, the first entry that is found is changed.

<b>Example </b>

Conversion of the local currency of an airline to Euro using key access in the scarr_tab internal table.

PARAMETERS p_carrid TYPE scarr-carrid.

DATA scarr_tab TYPE SORTED TABLE OF scarr

WITH UNIQUE KEY carrid.

DATA scarr_wa TYPE scarr.

SELECT *

FROM scarr

INTO TABLE scarr_tab.

READ TABLE scarr_tab INTO scarr_wa

WITH TABLE KEY carrid = p_carrid.

scarr_wa-currcode = 'EUR'.

MODIFY TABLE scarr_tab FROM scarr_wa

TRANSPORTING currcode.

Addition 2

... itab INDEX idx

Effect

This variant is only possible for standard tables and sorted tables. the line to be changed is specified by its idx table index. For idx, a data object of type i is expected.

The following cases result in an untreatable exception:

If idx contains a value less than or equal to 0

If the content of the table key of a sorted table was changed

Within a LOOP loop, the INDEX addition can be ommitted. In this case the current table line of the LOOP loop is changed. If the current line in the same loop pass was deleted, however, the behavior is undefined.

Note

The INDEX addition can also be after FROM wa.

<b>Example </b>

Conversion of the local currency of an airline to Euro in the scarr_tab internal table using index access.

PARAMETERS p_carrid TYPE scarr-carrid.

DATA scarr_tab TYPE SORTED TABLE OF scarr

WITH UNIQUE KEY carrid.

DATA: idx TYPE sy-tabix,

scarr_wa TYPE scarr.

SELECT *

FROM scarr

INTO TABLE scarr_tab.

READ TABLE scarr_tab

WITH TABLE KEY carrid = p_carrid

TRANSPORTING NO FIELDS.

idx = sy-tabix.

scarr_wa-currcode = 'EUR'.

MODIFY scarr_tab INDEX idx FROM scarr_wa

TRANSPORTING currcode.

Addition 3

... TRANSPORTING comp1 comp2 ...

Effect

The TRANSPORTING addition has the effect that only the specified comp1 comp2 ... components of the work area are assigned to the corresponding components of the line(s) to be changed. For sorted tables and hashed tables, no table key components may be specified after TRANSPORTING.

The comp1 comp2 ... component specifications are made in accordance with the rules specified in Component specification, with the constraint that after TRANSPORTING, no attributes of classes can be addressed using the object component selector.

<b>Example </b>

Change the contents of the planetype component for all lines in the sflight_tab internal table in which this component contains the value p_plane1 to the value p_plane2.

PARAMETERS: p_carrid TYPE sflight-carrid,

p_connid TYPE sflight-connid,

p_plane1 TYPE sflight-planetype,

p_plane2 TYPE sflight-planetype.

DATA sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate.

DATA sflight_wa TYPE sflight.

SELECT *

FROM sflight

INTO TABLE sflight_tab

WHERE carrid = p_carrid AND

connid = p_connid.

sflight_wa-planetype = p_plane2.

MODIFY sflight_tab FROM sflight_wa

TRANSPORTING planetype WHERE planetype = p_plane1.

Regards,

Pavan

Read only

Former Member
0 Likes
3,072

Hi,

MODIFY Command will modify a record if a record with the same key feilds exists else it will insert a new record.

APPEND : This will insert a new record in the database , if a record with the same key already exists then an error will occure.

Thanks.

Reward If Helpful.

Read only

Former Member
0 Likes
3,072

If the primary key is already exist in the database table then the append statement will not have any effect. The same in case of modify, the perticular row of database table will updated by new values.

If the primary key is not exist in the database table, modify & append will act same. both will insert a row in the table.

Read only

former_member188827
Active Contributor
0 Likes
3,072

append is used to insert data in an internal table...e.g

select * from vbak into itab where vbeln = '1234'.

append itab.

endselect.

dis will insert record from vbak into internal table itab which satisfy selection criteria.

modify is used to make changes permanant.

e.g .

delete from vbak where vbeln = '234'.

modify vbak.

Read only

Former Member
0 Likes
3,072

Hi,

1). "Modify" modifies the the current internal table.

For eg. Modify itab from wa_itab.

Or Modify itab from wa_itab transporting...............

No additional records are added at the end.

2). "Append" appends(Adds) a record to the end of the table.

For eg. We use append in displaying data using ALV, wheer we append the contents to the fieldcatalog.So, the contents are added one after the other, and the result is finally dispalyed on screen.

go through this link...

Regards,

Priyanka.

Read only

Former Member
0 Likes
3,072

Hi,

append staement insert the data from header to the end of of the body of an internal table.

modify statement also insert a data in a database table through modify statement.

u can also use this link...

http://wiki.ittoolbox.com/index.php/ABAP_certification_questions

If useful reward me with points.

Thanks

Sanket.

Read only

Former Member
0 Likes
3,072

hi all,

Thanxs a lot for all ur responses. i have assigned points for everyone.

regd

hari

Read only

Former Member
0 Likes
3,072

Hi Hari,

Append is adding a new record to internal table

eg. itab_matnr-matnr = '1000'.

append itab.

modify - modifying an already existing record

eg. loop at itab_matnr

lv_tabix = sy-tabix.

if itab_matnr-matnr = '1000'.

itab_matnr-matnr = '2000'.

modify itab_matnr index lv_tabix.

endif.

endloop

Regards

Arun

Read only

jaideeps
Product and Topic Expert
Product and Topic Expert
0 Likes
3,072

hi hari,

Append can insert/add the new data/records...

whereas modify will update the data to the existing record/data..

thanks

jaideep

*reward points if useful