Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

My subtotal and totals(in ALV) does not work...

Hello experts,

It seems that subtotals and totals that I declared is not working. My logic for subtotal is that for every group(records are grouped by asset_dum field) it will do a subtotal and at the end of the records it will give total. Anyway, here is my code for ALV:

TYPES: BEGIN OF t_finaltab,

asset_dum LIKE iloa-anlnr,

asset LIKE iloa-anlnr,

parent LIKE iloa-anlnr,

accq_cost LIKE anlc-kansw,

acc_dep LIKE anlc-kansw,

anlc_val LIKE anlc-kansw,

anlp_val LIKE anlc-kansw,

asset_book_val LIKE anlc-kansw,

location LIKE t499s-ktext,

description LIKE iflo-pltxt,

END OF t_finaltab.

data: it_finaltab type standard table t_finaltab with header line.

FORM display_alv.

SORT it_finaltab BY asset_dum asset parent.

PERFORM f_build_comment USING gt_list_top_of_page[].

PERFORM f_build_layout USING gs_layout.

PERFORM f_init_fieldcat USING gt_fieldcat[].

PERFORM f_init_events USING 'TOP' gt_events[].

  • PERFORM f_init_fieldsum USING gt_fieldsum[].

PERFORM f_init_events USING 'SUM' gt_events_sum[].

PERFORM f_init_sort USING gt_sort[].

  • PERFORM f_init_sort_del USING gt_sort_del[]. "AVH - 04/04/06

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

i_callback_program = g_repid

i_callback_user_command = 'USER_COMMAND'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

it_fieldcat = gt_fieldcat[]

is_layout = gs_layout

i_tabname = 'IT_FINALTAB'

it_events = gt_events[]

it_sort = gt_sort

i_text = '1ST'

TABLES

t_outtab = it_finaltab.

gt_print-reserve_lines = 2.

gt_print-no_coverpage = 'X'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

EXPORTING

is_print = gt_print.

ENDFORM. " DISPLAY_ALV

----


  • FORM f_build_comment *

----


  • ........ *

----


  • --> %TOP_OF_PAGE *

----


FORM f_build_comment USING %top_of_page TYPE slis_t_listheader.

DATA: ls_line TYPE slis_listheader,

d_name(60),

lv_date(10),

lv_time(10),

lc_dttm(50).

**-REPORT NAME

CLEAR: d_name, ls_line.

MOVE: sy-title TO d_name.

ls_line-typ = 'H'.

ls_line-info = d_name.

APPEND ls_line TO %top_of_page.

**-USER ID AND DATE/TIME

CLEAR: d_name, ls_line.

CONCATENATE: 'Generated by:' sy-uname INTO d_name SEPARATED BY space.

ls_line-typ = 'H'.

ls_line-info = d_name.

APPEND ls_line TO %top_of_page.

CLEAR: d_name, ls_line.

WRITE: sy-datum TO lv_date MM/DD/YYYY,

sy-uzeit TO lv_time USING EDIT MASK '__:__:__'.

CONCATENATE: 'Generated on:' lv_date lv_time

INTO d_name SEPARATED BY space.

ls_line-typ = 'H'.

ls_line-info = d_name.

APPEND ls_line TO %top_of_page.

ENDFORM. " F_BUILD_COMMENT

----


  • FORM f_build_layout *

----


  • ........ *

----


  • --> %LAYOUT *

----


FORM f_build_layout USING %layout TYPE slis_layout_alv.

%layout-detail_popup = 'X'.

%layout-zebra = 'X'.

%layout-totals_text = 'Total'.

ENDFORM. " F_BUILD_LAYOUT

----


  • FORM f_init_fieldcat *

----


  • ........ *

----


  • --> %FIELDCAT *

----


FORM f_init_fieldcat USING %fieldcat TYPE slis_t_fieldcat_alv.

DATA: lc_fieldcat TYPE slis_fieldcat_alv.

CLEAR lc_fieldcat.

DEFINE m_field.

add 1 to lc_fieldcat-col_pos.

lc_fieldcat-fieldname = &1.

lc_fieldcat-outputlen = &2.

lc_fieldcat-seltext_l = &3.

lc_fieldcat-do_sum = &4.

lc_fieldcat-inttype = &5.

lc_fieldcat-hotspot = &6.

lc_fieldcat-fix_column = &7.

lc_fieldcat-ddictxt = 'L'.

lc_fieldcat-no_zero = 'X'.

append lc_fieldcat to %fieldcat.

END-OF-DEFINITION.

m_field 'ASSET' '12' 'Asset' '' '' '' '' .

m_field 'PARENT' '12' 'Parent' '' '' '' '' .

m_field 'DESCRIPTION' '40' 'Description' '' '' '' '' .

m_field 'LOCATION' '40' 'Location' '' '' '' '' .

m_field 'ASSET_BOOK_VAL' '20' 'Net Book Value' 'X' 'X' '' ''.

ENDFORM. " f_init_fieldcat

----


  • FORM f_init_events *

----


  • ........ *

----


  • --> P_TYPE *

  • --> %EVENTS *

----


FORM f_init_events USING p_type CHANGING %events TYPE slis_t_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = %events

EXCEPTIONS

list_type_wrong = 1

OTHERS = 2.

IF sy-subrc = 0.

PERFORM f_build_events USING: slis_ev_user_command.

IF p_type = 'TOP'.

PERFORM f_build_events USING: gc_top.

ELSEIF p_type = 'SUM'.

PERFORM f_build_events_sum USING: gc_topsum.

ENDIF.

ELSE.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " F_INIT_EVENTS

----


  • FORM f_build_events *

----


  • ........ *

----


  • --> %EVENT *

----


FORM f_build_events USING %event.

READ TABLE gt_events WITH KEY name = %event.

IF sy-subrc = 0.

MOVE: %event TO gt_events-form.

  • MOVE 'USER_COMMAND' TO gt_events-form.

MODIFY gt_events INDEX sy-tabix.

ENDIF.

ENDFORM. " F_BUILD_EVENTS

----


  • FORM top_of_page *

----


  • ........ *

----


FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = gt_list_top_of_page.

ENDFORM.

----


  • FORM f_init_sort *

----


  • ........ *

----


  • --> %SORT *

----


FORM f_init_sort USING %sort TYPE slis_t_sortinfo_alv.

DATA: gs_sort TYPE slis_sortinfo_alv.

CLEAR gs_sort.

gs_sort-fieldname = 'ASSET_DUM'.

gs_sort-group = 'UL'.

APPEND gs_sort TO %sort.

ENDFORM. " F_INIT_SORT

----


  • FORM f_build_events_sum *

----


  • ........ *

----


  • --> %EVENT *

----


FORM f_build_events_sum USING %event.

READ TABLE gt_events_sum WITH KEY name = %event.

IF sy-subrc = 0.

MOVE: %event TO gt_events_sum-form.

  • MOVE 'USER_COMMAND' TO gt_events-form.

MODIFY gt_events_sum INDEX sy-tabix.

ENDIF.

ENDFORM. " F_BUILD_EVENTS

Tags:
Not what you were looking for? View more on this topic or Ask a question