cancel
Showing results for 
Search instead for 
Did you mean: 

ALV EXCEL custom template

Former Member
0 Kudos

Hi all SDNs,

I'm trying to do the following:

in a report I use FM REUSE_ALV_GRID_DISPLAY to display a table with char and numeric fields like this:

aaa 12 4 33%

bbb 20 5 25%

As you can see there is a column with percentage value. I want to summarize all the column but (obviously) the percentage column reach an incorrect value.

I try with excel custom template including a bit of VB to create the total line but I don't know where to put my code in the excel template.

Can u help me?

Thanks

Stefano

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Stefano,

When you say <i>summarize</i> do you mean <b>average</b> or <b>sum</b> ?

Can you give us an example like the following or something like if this is the input, then the output should be like this?


 ---------------------------------
|COLA  |  COLB  |  COLC  |  COLD  |
 ---------------------------------
| aaa  |   12   |   4    |  33    |
| bbb  |   20   |   5    |  25    |
 ---------------------------------
| Total    32       9       58    |
----------------------------------

Use [code ] and <b>[/code ]</b> for arranging your table in the above manner without the space before the end bracket <b>]</b>. If you do not use the above tags, table would appear distorted.

Regards,

Subramanian V.

Former Member
0 Kudos

Hi,

thank you for reply, here is the answer.


 ---------------------------------
|COLA  |  COLB  |  COLC  |  COLD  |
 ---------------------------------
| aaa  |   12   |   4    |  33%   |
| bbb  |   20   |   5    |  25%   |
 ---------------------------------
| Total    32       9       28%   |
----------------------------------

this mean that 9 is the 28% of 32.

Hope this is explaining.

Hi again and a happy new year!

Stefano

Former Member
0 Kudos

The question looks pretty neat.

I do not think this is possible with ALV. However you can manually calculate and place this as the last row of the internal table and change the color of this row.


data: sum_cola type i,
      sum_colb type i,
      percentage_col_d type p,
      n type i.

clear sum_cola.
clear sum_colb.
clear percentage_col_d.
clear n.

loop at itab into wa_itab.
   sum_colb = sum_colb + wa_itab-colb.
   sum_colc = sum_colc + wa_itab-colc.
endloop.
percentage_col_d = sum_colc * 100 / sum_colb .
wa_itab-colb = sum_cola.
wa_itab-colc = sum_colb.
wa_itab-cold = percentage_col_d.
append wa_itab to i_itab.

There are two attributes in layout -

<b>info_fieldname</b>

<b>coltab_fieldname </b>

which you can use for displaying a coloured row.

Regards,

Subramanian V.

Former Member
0 Kudos

Dear Subramanian,

probably there was a misunderstanding. I already know that the functionality described previously is not possible with ALV, but I'm sure that it is possible with Excel to create a total line with a Formula in the field 'COL_D'.

I want to do this in excel to keep the possibility of summarization by the user in ALV, and to get a total line as requested in the Excel export file.

To do this I think that I have to put some code in the Excel template (to read the table's number of line and put the total line in the correct row of the excel sheet) but I don't know where exactly the code should be putted. In the Library documentation of ALV list SAP talk about these "template modifications" but how to make the modifications in the excel template is not explained!

Hope you can help me!

thank you again,

Stefano