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: 

alv

Former Member
0 Kudos

how can we do totals and sub totals in alv?

1 ACCEPTED SOLUTION

S0025444845
Active Participant
0 Kudos

Hi,

take help of the below code.

FORM build_fieldcat CHANGING p_it_fieldcat LIKE it_fieldcat.

DATA : wa_fieldcat TYPE slis_fieldcat_alv,

l_col_pos TYPE i.

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'NETWR'.

wa_fieldcat-ref_fieldname = 'NETWR'.

wa_fieldcat-ref_tabname = 'VBRP'.

wa_fieldcat-cfieldname = 'WAERK'.

wa_fieldcat-do_sum = 'X'.

wa_fieldcat-seltext_l = 'Net Sales Value'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'WAERK'.

wa_fieldcat-ref_fieldname = 'WAERK'.

wa_fieldcat-ref_tabname = 'VBRK'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

  • NEW Andreas Retzlaff

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'WAVWR'.

wa_fieldcat-ref_fieldname = 'WAVWR'.

wa_fieldcat-ref_tabname = 'VBRP'.

wa_fieldcat-cfieldname = 'WAERK'.

wa_fieldcat-do_sum = 'X'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'GMV'.

wa_fieldcat-ref_fieldname = 'WAVWR'.

  • wa_fieldcat-ref_tabname = 'VBRP'.

wa_fieldcat-cfieldname = 'WAERK'.

wa_fieldcat-seltext_s = 'GMV'.

wa_fieldcat-seltext_m = 'GMV'.

wa_fieldcat-seltext_l = 'GMV'.

wa_fieldcat-do_sum = 'X'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

endform.

*////for subtotal

FORM build_sortinfo CHANGING p_it_sortinfo LIKE it_sortinfo.

DATA : wa_sortinfo TYPE slis_sortinfo_alv.

wa_sortinfo-fieldname = 'BUKRS'.

wa_sortinfo-tabname = 'VBRK'.

wa_sortinfo-up = 'X'.

wa_sortinfo-subtot = 'X'.

APPEND wa_sortinfo TO p_it_sortinfo.

wa_sortinfo-fieldname = 'VBELN'.

wa_sortinfo-tabname = 'VBAK'.

wa_sortinfo-up = 'X'.

wa_sortinfo-subtot = 'X'.

APPEND wa_sortinfo TO p_it_sortinfo.

ENDFORM. " build_sortinfo

regards,

sudha

8 REPLIES 8

0 Kudos

same thread.

Former Member
0 Kudos

Hi,

By using Control break statements,

At new

At end of....

and Sum statement.

Regards,

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

In fieldcatalog for that field, do_sum = 'X'.

Message was edited by:

Jayanthi Jayaraman

Former Member
0 Kudos

Hi,

please check out the following link it might help you

http://help.sap.com/saphelp_sm32/helpdata/en/16/7b9938ac52d205e10000009b38f8cf/frameset.htm

************please reward points if the information is helpful to you******************

former_member201227
Active Participant
0 Kudos

Hi,

In the fieldcatalog for the field which you need the total, set the flag for do_sum to 'X'.

fieldcat-do_sum = 'X' and pass the fieldcat to ALV display Function module.

Regards,

Sharmila

Former Member
0 Kudos

hi,

To do totals we have one option in field catalog i.e., do_sum option .

For subtotals we hav one option sub totals only.

S0025444845
Active Participant
0 Kudos

Hi,

take help of the below code.

FORM build_fieldcat CHANGING p_it_fieldcat LIKE it_fieldcat.

DATA : wa_fieldcat TYPE slis_fieldcat_alv,

l_col_pos TYPE i.

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'NETWR'.

wa_fieldcat-ref_fieldname = 'NETWR'.

wa_fieldcat-ref_tabname = 'VBRP'.

wa_fieldcat-cfieldname = 'WAERK'.

wa_fieldcat-do_sum = 'X'.

wa_fieldcat-seltext_l = 'Net Sales Value'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'WAERK'.

wa_fieldcat-ref_fieldname = 'WAERK'.

wa_fieldcat-ref_tabname = 'VBRK'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

  • NEW Andreas Retzlaff

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'WAVWR'.

wa_fieldcat-ref_fieldname = 'WAVWR'.

wa_fieldcat-ref_tabname = 'VBRP'.

wa_fieldcat-cfieldname = 'WAERK'.

wa_fieldcat-do_sum = 'X'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

l_col_pos = l_col_pos + 1.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = 'GMV'.

wa_fieldcat-ref_fieldname = 'WAVWR'.

  • wa_fieldcat-ref_tabname = 'VBRP'.

wa_fieldcat-cfieldname = 'WAERK'.

wa_fieldcat-seltext_s = 'GMV'.

wa_fieldcat-seltext_m = 'GMV'.

wa_fieldcat-seltext_l = 'GMV'.

wa_fieldcat-do_sum = 'X'.

APPEND wa_fieldcat TO p_it_fieldcat.

CLEAR wa_fieldcat.

endform.

*////for subtotal

FORM build_sortinfo CHANGING p_it_sortinfo LIKE it_sortinfo.

DATA : wa_sortinfo TYPE slis_sortinfo_alv.

wa_sortinfo-fieldname = 'BUKRS'.

wa_sortinfo-tabname = 'VBRK'.

wa_sortinfo-up = 'X'.

wa_sortinfo-subtot = 'X'.

APPEND wa_sortinfo TO p_it_sortinfo.

wa_sortinfo-fieldname = 'VBELN'.

wa_sortinfo-tabname = 'VBAK'.

wa_sortinfo-up = 'X'.

wa_sortinfo-subtot = 'X'.

APPEND wa_sortinfo TO p_it_sortinfo.

ENDFORM. " build_sortinfo

regards,

sudha