2008 Jun 24 6:21 AM
2008 Jun 24 6:23 AM
hi,
append statemnt : add records at the end of table, adds the new record as the last record of the table
collect statemnt : sums up the numeric values based on the key, If the new coming record has same key then the new records numeric fields are added to the existing record else it works like append i.e add rows at the end of table
See the below example
data : begin of itab occurs 0,
f1(2),
f2 type i,
end of itab.
data : begin of jtab occurs 0,
f1(2),
f2 type i,
end of jtab.
itab-f1 = 'AA'.
itab-f2 = 123.
append itab.
itab-f1 = 'AA'.
itab-f2 = 123.
append itab.
jtab-f1 = 'AA'.
jtab-f2 = 123.
collect jtab.
jtab-f1 = 'AA'.
jtab-f2 = 123.
collect jtab.
jtab-f1 = 'BB'.
jtab-f2 = 123.
collect jtab.
Write : / 'APPEND STATEMENT'.
loop at itab.
write :/ itab-f1,
itab-f2.
ENDLOOP.
Write : / 'Collect STATEMENT'.
loop at jtab.
write :/ jtab-f1,
jtab-f2.
ENDLOOP.
O/P : Append Statenment
AA 123
AA 123
Collect Statement
AA 246
BB 123
regards
prasanth
2008 Jun 24 6:23 AM
hi,
append statemnt : add records at the end of table, adds the new record as the last record of the table
collect statemnt : sums up the numeric values based on the key, If the new coming record has same key then the new records numeric fields are added to the existing record else it works like append i.e add rows at the end of table
See the below example
data : begin of itab occurs 0,
f1(2),
f2 type i,
end of itab.
data : begin of jtab occurs 0,
f1(2),
f2 type i,
end of jtab.
itab-f1 = 'AA'.
itab-f2 = 123.
append itab.
itab-f1 = 'AA'.
itab-f2 = 123.
append itab.
jtab-f1 = 'AA'.
jtab-f2 = 123.
collect jtab.
jtab-f1 = 'AA'.
jtab-f2 = 123.
collect jtab.
jtab-f1 = 'BB'.
jtab-f2 = 123.
collect jtab.
Write : / 'APPEND STATEMENT'.
loop at itab.
write :/ itab-f1,
itab-f2.
ENDLOOP.
Write : / 'Collect STATEMENT'.
loop at jtab.
write :/ jtab-f1,
jtab-f2.
ENDLOOP.
O/P : Append Statenment
AA 123
AA 123
Collect Statement
AA 246
BB 123
regards
prasanth
2008 Jun 24 6:24 AM
hi,
APPEND : ADD the records at the end of the internal table,
if it has primary key if u try to append the same primary key values it throws error.
COLLECT: it has the same functionality of inserting the record
if the primary key value exists already if sums up the numeric value for that record.
if no same primary key value is available then the record is inserted.
Regards,
priya
2008 Jun 24 6:25 AM
hi,
Collect stmt will add up all the numeric values for the identical record if any in the int table.
where as Append stmt will add the record at the end of the int table.
Reward points if useful
Chandra
2008 Jun 24 6:26 AM
Hi ,
Append add the records to last row .
for eg . ITAB is ur internal tab and has one record .
you have fields
Field a Field B COUNTER
A B 1
If you have another record say A B 2
and you say APPEND then it becomes
Field a Field B COUNTER
A B 1
A B 2
But if you say COLLECT ,it sees the fields of record which are matching so Field A and Field B are matching so it will add the counter .but you should have sort ITAB by field A and Field B
Field a Field B COUNTER
A B 2
Please reward if useful.
2008 Jun 24 6:27 AM
Hi,
Append Adds a record while Collect Adds up all Numeric fields.
Regards
2008 Jun 24 6:28 AM
hi Vinay,
Append :
Appends a new line to the end of the internal table itab. You can only use this variant with index tables (standard or sorted table).
If you specify wa TO , the new line is taken from the contents of the explicitly specified work area wa.
If you use INITIAL LINE TO, a line filled with the correct initial value for the type is added.
If the part before itab is omitted, the new line is taken from the header line of the internal table itab.
After the APPEND, the system field SY-TABIX contains the index of the last line in the table.
The system variable SY-TABIX contains the index of the appended line.
CAUTION :
Using APPEND may give duplicate entries.
APPEND works even if a line with same standard key already exists.
Collect :
COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key (see Key definition for internal tables ). The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa. itab must have a flat structure, that is, it may not contain other internal tables. All components that are not part of the key must be have numeric types (see ABAP numeric types).
If the system finds an entry, the numeric fields that are not part of the table key (see ABAP number types) are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead.
Please search SDN before posting new threads
Reward Points if Helpful.
2008 Jun 24 6:29 AM
Hi,
MODIFY u2013 Inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.
APPEND u2013 This statement appends one or more rows to an internal table.
COLLECT -This inserts the contents of a work area either as single row into an internal table or adds the values of its numeric components to the corresponding values of existing rows with the same key.
regards,
teja.
2008 Jun 24 6:32 AM
COLLECT :
When the line is inserted, the system checks whether there is already a table entry that matches the key. If there is no corresponding entry already in the table, the COLLECT statement has the same effect as inserting the new line. If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.
APPEND :
This Statement just appends a line into the table regardless of whether a table entry with same key exists in the table in case of non-unique key of standard or sorted tables. So, Duplicate entries are possible. But, a runtime error occurs if you attempt to add a duplicate entry to a sorted table with a unique key. Equally, a runtime error occurs if you violate the sort order of a sorted table by appending to it.
2008 Jun 24 6:35 AM
Hi Vinay,
append : Append statement just adds the records at the
end of the table.
collect: Collect statement sums up the numeric value fields,
based on the key. Here the key is the combination
of the non numeric fields of the table.
eg.
tab1-
AA 100
AB 200
suppose if we add the following records to that table:
AA 300 and AB 500.
Append gives the result: AA 100
AB 200
AA 300
AB 500
Collect gives the result : AA 400
AB 700
here the key is field1.
Hope this helps you. Any queries, get back to me.
Regards,
Chandra Sekhar
2008 Jun 24 8:02 AM
Hi,
Append Statement Add the New records As The Last Recor At End of the Internal Table.
Basic Function Of Collect Is Like Append, But If the new record
has the same key fields like previously inserted records,then
this statement add the Non-key numeric fields of the first matching record with the newly inserted record.
Only the non-key numeric fields are added.
I Hope it will help you.