Skip to Content
-3

appropriate use of COLLECT statement

Feb 21 at 11:09 AM

67

avatar image

I have one internal table in it we have Account number, and for one account number we have multiple document numbers with different amounts respectively. In the current program only account number and sum of all document number's amount is getting displayed through COLLECT statement but now user wants document number and respective amount in the ALV as well. So I feel now COLLECT statement will not work. Total should be displayed in the new line, suppose 5 document numbers are there then total should be displayed at the 6th line. I tried one test program and fetched data from SFLIGHT table but my total is coming in at the top of the table.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Raymond Giuseppi
Feb 21 at 12:13 PM
2

If you are using ALV, don't use COLLECT, just fill the internal table at document level, sort by account number, declare amount as sum, define account level for subtotal. (If you add a sum record to the table, it will carry an initial document number so will be sorted by default before the records with a document number)

If you are using CL_SALV_TABLE (hopefully) use:

  • cl_salv_aggregations (table->get_aggregations, methods: opt clean, add_aggregation) to sum a column
  • cl_salv_sorts (table->get_sorts, clean, add_sort) to sort and define sub totals
Share
10 |10000 characters needed characters left characters exceeded
Nic Teunckens Feb 21 at 11:16 AM
1

Why not just look into SAP Help Documentation on COLLECT : link

Share
10 |10000 characters needed characters left characters exceeded
Sumit Kumar Feb 21 at 11:10 AM
-3

collect-program.txt

Sample Program attached.


Show 1 Share
10 |10000 characters needed characters left characters exceeded

Could you please provide a code which compiles! (declaring lw_test twice leads to a syntax error)

0
Iftah Peretz
Feb 22 at 01:30 PM
0

I do second Raymond's answer. Nonetheless, I recently came across this. Maybe it can be of use to you.

Share
10 |10000 characters needed characters left characters exceeded