Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Report ALV sum of columns at Bottom

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

GauthamV
Active Contributor
0 Kudos

hi,

use do_sum field in ur fieldcatelog.

fieldcatelog-do_sum = 'X'.

16 REPLIES 16

Former Member
0 Kudos

Hi

For the Field D, E and F in the intenal table

itab_fieldcatalog-do_sum = 'X'. for the field in D, E and F internal table.

Regards

MD

GauthamV
Active Contributor
0 Kudos

hi,

use do_sum field in ur fieldcatelog.

fieldcatelog-do_sum = 'X'.

Former Member
0 Kudos

Hi,

I need to display like this.

A B C D

-


1 100 200 300

2 100 200 300

3 100 200 300

-


Sum 300 600 900

Former Member
0 Kudos

Dear Avi,

use do_sum with X while building the filed catalog for all three columns, it will solve your problem.

Rajneesh Gupta

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

This message was moderated.

0 Kudos

Modifed Version..

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.

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 = 2.
wa_sort-fieldname = 'FIELD2'.
wa_sort-tabname = 'IT_OUTPUT'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sortcat.

wa_sort-spos = 3.
wa_sort-fieldname = 'FIELD3'.
wa_sort-tabname = 'IT_OUTPUT'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sortcat.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_callback_program = i_repid
    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.

Former Member
0 Kudos

Hi Vijay,

Thanks a lot.

Can I write 'Sum' at the bottom!!

Sum 60 60 60

0 Kudos

This Option working only in Normal List and it is not working in ALV GRID function.

Former Member
0 Kudos

Hi Vijay,

Can u please let me know how can we do it in List display?

On the same example

GauthamV
Active Contributor
0 Kudos

hi,

use this link.

[https://forums.sdn.sap.com/rss/rssmessages.jspa?threadID=1033110]

[http://help.sap.com/saphelp_nw04/helpdata/en/ee/c8e056d52611d2b468006094192fe3/frameset.htm]

Edited by: gautham chakraverthi on Sep 22, 2008 12:48 PM

0 Kudos

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.

Former Member
0 Kudos

Avi,

Refer the standard program BCALV_EDIT_01

Regards

Indu

Former Member
0 Kudos

Hi,

Check the links

Regards,

Anirban

former_member181995
Active Contributor
0 Kudos
wa_fieldcat-ref_fieldname = 'DMBTR'.
  wa_fieldcat-ref_tabname = 'BSIK'.
  wa_fieldcat1-do_sum(1) = 'X'.

Former Member
0 Kudos

Hi,

Check out this link.

[http://saptechnical.com/Tutorials/ALV/Subtotals/Define.htm]

Regards,

Amit.