‎2005 Mar 29 8:58 AM
hey guys,
Can we use collect statement in same internal table?
loop at itab_list.
collect itab_list.
endloop.
is it correct?
ambichan.
‎2005 Mar 29 9:20 AM
> hey guys,
> Can we use collect statement in same internal table?
> loop at itab_list.
> collect itab_list.
> endloop.
> is it correct?
-> no.
try this
DATA itab_collect LIKE itab_list OCCURS 0 WITH HEADER LINE.
loop at itab_list.
collect itab_list into itab_collect.
endloop.
Andreas
‎2005 Mar 29 9:16 AM
Hi Ambi
Here is an official explanation:
<i>"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.
You should only use the COLLECT statement if you want to create summarized tables. If you use other statements to insert table entries, you may end up with duplicate entries."</i>
By the way, do not forget that, all of the non-key fields of your internal table must have a numeric type (F, I, or P).
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>
‎2005 Mar 29 9:20 AM
> hey guys,
> Can we use collect statement in same internal table?
> loop at itab_list.
> collect itab_list.
> endloop.
> is it correct?
-> no.
try this
DATA itab_collect LIKE itab_list OCCURS 0 WITH HEADER LINE.
loop at itab_list.
collect itab_list into itab_collect.
endloop.
Andreas
‎2005 Mar 29 3:27 PM
Yes, you can do this... the question rather is: what do you want to achieve?
Suppose your internal (standard) table contains two entries with the same key where the non-key part is just an integer with value 1 in the first line and value 2 in the second line.
After running your little piece of code on this internal table the non-key part of the first line will be 4 and the second line will stay as is.
By the way: COLLECT should rather be used to fill 'empty' tables for performance reasons.
Tom