06-29-2006 10:09 AM
Helloe experts,
I declared 4 of my columns where do_sum = 'X'. Now, the user wants the total to be displayed. How can I do this? again, thank you guys!
06-29-2006 10:15 AM
hi,
try this for alv-list:
data lay type slis_layout_alv.
...
lay-totals_text = 'TOTAL'.
...
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = c_tabname
IS_VARIANT = gs_variant
IS_layout = lay
I_SAVE = x_save
TABLES
T_OUTTAB = gridtab
EXCEPTIONS
OTHERS = 1.
A.
06-29-2006 10:13 AM
Hi
You can indicate the title for total and subtotal in layout structure.
it_layout-totals_text
it_layout-subtotals_text
Max
Message was edited by: max bianchi
06-29-2006 10:14 AM
You will have to activate the subtotal text event. Take a look at the sample program, BCALV.
Regards,
Ravi
06-29-2006 10:15 AM
hi,
try this for alv-list:
data lay type slis_layout_alv.
...
lay-totals_text = 'TOTAL'.
...
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = c_tabname
IS_VARIANT = gs_variant
IS_layout = lay
I_SAVE = x_save
TABLES
T_OUTTAB = gridtab
EXCEPTIONS
OTHERS = 1.
A.
06-29-2006 10:19 AM
Hi guys,
Thanks for the replies. But I need to use GRID not LIST.
06-29-2006 10:22 AM
Hi
The fields it_layout-totals_text, it_layout-subtotals_text should be valid for GRID too.
Max
06-29-2006 10:39 AM
Hi Viray,
In case of Grid totals text and subtotal text will not work. so you have to use cl_gui_alv_grid class , there one event for subtotals. you have to implement that.
check the Demo program <b>BCALV_TEST_GRID_EVENTS</b> there you can see the implementation of event for subtotal text
regards
vijay
06-29-2006 10:48 AM
Hi,
this is how you should do...
CLASS lcl_event_handler DEFINITION DEFERRED.
DATA: dg_events_receiver TYPE REF
TO lcl_event_handler. "event receiver
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
* For Event handling *
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
subtotal_text FOR EVENT subtotal_text
OF cl_gui_alv_grid
IMPORTING es_subtottxt_info
ep_subtot_line
e_event_data.
ENDCLASS. "VERIFY_EVENT_HANDLER DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
* Implementation of event handler method *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD subtotal_text.
PERFORM d0100_event_subtotal_text USING es_subtottxt_info
ep_subtot_line
e_event_data.
ENDMETHOD. "subtotal_text
ENDCLASS. "lcl_event_handler IMPLEMENTATION
*--set event handler
PERFORM set_event_handler.
CALL METHOD dg_grid->set_table_for_first_display
EXPORTING
is_layout = ds_layout
CHANGING
it_outtab = <fs_f>
it_fieldcatalog = dt_alv_cat
it_sort = dt_sort
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE i000 WITH
'Error in calling SET_TABLE_FOR_FIRST_DISPLAY'(026).
ENDIF.
*&---------------------------------------------------------------------*
*& Form set_event_handler
*&---------------------------------------------------------------------*
* event handler
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_event_handler .
CREATE OBJECT dg_events_receiver.
SET HANDLER dg_events_receiver->subtotal_text
FOR dg_grid.
ENDFORM. " set_event_handler
*&---------------------------------------------------------------------*
*& Form d0100_event_subtotal_text
*&---------------------------------------------------------------------*
* To handle subtotal text event
*----------------------------------------------------------------------*
* -->P_ES_SUBTOTTXT_INFO text
* -->P_EP_SUBTOT_LINE text
* -->P_E_EVENT_DATA text
*----------------------------------------------------------------------*
FORM d0100_event_subtotal_text USING
p_es_subtottxt_info TYPE lvc_s_stxt
p_ep_subtot_line TYPE REF TO data
p_e_event_data TYPE REF TO cl_alv_event_data .
FIELD-SYMBOLS: <fs> TYPE ANY.
ASSIGN p_e_event_data->m_data->* TO <fs>.
<fs> = 'TOTAL'(027).
ENDFORM. " d0100_event_subtotal_text
Regards
vijay
06-29-2006 10:15 AM
Hai,
In the layout structure specify the text
l_layout-TOTALS_TEXT = 'total'.
Cheers,
Umasankar
06-29-2006 10:16 AM
Hi Viray
check the following code, it works only for list , incas e of grid it will not give the texts.
report ztest_alv_check message-id zz .
type-pools: slis.
data: x_fieldcat type slis_fieldcat_alv,
it_fieldcat type slis_t_fieldcat_alv,
l_layout type slis_layout_alv,
x_events type slis_alv_event,
it_events type slis_t_event.
data: begin of itab occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
ZMENG like vbap-ZMENG,
end of itab.
select vbeln
posnr
zmeng
from vbap
up to 20 rows
into table itab.
loop at itab.
itab-ZMENG = sy-tabix .
modify itab index sy-tabix.
endloop.
x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-seltext_l = 'VBELN'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.
x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-seltext_l = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 3.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.
x_fieldcat-fieldname = 'ZMENG'.
x_fieldcat-seltext_l = 'ZMENG'.
x_fieldcat-tabname = 'ITAB'.
<b>x_fieldcat-do_sum = 'X'.</b>
x_fieldcat-col_pos = 4.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.
<b>data: sort type slis_sortinfo_alv,
it_sort type SLIS_T_SORTINFO_ALV.
sort-fieldname = 'VBELN'.
sort-up = 'X'.
sort-subtot = 'X'.</b>
APPEND sort to it_sort.
<b> l_layout-TOTALS_TEXT = 'total text'.
l_layout-SUBTOTALS_TEXT = 'subtotal text'.</b>
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = sy-repid
is_layout = l_layout
it_fieldcat = it_fieldcat
it_events = it_events
it_sort = it_sort
tables
t_outtab = itab
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
Regards
vijay