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 COLLECT and APPEND

Former Member
5,145

hai friends,

i want the basic difference between COLLECT and APPEND statements

thanks in advance

@jay

1 ACCEPTED SOLUTION
Read only

Simha_
Product and Topic Expert
Product and Topic Expert
3,550

Hi,

<b>APPEND</b>

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

<b>COLLECT:</b>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.

Cheers,

Simha.

14 REPLIES 14
Read only

Former Member
0 Likes
3,550

Hi ajay,

1. APPEND simply

inserts one record at the end.

2. While Collect is Intelligent.

(it will not simply add one record.

Instead.

3. It will check all the alpha-numeric field combinations

in the internal table

and if found, then it will simply SUM up the numeric values in that record,

else it will insert one record)

regards,

amit m.

Read only

0 Likes
3,550

hai,

I did't clear with answer for COLLECT statement.. what i know is ..that append statement will append all the records at the end of the table.. is it correct or not.. clarify..

and give me the some datiled abt COLLECT

thanks

@jay

Read only

0 Likes
3,550

Hi Ajay,

Append will append the record at the end of the internal table.

But the collect will add up all the numerical fields based on the character fields.

Eg: you have an internal table with three columns

f1 f2 f3

a 1 3

b 1 4

a 3 6

b 2 4

c 5 6

when you are collecting this data into a new internal table.... the new internal table will have the following data:

f1 f2 f3

a 4 9

b 3 8

c 5 6

Regards,

Ramesh

*If reply found useful reward with points

Read only

3,550

Very good explanation!

Thanks..

Read only

gopi_narendra
Active Contributor
0 Likes
3,550

just to put simply on one line

collect will sum up all the numeric field values of the internal table

insert adds a new record to the internal table

Regards

Gopi

Read only

Former Member
0 Likes
3,550

HI,

<b>APPEND :</b>

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

IT ALLOWS DUPLICATION

<b>COLLECT:</b>

IT IS USED TO A GET A RECORD FROM HEADER TO THE BODY AREA BUT IT WILL NOT ALLOW ANY DUPLICATION EXCEPT IF THERE IS ANY NUMERIC FIELS IT ADDS THAT FIELDS DATA BUT NOT AS A NEW RECORD

Regards

Sudheer

Read only

Former Member
0 Likes
3,550

Collect will all add the numeric values in the fields based on key fields allows you to create summerized data sets

where as

Append will append the records at the end of the last record

~~Guduri

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
3,551

Hi,

<b>APPEND</b>

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

<b>COLLECT:</b>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.

Cheers,

Simha.

Read only

Former Member
0 Likes
3,550

Hi Ajay,

Append Statement simply adds one record at the end of internal table.

Collect statement sums up the quantity fields in the internal table.

e.g. If an nternal table has the following data :

A B 1

C B 2

The next data is say A B 2.

Then Result of Append will be

A B 1

C B 2

A B 2

Result of collect will be

A B 3

C B 2

Hope it clarifies ur doubt.

Please award points if helpful.

Thanks,

Himanshu.

Read only

Former Member
0 Likes
3,550

hi

in append record will just inserted to internal table.

but when you use collect , all numeric fields will be added together if value of non numeric is same.

for eg suppose u have following data

a 10 5

b 4 6

a 3 1

reward points if helpful

using collect the internal table will be

a 13 6

b 4 6

Read only

Former Member
0 Likes
3,550

by default C N D T X are the datatypes for key field of a int table <if you are not defining any explicit key field> so collect will add all other data types fields like integer if those key fields are repeating

suppose you have

f1(char) f2(int)

a 1

a 3

b2

b5

collect here will give you two rows a 4 and b7.

append is appending the rows at the end .

itab-f1 = b.

itab-f1 = 7.

append itab.

now your itab.

f1(char) f2(int)

a 1

a 3

b 2

b 5

b 7.

regards

shiba dutta

Read only

Former Member
0 Likes
3,550

append lines Statement

Use the append lines statement when you want to append rows to the end of the target table.

Internal Table Using collect

Using the collect statement, you can create totals within an internal table as you fill it.

Read only

Former Member
0 Likes
3,550

After MY SIMPLE DEFINITION ABOVE...

Here goes an example of Collect Statement:

I_final contains:

forcuram forcurkey

599.40 EUR

599.40 EUR

549.91 USD

  LOOP AT i_final INTO wa_final.

    wa_temp-forcuram  = wa_final-forcuram.
    wa_temp-forcurkey = wa_final-forcurkey.

    COLLECT wa_temp INTO i_collect.

    CLEAR: wa_temp.

  ENDLOOP.

LOOP AT i_collect INTO wa_collect.
    WRITE:  / wa_collect-forcuram,
              wa_collect-forcurkey.

ENDLOOP.

i_collect now contains:

forcuram forcurkey

1198.80 EUR

549.91 USD

*Kindly reward points if this is helpful. Thanks!

Read only

natalie_gohain
Explorer
3,550

Append keyword is used to transfer data from work area to the last record of internal table.

Syntax: Append <work_area> to <internal_table>.

Ex: Append wa_ekpo to it_ekpo.

Collect keyword checks the internal table for the presence of the record based on the key field. If it is not there, it performs like append by adding record to the last; else it adds the numeric fields from work area to number field in the internal table.

Syntax: Collect <work_area> into <internal_table>.

Ex: - Collect wa_ekpo into it_ekpo.