12-03-2007 5:27 AM
Can anyone tell , me how to get the total of the total number of records displayed in the ALV GRID DISPLAY.??
12-03-2007 5:30 AM
Hi,
Refer this code
&----
*& Form sub_display_data
&----
text
----
FORM sub_display_data .
*--To sort the output through material number
DATA : lwa_sort TYPE slis_sortinfo_alv.
DATA : lit_sort TYPE slis_t_sortinfo_alv.
*--Pass the values to the table
lwa_sort-fieldname = 'PERNR'. "Field name in o/p inttable
lwa_sort-tabname = 'it_final2'. "Output Internal table
lwa_sort-spos = '1'. "Sort sequence
lwa_sort-up = 'X'. "Sort in ascending order
lwa_sort-down = ' '. "Sort in descending order
lwa_sort-subtot = 'X'. "Subtotal
APPEND lwa_sort TO lit_sort.
*--Pass the values to the table
lwa_sort-fieldname = 'WORKDATE'. "Field name in o/p inttable
lwa_sort-tabname = 'it_final2'. "Output Internal table
lwa_sort-spos = '2'. "Sort sequence
lwa_sort-up = 'X'. "Sort in ascending order
lwa_sort-down = ' '. "Sort in descending order
lwa_sort-subtot = ' '. "Subtotal
APPEND lwa_sort TO lit_sort.
*--Pass the values to the table
lwa_sort-fieldname = 'WEKLY'. "Field name in o/p inttable
lwa_sort-tabname = 'it_final2'. "Output Internal table
lwa_sort-spos = '3'. "Sort sequence
lwa_sort-up = 'X'. "Sort in ascending order
lwa_sort-down = ' '. "Sort in descending order
lwa_sort-subtot = ' '. "Subtotal
APPEND lwa_sort TO lit_sort.
wa_layout-colwidth_optimize = 'X'.
IF NOT it_final2[] IS INITIAL.
*--Call the function module to display the ALV report
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = wa_layout
i_callback_program = v_repid
it_fieldcat = it_fieldcat1[]
i_default = c_chk
i_save = c_save
it_sort = lit_sort
TABLES
t_outtab = it_final2
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.
ELSE.
*--Message No data found
MESSAGE i888 WITH text-017.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " sub_display_data
Regards,
Prashant
12-03-2007 5:33 AM
hi,
select the columns which u want to sum up.
use SUM(Sigma) button in the alv grid layout.
Cheers.,
Chandra
Message was edited by:
Chandrasekhar Velpula
12-03-2007 5:34 AM
Hi,
In the Layout Structure put you label in the "TOTALS_TEXT" field.
ie.
data: st_layout like slis_layout_alv.
st_layout-totals_text = 'Total in Lakhs'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING....
is_layout = st_layout...
check with tis code
&----
*& Report ZALV_SUM
*&
&----
*&
*&
&----
REPORT ZNNR_ALV_SUM.
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
*----
TYPES: BEGIN OF t_vbap,
vbeln TYPE vbap-vbeln,
matnr TYPE vbap-matnr,
netwr TYPE vbap-netwr,
waerk TYPE vbap-waerk,
END OF t_vbap.
DATA: it_vbap TYPE STANDARD TABLE OF t_vbap INITIAL SIZE 0,
wa_vbap TYPE t_vbap.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
&----
*& Form BUILD_FIELDCATALOG
&----
Build Fieldcatalog for ALV Report
----
form build_fieldcatalog.
fieldcatalog-fieldname = 'VBELN'.
fieldcatalog-seltext_m = 'Sales Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETWR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-do_sum = 'X'. "Display column total
fieldcatalog-cfieldname = 'WAERK'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'WAERK'.
fieldcatalog-seltext_m = 'Price Curr'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
&----
*& Form BUILD_LAYOUT
&----
Build layout for ALV grid report
----
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
&----
*& Form DISPLAY_ALV_REPORT
&----
Display report using ALV grid
----
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
tables
t_outtab = it_vbap
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.
endform. " DISPLAY_ALV_REPORT
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
form data_retrieval.
select vbeln matnr netwr waerk
up to 50 rows
from vbap
into table it_vbap.
endform. " DATA_RETRIEVAL
Reward if usefull