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: 

Changing Subtotal and total in cl_gui_alv_grid

Former Member
0 Kudos

Hello,

I'm having trouble changing the subtotal of the ALV but the total has changed.

Is this class used only to change the totals?

PBO

CREATE OBJECT container

       EXPORTING

         container_name = 'CUSTOM'.

     "create the splitter control

     CREATE OBJECT splitter

       EXPORTING

         parent        = container

         orientation   = 0

         sash_position = 15."bar location

     CREATE OBJECT splitter2

       EXPORTING

         parent        = splitter->bottom_right_container

         orientation   = 1

         sash_position = 12."bar location

     CREATE OBJECT grid1

       EXPORTING

         i_parent = splitter2->bottom_right_container.

     CALL METHOD grid1->set_table_for_first_display

       EXPORTING

         is_layout            = wa_layout2

         it_toolbar_excluding = lt_exclude

       CHANGING

         it_sort              = it_sort2

         it_outtab            = lt_disp[]

         it_fieldcatalog      = it_fieldcat2.

     CREATE OBJECT tree1

       EXPORTING

         i_parent         = splitter2->top_left_container

         i_no_html_header = 'X'

         i_no_toolbar     = 'X'.

     PERFORM f_register_events.

     CALL METHOD tree1->set_table_for_first_display

       CHANGING

         it_sort         = it_sort

         it_outtab       = it_report2[]

         it_fieldcatalog = it_fieldcat3.

     CREATE OBJECT doc.

     PERFORM f_fill_top_of_page.

     CREATE OBJECT event_receiver.

     SET HANDLER event_receiver->handle_top_of_page FOR grid1.

*    SET HANDLER event_receiver->handle_toolbar FOR grid1.

*    CALL METHOD grid1->set_toolbar_interactive.

     PERFORM f_total.

Form f_total.

DATA: total TYPE REF TO data,

    subtotal1 TYPE REF TO data.

   FIELD-SYMBOLS: <total> LIKE lt_disp,

                  <subtotal1> LIKE lt_disp,

                  <wa> TYPE t_report2.

   CALL METHOD grid1->get_subtotals

     IMPORTING

       ep_collect00 = total

       ep_collect01 = subtotal1.

   ASSIGN total->* TO <total>.

   ASSIGN subtotal1->* TO <subtotal1>.

   LOOP AT <subtotal1> ASSIGNING <wa>.

     TRY.

         <wa>-varabper = ( <wa>-c_m_varab / <wa>-c_m_bud ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-varalper = ( <wa>-c_m_varal / <wa>-c_m_ly ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-ytdabper = ( <wa>-ytd_varab / <wa>-ytd_bud ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-ytdalper = ( <wa>-ytd_varal / <wa>-ytd_ly ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-fyabper = ( <wa>-fy_varcb / <wa>-fy_bud ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-fyalper = ( <wa>-fy_varcl / <wa>-fy_ly ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

   ENDLOOP.

   LOOP AT <total> ASSIGNING <wa>.

     TRY.

         <wa>-varabper = ( <wa>-c_m_varab / <wa>-c_m_bud ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-varalper = ( <wa>-c_m_varal / <wa>-c_m_ly ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-ytdabper = ( <wa>-ytd_varab / <wa>-ytd_bud ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-ytdalper = ( <wa>-ytd_varal / <wa>-ytd_ly ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-fyabper = ( <wa>-fy_varcb / <wa>-fy_bud ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

     TRY.

         <wa>-fyalper = ( <wa>-fy_varcl / <wa>-fy_ly ) * 100.

       CATCH cx_sy_zerodivide.

     ENDTRY.

   ENDLOOP.

* Refresh the table display

   CALL METHOD grid1->refresh_table_display

     EXPORTING

       i_soft_refresh = 'X'.

endform.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Solved.

Had to use collect02. I missed the sorting.

2 REPLIES 2

Former Member
0 Kudos

Solved.

Had to use collect02. I missed the sorting.

raymond_giuseppi
Active Contributor
0 Kudos

You have to call your form f_total each and every time the ALV grid is displayed.

For this manage event "after_refresh" and in this event call your form.

Note that the call of "refresh_table_display" will trigger another "after_refresh". To prevent an infinite loop, define a flag in global data, in the form, check at begin of form, if flag already set, clear it and exit the form, else set this flag just before calling "refresh_table_display" .

Also if user is allowed to maintain variant, you cannot anticipate the number of subtotals, so manage every level (or disable some options of ALV menu)

Regards,

Raymond