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

abap

Former Member
0 Likes
1,040

hi all,

what is the difference between append , insert and move.

what is the use of collect statement?

thanks in advance,

chandana

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,008

Hi,

APPEND:

Appends the contents of a structure to an internal table. This operation can only be used with standard tables.

syntax: APPEND wa to itab.

INSERT:

Inserts the content of a structure into an internal table.

In the case of a standard table, this content is appended, in a sorted table it is inserted in the right place according to the key, and in a hashed table it is inserted according to the hash algorithm.

syntax:INSERT wa into table itab <condition>

Example:

data: it_mara type mara,

wa_mara like line of it_mara.

*fill structure with values

wa_mara-matnr = .........

wa_mara-maktx = ........

wa_mara-meins = ..........

INSERT wa_mara into table it_mara.

COLLECT:

Accumulates the contents of a structure in row of an internal table that

has the same key. In doing so, only non-key fields are added. Hence, this

statement can only be used for tables whose non-key fields are all numeric.

Please reward points if helpful.

7 REPLIES 7
Read only

nikhil_chitre
Active Participant
0 Likes
1,008

Hi,

Just type these ststements on ABAP Editor. and press F1.

u'll get a detailed explaniation SAP help. with Example.

Regards,

Nikhil

Read only

Former Member
0 Likes
1,008

Hi,

Please refer sap help or just do an F1 on the keyword in ABAP editor.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb36c8358411d1829f0000e829fbfe/frameset.htm

Regards,

N.

Read only

Former Member
0 Likes
1,008

Hi,

Append : It appends record in last row of a table.

Insert :u can insert a row what ever u want .

move : it moves one field content to another field.

Collect : if any record exist with same valuse it adds to recods and stored it into one row ( it now allow duplicates ).

Regards,

Narasimha

Read only

Former Member
0 Likes
1,008

Hi,

Using INSERT statement. INSERT statement adds a line/work area to the internal table. You can specify the position at which the new line is to be added by using the INDEX clause with the INSERT statement.

Here the <wa> or INITIAL LINE is inserted into ITAB at index <IDX>. The new entry will have the index <idx> and the following line has the index of <idx> + 1. Suppose there are less than <idx> - 1 entries, then the new line cannot be inserted and hence the value of SY-SUBRC is set to 4.

SY-SUBRC is the system variable which store the return value after the execution of a operation. It has the value of 0 for success and 4 for failure.

Using the APPEND statement we can either add one line from another work area to the internal table or we can add one initial line to the internal table. Initial lines adds a line initialized with the correct value for its type to the table. Suppose you have a table with two columns where col1 is an integer and col2 is a character. Then APPEND initial line , adds a line initialized with respect to the data type of the columns, i.e. 0 for Col1 and space for Col2.

Here <wa> or the Initial Line is appended to the internal table <itab>.

The system variable SY-TABIX contains the index of the appended line.

COLLECT is another form of statement used for populating the internal tables. Generally COLLECT is used while inserting lines into an internal table with unique standard key.

Incase of tables with Header line, INTO option is omitted. Suppose there is already an entry having a key same as the one you are trying to append, then a new line is not added to the table, but the numeric fields of both the entries are added and only one entry corresponding to the key is present. Value of SY-TABIX is changed to the row of the original entry. Else COLLECT acts similar to APPEND and SY-TABIX contains the index of the processed line.

The contents of one internal table can be copied to another by using the APPEND LINES or INSERT LINES statement. A more simpler way is to use tany of the following syntaxu2019s.

MOVE ITAB1 TO ITAB2.

OR

ITAB1 = ITAB2.

These copy the contents of ITAB1 to ITAB2. Incase of internal tables with header line we have to use [] inorder to distinguish from work area. So, to copy contents of internal tables with header line the syntax becomes,

ITAB1[] = ITAB2[].

Regards

Kannaiah

Read only

Former Member
0 Likes
1,008

Hi,

1.Append stmt is used to append in a last row of the internal table.

2.Insert stmt is used to insert the rows in a specific row i.e when we want to insert in a 6th row we can do by using this stmt.but it is not possible in append stmt.

3.Move stmt is used to move the data's from one internal table to another internal table.There is move-corresponding also,it is used to move from one field to corresponding field.

4.Collect is nothing but adding the values.for ex In a internal table if the key fields are same then we add these two into one.This is the purpose of collect stmt.

Thank u,

Manjula Devi.D

Read only

Former Member
0 Likes
1,008

hi,

Using the APPEND statement we can either add one line from another work area to the internal table or we can add one initial line to the internal table. Initial lines adds a line initialized with the correct value for its type to the table. Suppose you have a table with two columns where col1 is an integer and col2 is a character. Then APPEND initial line , adds a line initialized with respect to the data type of the columns, i.e. 0 for Col1 and space for Col2.

Though Append looks simpler, some cautions have o be taken while using the APPEND statement. APPEND statement may give duplicate entries. It works even if a line with the same standard key already exists.

AND NEXT------INSERT:

INSERT statement adds a line/work area to the internal table. You can specify the position at which the new line is to be added by using the INDEX clause with the INSERT statement.

Consider the syntax shown in the slide. Here the <wa> or INITIAL LINE is inserted into ITAB at index <IDX>. The new entry will have the index <idx> and the following line has the index of <idx> + 1. Suppose there are less than <idx> - 1 entries, then the new line cannot be inserted and hence the value of SY-SUBRC is set to 4.

SY-SUBRC is the system variable which store the return value after the execution of a operation. It has the value of 0 for success and 4 for failure.

AND NEXT -


MOVE:

The contents of one internal table can be copied to another by using the APPEND LINES or INSERT LINES statement. A more simpler way is to use any of the following syntaxu2019s.

MOVE ITAB1 TO ITAB2.

OR

ITAB1 = ITAB2.

These copy the contents of ITAB1 to ITAB2. Incase of internal tables with header line we have to use [] inorder to distinguish from work area. So, to copy contents of internal tables with header line the syntax becomes,

ITAB1[] = ITAB2[].

THE USE OF COLLECT STATEMENT:

COLLECT is another form of statement used for populating the internal tables. Generally COLLECT is used while inserting lines into an internal table with unique standard key. The syntax for COLLECT statement is as shown.

Incase of tables with Header line, INTO option is omitted. Suppose there is already an entry having a key same as the one you are trying to append, then a new line is not added to the table, but the numeric fields of both the entries are added and only one entry corresponding to the key is present. Value of SY-TABIX is changed to the row of the original entry. Else COLLECT acts similar to APPEND and SY-TABIX contains the index of the processed line.

Let us see an example using COLLECT statement.

Example:

Data: Begin of itab occurs 3,

column1(3) type C,

column2(2) type N,

column3 type I,

End of itab.

itab-column1 = u2018abcu2019.

itab-column2 = u201912u2019.

itab-column3 = 3.

collect itab.

write /sy-tabix.

itab-column1 = u2018defu2019.

itab-column2 = u201934u2019.

itab-column3 = 5.

collect itab.

write/sy-tabix.

itab-column1 = u2018abcu2019.

itab-column2 = u201912u2019.

itab-column3 = 7.

collect itab.

write /sy-tabix.

Loop at itab.

write :/itab-column1,

itab-column2,

itab-column3.

Endloop.

Result:

1

2

1

abc 12 10

def 34 5

HOPE THIS MAY BE HELPFUL....

reward if helps...

regards,

praveena.

Read only

Former Member
0 Likes
1,009

Hi,

APPEND:

Appends the contents of a structure to an internal table. This operation can only be used with standard tables.

syntax: APPEND wa to itab.

INSERT:

Inserts the content of a structure into an internal table.

In the case of a standard table, this content is appended, in a sorted table it is inserted in the right place according to the key, and in a hashed table it is inserted according to the hash algorithm.

syntax:INSERT wa into table itab <condition>

Example:

data: it_mara type mara,

wa_mara like line of it_mara.

*fill structure with values

wa_mara-matnr = .........

wa_mara-maktx = ........

wa_mara-meins = ..........

INSERT wa_mara into table it_mara.

COLLECT:

Accumulates the contents of a structure in row of an internal table that

has the same key. In doing so, only non-key fields are added. Hence, this

statement can only be used for tables whose non-key fields are all numeric.

Please reward points if helpful.