‎2009 Jul 28 1:46 PM
Hi all
I have two field which is custome number and i want they sum in same line for this i write below code .
and after this i want differece between this two total. so how can i get this.
DEFINE m_sort.
clear lt_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = 'kunrg'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
ls_sort-group = 'X'.
append ls_sort to lt_sort.
clear lt_sort.
it_sort-fieldname = 'kunrg'.
it_sort-up = 'X'.
append ls_sort to lt_sort.
CLEAR lt_sort.
END-OF-DEFINITION.
but i didn't get this field in group and not get sub total so please help me out as soon as possible.. please.
‎2009 Jul 28 2:01 PM
HI,
Please refer the below code for Totals and subtotals.
type-pools : slis.
data: begin of t_itab occurs 0,
kunnr type kunnr,
waers type waers,
dmbtr type dmbtr,
end of t_itab.
data: w_fieldcat type slis_fieldcat_alv,
it_fieldcat type slis_t_fieldcat_alv,
t_sort type slis_t_sortinfo_alv,
w_sort type slis_sortinfo_alv,
w_layout type slis_layout_alv.
t_itab-kunnr = '0001'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '100.00'.
append t_itab.
t_itab-kunnr = '0001'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '200.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '100.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '400.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '300.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '100.00'.
append t_itab.
w_fieldcat-fieldname = 'KUNNR'.
append w_fieldcat to it_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'WAERS'.
append w_fieldcat to it_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'DMBTR'.
w_fieldcat-do_sum = 'X'.
append w_fieldcat to it_fieldcat.
clear w_fieldcat.
*
w_sort-fieldname = 'KUNNR'.
w_sort-up = 'X'.
w_sort-group = '*'.
w_sort-subtot = 'X'.
append w_sort to t_sort.
w_layout-totals_text = 'Grand Total'.
w_layout-subtotals_text = 'Sub total'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
it_sort = t_sort
is_layout = w_layout
TABLES
t_outtab = t_itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
ENDIF.
Regards,
Bhavana
‎2009 Jul 28 1:52 PM
in your field catalog for that field which you want to do the sum. specify do_sum = 'X'
‎2009 Jul 28 2:01 PM
HI,
Please refer the below code for Totals and subtotals.
type-pools : slis.
data: begin of t_itab occurs 0,
kunnr type kunnr,
waers type waers,
dmbtr type dmbtr,
end of t_itab.
data: w_fieldcat type slis_fieldcat_alv,
it_fieldcat type slis_t_fieldcat_alv,
t_sort type slis_t_sortinfo_alv,
w_sort type slis_sortinfo_alv,
w_layout type slis_layout_alv.
t_itab-kunnr = '0001'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '100.00'.
append t_itab.
t_itab-kunnr = '0001'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '200.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '100.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '400.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '300.00'.
append t_itab.
t_itab-kunnr = '0002'.
t_itab-waers = 'USD'.
t_itab-dmbtr = '100.00'.
append t_itab.
w_fieldcat-fieldname = 'KUNNR'.
append w_fieldcat to it_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'WAERS'.
append w_fieldcat to it_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'DMBTR'.
w_fieldcat-do_sum = 'X'.
append w_fieldcat to it_fieldcat.
clear w_fieldcat.
*
w_sort-fieldname = 'KUNNR'.
w_sort-up = 'X'.
w_sort-group = '*'.
w_sort-subtot = 'X'.
append w_sort to t_sort.
w_layout-totals_text = 'Grand Total'.
w_layout-subtotals_text = 'Sub total'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
it_sort = t_sort
is_layout = w_layout
TABLES
t_outtab = t_itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
ENDIF.
Regards,
Bhavana
‎2009 Jul 29 5:35 AM
Hi,
FOR TOTAL:
there is a property of fieldcatalog, that is do_sum.
USE COED LIKE:
PERFORM fieldcat USING:
'1' 'MATNR' 'I_MARD' 'MATERIAL NO' 'MARD' 'MATNR ' ' ',
'2' 'NETWR' 'I_MARD' 'PLANT' 'MARD' 'WERKS' ' ',
..............................
FORM fieldcat USING value(p_0029)
value(p_0030)
value(p_0031)
value(p_0032)
wa_fieldcat-col_pos = p_0029.
wa_fieldcat-fieldname = p_0030.
wa_fieldcat-tabname = p_0031.
wa_fieldcat-reptext = p_0032.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO i_fieldcat.
ENDFORM. " FIELDCAT
in final output you will get the total of currency field.
FOR SUB TOTAL:
decleare: i_sort type standard table of slis_sortinfo_alv,
wa_sort type slis_t_sortinfo_alv.
wa_sort-spos = '1'.
wa_sort-fieldname = 'field1'.
wa_sort-subtot = 'X'.
append wa_tab to i_sort.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
it_sort = i_sort
Hope this can solve your pbs.
Regards,
Tutun