04-21-2009 8:35 AM
Dear Masters,
I need a solution for my problem. I need to modify sorting of subtotal and grand total based on currency which criteria i create myself. The standard alv output sort total by currency based on alpahabetical order, e.g: AUD, EUR, IDR, USD. I need to change the sorting into IDR, USD, AUD, EUR. How can i do it in alv grid?
I also like to add new line after grand total line, which is grand total in Local Currency, in this case, in IDR, which rate given. I can get the figure of subtotal, but i don't know how to append new line after grand total line output in alv standard.
Need your suggestion.
Many thanks,
Tiara
05-11-2009 1:32 PM
Hi,
I have used object oriented ALV. You can remove final total line and have sub total lines. Code below can help you.
1) Fieldcatalog you can do sum for currency values
2) Sort Build you can have sub totals.
3) layout_init you can remove final total line.
4) CALL METHOD grid->set_table_for_first_display you can pass above structure for excepted Result.
*----
fieldcatalog_init
*----
FORM fieldcatalog_init USING lt_fieldcatalog TYPE lvc_t_fcat
value(field_name) value(field_type) value(field_text) value(field_key).
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
CLEAR ls_fieldcatalog.
ls_fieldcatalog-fieldname = field_name.
ls_fieldcatalog-datatype = field_type.
ls_fieldcatalog-reptext = field_text.
ls_fieldcatalog-coltext = field_text.
ls_fieldcatalog-seltext = field_text.
ls_fieldcatalog-tooltip = field_text.
ls_fieldcatalog-key = field_key.
IF field_type = 'CURR'.
ls_fieldcatalog-do_sum = 'X'.
ENDIF.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ENDFORM. "fieldcatalog_init
*----
sort_build
*----
FORM sort_build USING lt_sort TYPE lvc_t_sort.
DATA: ls_sort TYPE lvc_s_sort.
ls_sort-fieldname = 'BUKRS'. "Fieldname on which to sort
ls_sort-subtot = 'X'.
ls_sort-up = 'X'. "Sort Ascending
APPEND ls_sort TO lt_sort.
IF p_comp <> 'X'.
ls_sort-fieldname = 'LIFNR'. "Fieldname on which to sort
ls_sort-subtot = 'X'.
ls_sort-up = 'X'. "Sort Ascending
APPEND ls_sort TO lt_sort.
ENDIF.
ls_sort-fieldname = 'WAERS'. "Fieldname on which to sort
ls_sort-subtot = 'X'.
ls_sort-up = 'X'. "Sort Ascending
APPEND ls_sort TO lt_sort.
ENDFORM. "sort_build
*----
layout_init
*----
FORM layout_init USING ls_layout TYPE lvc_s_layo.
DATA lv_date(10) TYPE c.
WRITE sy-datum TO lv_date.
IF p_line = 'X'.
CONCATENATE 'Line Item wise Report as on' lv_date INTO w_string2 SEPARATED BY space.
ELSEIF p_vend = 'X'.
CONCATENATE 'Vendor Summary Report as on' lv_date INTO w_string2 SEPARATED BY space.
ELSEIF p_comp = 'X'.
CONCATENATE 'Company Summary Report as on' lv_date INTO w_string2 SEPARATED BY space.
ENDIF.
ls_layout-zebra = 'X'.
ls_layout-grid_title = w_string2.
ls_layout-sel_mode = 'A'.
ls_layout-no_merging = 'X'.
ls_layout-cwidth_opt = 'X'.
ls_layout-no_totline = 'X'.
IF p_line = 'X'.
ls_layout-ctab_fname = 'COLINFO'.
ENDIF.
ENDFORM. "layout_init
CALL METHOD grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
is_variant = va_layout "&see below
i_save = 'A' "&see below
i_default = ''
CHANGING
it_outtab = it_apout[]
it_fieldcatalog = gt_fieldcatalog
it_sort = gt_sort.
Edited by: Himanshu Dave on May 11, 2009 2:33 PM