Skip to Content
author's profile photo Former Member
Former Member

How to do subtotalling when using CL_GUI_ALV_GRID Class?

I am using CL_GUI_ALV_GRID Class in a report. In this report, I have to generate a summary report where the report has to look summarized based on four fields viz. G/L Account, Profit Center, Plant, Material Group as per mentioned in the given order of heirarchy. The subtotalling has to be done on the amount field(WRBTR).

Can someone please let me know, as how can this be done? Do let me know, if you require any other information from my side.

Thanks & Regards,

Ravi

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2007 at 06:13 AM

    Hi,

    go to SLIS and then search for subtotal field and make it as 'X' for the field you want to get the subtotal similarly for the total also

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2007 at 06:14 AM

    check if this is helpful.

    PERFORM f007_set_aggregations USING lr_aggregations

    'D5_LCL'.

    &----


    *& Form f007_set_aggregations

    &----


    • Function to calculate the subtotals

    ----


    FORM f007_set_aggregations USING ir_aggregations TYPE REF TO cl_salv_aggregations

    lw_col TYPE any.

    constants: lc_1 type SALV_DE_AGGREGATION value '1'.

    TRY.

    ir_aggregations->set_numerical_aggregation( abap_true ).

    TRY.

    ir_aggregations->add_aggregation(

    columnname = lw_col

    aggregation = lc_1 ).

    CATCH cx_salv_data_error cx_salv_existing cx_salv_not_found.

    MESSAGE i023(salv_exception).

    CATCH cx_salv_method_not_supported.

    MESSAGE i028(salv_exception) WITH space space space space.

    ENDTRY.

    CATCH cx_salv_method_not_supported.

    MESSAGE i028(salv_exception) WITH space space space space.

    ENDTRY.

    ENDFORM. "f007_set_aggregations

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2007 at 07:13 AM

    Hi,

    Can someone please provide a direction?

    Its kindda urgent!!

    Regards,

    Ravi

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

        CALL METHOD o_alvgrid->set_table_for_first_display
           EXPORTING
             is_variant                    = w_variant
             i_save                        = c_a
      *    I_DEFAULT                     = 'X'
             is_layout                     = p_layout
      *    IS_PRINT                      =
             it_special_groups             = p_groups[]
             it_toolbar_excluding          = p_exclude[]
      *    IT_HYPERLINK                  =
      *    IT_ALV_GRAPHICS               =
      *    IT_EXCEPT_QINFO               =
          CHANGING
             it_outtab                     = p_output[]
             it_fieldcatalog               = p_fieldcat[]
            IT_SORT                       = it_sort
      *    IT_FILTER                     =
          EXCEPTIONS
             invalid_parameter_combination = 1
             program_error                 = 2
             too_many_lines                = 3
             OTHERS                        = 4.
      
      f8000_sortcat_init CHANGING it_sort TYPE LVC_S_SORT.
        CLEAR wa_sortinfo.
        wa_sortinfo-fieldname = 'RMATNR'.
        wa_sortinfo-tabname = 'I_OUTTAB'.
        wa_sortinfo-spos = 2.   " First sort by this field.
        wa_sortinfo-up = 'X'.    "   Ascending
        wa_sortinfo-subtot = 'X'.    " Subtotal at Name1
        APPEND wa_sortinfo TO it_sort.
      
        CLEAR wa_sortinfo.
        wa_sortinfo-fieldname = 'CPUDT'.
        wa_sortinfo-tabname = 'I_OUTTAB'
        wa_sortinfo-spos = 1.   " First sort by this field.
        wa_sortinfo-up = 'X'.            "   Ascending
        wa_sortinfo-subtot = 'X'.        " Subtotal at Name1
        APPEND wa_sortinfo TO it_sort.

      Please refer the structure LVC*SORT I have takedn teh code form SLIS.

      If you do so you can get the subtotal.

      Also make sure that you have to enable to SUM = 'X' for the particular field in fieldcatalog.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2007 at 07:35 AM

    Hi Ravi,

    I've used the following code to toal the no. of entries based on field MSGRP.

    V_DIV = 'DEP_TOT'.

    SORT ITABMEL1 BY SWERK MSGRP .

    LOOP AT ITABMEL1 WHERE SWERK NE V_DIV

    IDX = IDX1 + 1.

    AT END OF MSGRP.

    GRANDTOTAL = GRANDTOTAL + 1.

    IF DIV <> ITABMEL1-MSGRP.

    DIV = ITABMEL1-MSGRP.

    CLEAR ITABMEL1.

    ITABMEL1-DIV = DIV.

    ITABMEL1-SWERK = 'DEP_TOT'.

    ITABMEL1-MSGRP = COUNT.

    CLEAR COUNT.

    IDX1 = IDX + 1.

    INSERT ITABMEL1 INDEX IDX1.

    ELSE.

    CLEAR ITABMEL1.

    COUNT1 = COUNT + 1.

    DELETE ITABMEL1 INDEX IDX1.

    ITABMEL1-SWERK = 'DEP_TOT'.

    ITABMEL1-MSGRP = COUNT1.

    CLEAR COUNT1.

    IDX2 = IDX.

    INSERT ITABMEL1 INDEX IDX2.

    IDX1 = IDX2.

    ENDIF.

    ENDAT.

    COUNT = COUNT + 1.

    DIV = ITABMEL1-MSGRP.

    ITABMEL1-DIV = DIV.

    MODIFY ITABMEL1.

    ENDLOOP.

    Hope this helps.

    Reward if helpful.

    Regards,

    Sipra

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.