Application Development 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: 

What is a collect statement? How is it different from append?

Former Member
0 Kudos

hi,

What is a collect statement? How is it different from append?

regards.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Simple example :

Collect - when ever non numeric columns equal then it sums numeric value otherwise it works like append statement.

suppose you have internal table :

data : begin of itab occurs 0,

field1(3) type c, " -> Non numeric

field2 type i, " Numeric

end of itab.

itab-field1 = 'ABC'.

itab-field2 = 100.

collect itab.

itab-field1 = 'ABC'.

itab-field2 = 200.

collect itab.

loop at itab.

write:/ itab-field1,itab-field2.

endloop

output is : ABC 300

Since here collect will look at non numeric then it adds numeric columns.

data : begin of itab occurs 0,

field1(3) type c, " -> Non numeric

field2 type i, " Numeric

end of itab.

itab-field1 = 'ABC'.

itab-field2 = 100.

collect itab.

itab-field1 = 'ABD'.

itab-field2 = 200.

collect itab.

loop at itab.

write:/ itab-field1,itab-field2.

endloop

output is : ABC 100

ABD 200

Here it works like Append statement

I hope you got it

Thanks

Seshu

2 REPLIES 2

Sougata
Active Contributor
0 Kudos

Why are you flooding the forum when most of the answers can be found by searching this forum??

It's only a matter of time when the moderators will notice this and probably ban you from posting here permanently.

Former Member
0 Kudos

Simple example :

Collect - when ever non numeric columns equal then it sums numeric value otherwise it works like append statement.

suppose you have internal table :

data : begin of itab occurs 0,

field1(3) type c, " -> Non numeric

field2 type i, " Numeric

end of itab.

itab-field1 = 'ABC'.

itab-field2 = 100.

collect itab.

itab-field1 = 'ABC'.

itab-field2 = 200.

collect itab.

loop at itab.

write:/ itab-field1,itab-field2.

endloop

output is : ABC 300

Since here collect will look at non numeric then it adds numeric columns.

data : begin of itab occurs 0,

field1(3) type c, " -> Non numeric

field2 type i, " Numeric

end of itab.

itab-field1 = 'ABC'.

itab-field2 = 100.

collect itab.

itab-field1 = 'ABD'.

itab-field2 = 200.

collect itab.

loop at itab.

write:/ itab-field1,itab-field2.

endloop

output is : ABC 100

ABD 200

Here it works like Append statement

I hope you got it

Thanks

Seshu