Skip to Content
-3

appropriate use of COLLECT statement

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Feb 21 at 12:13 PM

    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
    Add comment
    10|10000 characters needed characters exceeded

  • Feb 21 at 11:16 AM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 21 at 11:10 AM
    -3

    collect-program.txt

    Sample Program attached.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 22 at 01:30 PM

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

    Add comment
    10|10000 characters needed characters exceeded