Skip to Content

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

Report ALV sum of columns at Bottom

Hi Gurus,

I have a report to be created which has columns let it be A,B,C,D,E,F,G.

I need to display the Sum of columns D and E ,F like Sum of colum D= , Sum of Column E = , Sum of column F at the output.

Can I do it in ALV if yes then how?

Please let me know the path forward.

Tags:
Former Member
Former Member replied

use of Layout and TOTALS_TEXT option it is possible.

There are some more changes to your code, Don't mention fieldnames and internal table names in small case. use Uppercase. and Don't give wrong Internal table names. During preview time they create short dumps.

TYPE-POOLS: slis.
DATA: int_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv,
i_repid LIKE sy-repid,
it_sortcat TYPE STANDARD TABLE OF slis_sortinfo_alv ,
wa_sort TYPE slis_sortinfo_alv.
data: layout type slis_layout_alv.

TYPES: BEGIN OF ty_final,
field1(5) TYPE c,
field2(10) TYPE c,
field3(10) TYPE c,
field4(10) TYPE c,
END OF ty_final.

DATA: it_final TYPE STANDARD TABLE OF ty_final,
it_final1 TYPE STANDARD TABLE OF ty_final.

DATA: wa_final TYPE ty_final.

wa_final-field1 = 'A'.
wa_final-field2 = 10.
wa_final-field3 = 10.
wa_final-field4 = 10.
APPEND wa_final TO it_final.
CLEAR: wa_final.

wa_final-field1 = 'B'.
wa_final-field2 = 20.
wa_final-field3 = 20.
wa_final-field4 = 20.
APPEND wa_final TO it_final.
CLEAR: wa_final.

wa_final-field1 = 'C'.
wa_final-field2 = 30.
wa_final-field3 = 30.
wa_final-field4 = 30.
APPEND wa_final TO it_final.
CLEAR: wa_final.

DATA: lv_tabname TYPE slis_tabname VALUE 'IT_FINAL'.

wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'FIELD1'.
wa_fcat-seltext_l = 'Primary'.

APPEND wa_fcat TO int_fcat.

wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'FIELD2'.
wa_fcat-seltext_l = 'First'.
wa_fcat-inttype = 'I'.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO int_fcat.

wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'FIELD3'.
wa_fcat-seltext_l = 'Second'.
wa_fcat-do_sum(1) = 'X'.
wa_fcat-inttype = 'I'.
APPEND wa_fcat TO int_fcat.

wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'FIELD4'.
wa_fcat-seltext_l = 'Third'.
wa_fcat-do_sum(1) = 'X'.
wa_fcat-inttype = 'I'.
APPEND wa_fcat TO int_fcat.


wa_sort-spos = 1.
wa_sort-fieldname = 'FIELD2'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sortcat.

wa_sort-spos = 2.
wa_sort-fieldname = 'FIELD3'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sortcat.

layout-totals_text = 'This is My Total'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    i_callback_program = i_repid
    is_layout          = layout
    it_fieldcat        = int_fcat[]
    it_sort            = it_sortcat[]
    i_save             = 'X'
  TABLES
    t_outtab           = it_final
  EXCEPTIONS
    program_error      = 1
    OTHERS             = 2.
IF sy-subrc NE 0.

  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question