Skip to Content

ALV Grid (cl_gui_alv_grid) - Excel InPlace issue - Custom Total/Subtotal Calculations

Hi Experts,

I am having an issue related to the Excel Inplace view within ALV Grid using CL_GUI_ALV_GRID with custom total/subtotal calculations. I have successfully used the event AFTER_REFESH and the methods GET_SUBTOTALS and REFRESH_TABLE_DISPLAY to change the default total value for a percent column. This is working correctly in the default Grid view. But I'm having issues related to the Excel Inplace view. (I had similar issues related to List Output view and print output, but have resolved those.)

The first issue is that the updated total/subtotal values are not passed to the Excel Inplace view and the original total amounts are displayed there. I've confirmed that my code in the AFTER_REFRESH event handler is called and does update the amounts in the subtotal tables after the Excel Inplace view is selected, but the updated total is not reflected in Excel, so the total is obviously recalculated somewhere within the Excel Inplace code. I've debugged extensively and can't find where this is calculated nor how I can override the value. (I found table MT_DATA within method EXECUTE_FCODE of CL_GUI_ALV_GRID that contains a record for each "cell", including the total line, but changing any values there in debug does not accomplish anything.)

The second issue is that when the user returns from the Excel Inplace view to the Grid view, the original total amounts are initially shown there as well, not the custom calculated amounts. If the Refresh button is then selected the total amounts are then updated correctly. I've confirm that my code in the AFTER_REFRESH event handler is called and does update the amounts in the subtotal tables after the Grid view is selected and REFRESH_TABLE_DISPLAY is called, but still the original total amounts are displayed until the user selects Refresh.

Can anyone at least point me in the right direction for either of these two issues? I understand why the first issue happens, I just can't find where/how to update the correct total values. But I'm not clear on why the second issue happens, since my code to calculate the total and my REFRESH_TABLE_DISPLAY are called after the user selects Grid view from the Excel Inplace view, before the Grid view is displayed.

On a much lower priority, I have a question about the issues I've already resolved. Those issues were that the custom total was not reflected in the List Output view of the grid or in the print output. (Just like with the Excel Inplace view.) These issues were resolved by applying the changed values to tables IT_COLLECT## (00-09) in program SAPLKKBL, using field symbols assigned to those tables, within the PRINT_TOP_OF_LIST event of my grid. Is this the right/best solution? I tried to find a way to access these fields using an event, but could not find anything that worked. (I tried to get a pointer to the grid used for the List Output view using function GET_GLOBALS_FROM_SLVC_FULLSCR, with plans to then use method GET_SUBTOTALS to access/update the total tables, but that FM did not return a value when called from within events of my grid.)

Thank you in advance for any help,


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Aug 09, 2016 at 02:09 AM

    I've determined that if I clear CL_GUI_ALV_GRID->M_CL_VARIANT->M_CALCULATE_TOTALS in debug at the point in method CL_GUI_ALV_GRID->EXECUTE_FCODE where event AFTER_USER_COMMAND occurs, that the custom total values are not overwritten by the standard sum, which solves both of my issues. But, I can't figure out how to access and change this field programmatically from within the event handler code for this event. (M_CL_VARIANT is private.)

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 29, 2016 at 06:43 PM

    I thought I should give an update on my original post.

    As for the original issue where the custom total/subtotal amount did not show up in the Excel Inplace view (or when first returning to Grid view from there), I have since determined that this only happens if the parameter I_APPL_EVENTS is set when creating the grid via CREATE OBJECT. If this parameter is not set, which is the default, then Excel Inplace does show the custom calculated total/subtotal amounts.

    Note that regardless of whether I_APPL_EVENTS is not set, the issue happens with the List view and my above noted fix does correct this. I have discovered that the issue also happens for the Export->Local File options (Spreadsheet, Clipboard, etc.), but the above noted Print_Top_Of_List fix also resolves these issues.

    Above I proposed a field that needed to be changed (M_CL_VARIANT->M_CALCULATE_TOTALS) that would resolve the issue for Excel Inplace, but asked for suggestions on how to clear this privat field. User Lukasz suggested a way to change that field, but I wasn't clear on how to apply his suggestion. I developed an alternative way to change this field and this has worked for me. I added code to the AFTER_USER_COMMAND event handler in the calling program such that when e_ucomm is &VEXCEL or &VGRID, that a local field is set to X and exported to memory. Then I implemented an implicit enhancement at the end of method EXECUTE_FCODE in CL_GUI_ALV_GRID that imports this local field and if set, this code clears M_CL_VARIANT->M_CALCULATE_TOTALS, which resolves the issue with the Excel Inplace view (&VEXCEL) and the return to Grid view (&VGRID). Note, this enhancement code also clears the local field and exports back to memory to clear it until set again. This enhancement using import from memory isn't the prettiest solution, but does work. I thought all was good...

    But then I discovered one more place where the custom total/subtotal is replaced by the standard. That is when the user selects Export->Spreadsheet (versus Export->Local File->Spreadsheet). Note that this issue happens regardless of whether or not I_APPL_EVENTS is set, just like the List view and Export->Local File->* options. But the above PTOL code does not fix this issue. I think this also applies to Export->Word processing and possible others. I have not yet found a solution to this issue. I've seen other posts asking about this issue, but no answers. Does anyone have a solution for this?


    Add a comment
    10|10000 characters needed characters exceeded

    • Ray,

      Let's assume you have local class called lcl_grid_trick.

      class lcl_grid_trick definition


      create public .

      public section.

      interfaces if_alv_rm_grid_friend .

      class-methods: clear_calculate_totals importing i_grid type ref to cl_gui_alv_grid.


      class lcl_grid_trick implementation.

      method clear_calculate_totals.

      clear i_grid->m_cl_variant->m_calculate_totals.



      Now you can call method lcl_grid_trick=>clear_calculate_totals( your_grid_object ).

      And it will clear the variable. But I don't know if it will help you as you've already created the enhancement.



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.