2008 Oct 23 10:14 AM
Hi,
I am using ALV grid ( FM type, not object-oriented).
the structure is like this...
NAME | Allocated | Used | Percentage |
I am doing a subtotal based on 'NAME'.
the logic for computing 'Percentage' is ' ( Used - Allocated ) / 100'.
The percentage value on the subtotal should be based on the subtotals of
column 'Allocated' and 'Used'.
But I am getting the total of the percentages in subtotal field of percentage......
I have to highlight the subtotal row also....
Plz suggest.......
Thanks
Akash.
Hi,
I am using ALV grid ( FM type, not object-oriented).
the structure is like this...
NAME | Allocated | Used | Percentage |
I am doing a subtotal based on 'NAME'.
the logic for computing 'Percentage' is ' ( Used - Allocated ) / 100'.
The percentage value on the subtotal should be based on the subtotals of
column 'Allocated' and 'Used'.
But I am getting the total of the percentages in subtotal field of percentage......
I have to highlight the subtotal row also....
Plz suggest.......
Thanks
Akash.
2008 Oct 23 10:18 AM
2008 Oct 23 10:22 AM
To change the subtotal we need to follow certain steps:
we need to get the ALV object form the ALV function module. We can use the FM GET_GLOBALS_FROM_SLVC_FULLSCR to get the Global data of the ALV. From this FM we will get the ALV object.
After getting the ALV object, we need to get the subtotal using the method GET_SUBTOTALS of the ALV object. We will get the first level subtotal using the parameter EP_COLLECT01.
Now, we need to modify the subtotal. Here we need to take help of Field-symbols since the EP_COLLECT01 is reference to data.
We need to refresh the Table display. For this purpose we can use the method REFRESH_TABLE_DISPLAY.
Here is the code snippet which performs all the steps mentioned above:
Code Snippet to change the Subtotal
DATA: lo_grid TYPE REF TO cl_gui_alv_grid.
*
get the global reference
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lo_grid.
*
get the subtotal
DATA: it_01 TYPE REF TO data.
*
CALL METHOD lo_grid->get_subtotals
IMPORTING
ep_collect01 = it_01.
*
change the data
FIELD-SYMBOLS: <ft_tab> TYPE ANY TABLE,
<fs_tab> TYPE ANY,
<ff_field> TYPE ANY.
ASSIGN it_01->* TO <ft_tab>.
*
LOOP AT <ft_tab> ASSIGNING <fs_tab>.
ASSIGN COMPONENT 'PER' OF STRUCTURE <fs_tab> TO <ff_field>.
<ff_field> = '100'.
ENDLOOP.
*
Refresh the table display
CALL METHOD lo_grid->refresh_table_display
EXPORTING
i_soft_refresh = 'X'.
To be able to use the FM GET_GLOBALS_FROM_SLVC_FULLSCR, we need to find a spot in our program which is being called after the ALV's main FM e.g. REUSE_ALV_GRID_DISPLAY. For this purpose, I have implemented the TOP_OF_PAGE event because it will always be called after the FM. In the subroutine for the TOP_OF_PAGE, I used the code snippet to change the Subtotal.
2008 Oct 23 10:45 AM
Hi,
Then you have to do the subtotal manually, i.e. using at end try like this...
LOOP AT it_final_d2 INTO wa_final_d2.
count = count + 1.
value1 = value1 + wa_final_d2-value.
ntgew1 = ntgew1 + wa_final_d2-ntgew.
kwert21 = kwert21 + wa_final_d2-kwert2 .
diff1 = diff1 + wa_final_d2-diff.
value = value + wa_final_d2-value.
ntgew = ntgew + wa_final_d2-ntgew.
kwert2 = kwert2 + wa_final_d2-kwert2 .
diff = diff + wa_final_d2-diff.
IF count = 1.
wa_final-bztxt = wa_final_d2-bztxt.
ELSE.
wa_final-bztxt = ' '.
ENDIF.
wa_final-oa = wa_final_d2-oa.
wa_final-kunnr = wa_final_d2-kunnr.
wa_final-text = wa_final_d2-text.
wa_final-value = wa_final_d2-value.
wa_final-ntgew = wa_final_d2-ntgew.
wa_final-ratio = wa_final_d2-ratio.
wa_final-kwert2 = wa_final_d2-kwert2.
wa_final-diff = wa_final_d2-diff.
wa_final-ratio1 = wa_final_d2-ratio1.
APPEND wa_final TO it_final.
AT END OF bztxt.--->this is the subtotal part
CLEAR count.
wa_final-bztxt = wa_final_d2-bztxt.
wa_final-oa = ' '.
wa_final-kunnr = ' '.
wa_final-text = ' '.
wa_final-value = value.
wa_final-ntgew = ntgew.
wa_final-kwert2 = kwert2.
wa_final-diff = diff.
wa_final-ratio = value / ntgew.
wa_final-ratio1 = diff / ntgew.
wa_final-line_color = 'C400' . "'C300'.
APPEND wa_final TO it_final.
CLEAR : value , ntgew , kwert2 , diff .
CLEAR wa_final-line_color.
ENDAT.
ENDLOOP.
wa_final-bztxt = 'GRAND SUM'.--->if you want grand total
wa_final-oa = ' '.
wa_final-kunnr = ' '.
wa_final-text = ' '.
wa_final-value = value1.
wa_final-ntgew = ntgew1.
wa_final-kwert2 = kwert21.
wa_final-diff = diff1.
wa_final-ratio = value1 / ntgew1.
wa_final-ratio1 = diff1 / ntgew1.
wa_final-line_color = 'C511'.-----> line colour
APPEND wa_final TO it_final.
now to get the particular row i.e. subtotal as coloured you have to use like this:
declare in your final internal table a field line_color(4) TYPE c,
in it_layout pass
it_layout-info_fieldname = 'LINE_COLOR'.
APPEND it_layout.
and in your final internal table fill line_color as shown above
2008 Oct 23 10:49 AM
2008 Nov 03 10:02 AM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |