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: 

Subtotals in alv-list

Former Member
0 Kudos

I am displaying an alv-list using REUSE_ALV_HIERSEQ_LIST_DISPLAY.

In the list there are two fields which are to be multiplied and shown as a subtotal under one field like as shown below:

field1 field2

1 1

2 2

____________________________________

subtotal: 5(11 + 22)

____________________________________

Can you suggest a way to display subtotals in this manner.

Thanks for your suggestions,

VB

1 REPLY 1

former_member186741
Active Contributor
0 Kudos

have a look at this example:

&----


*& Report ZNRW_ALV_BLOCK *

*& *

&----


*& *

*& *

&----


REPORT ZNRW_ALV_BLOCK .

type-pools: slis.

data : NUM1 type I,

NUM type I.

types:

begin of str,

mat like mara-matnr,

client like mara-mandt,

weight like mara-BRGEW,

end of str.

data

tab type standard table of str.

data :W_EVENT type slis_alv_event ,

tab2 like standard table of W_EVENT,

W_LAYOUT type slis_layout_alv,

W_FCAT type line of slis_t_fieldcat_alv,

tab1 like standard table of W_FCAT.

W_FCAT-reptext_ddic = 'Mat Number'.

W_FCAT-fieldname = 'MAT'.

W_FCAT-tabname = 'TAB'.

W_FCAT-ref_fieldname = 'MATNR'.

W_FCAT-ref_tabname = 'MARA'.

W_FCAT-seltext_l = 'MATERIAL'.

append W_FCAT to tab1.

W_FCAT-reptext_ddic = 'Client Num'.

W_FCAT-fieldname = 'CLIENT'.

W_FCAT-tabname = 'TAB'.

W_FCAT-ref_fieldname = 'MANDT'.

W_FCAT-ref_tabname = 'MARA'.

W_FCAT-seltext_l = 'CLIENT'.

W_FCAT-OUTPUTLEN = 20.

append W_FCAT to tab1.

W_FCAT-reptext_ddic = 'Weight'.

W_FCAT-fieldname = 'WEIGHT'.

W_FCAT-tabname = 'TAB'.

W_FCAT-ref_fieldname = 'BRGEW'.

W_FCAT-ref_tabname = 'MARA'.

W_FCAT-seltext_l = 'weight'.

<b>W_FCAT-DO_SUM = 'X'.</b>

append W_FCAT to tab1.

  • W_LAYOUT-no_colhead = 'X'.

W_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

W_EVENT-FORM = 'WRITE_TOP_PAGE'.

APPEND W_EVENT TO tab2.

NUM = 0.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

I_CALLBACK_PROGRAM = sy-cprog.

DATA tabDREF TYPE REF TO DATA.

FIELD-SYMBOLS <tab> TYPE table.

DATA IT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA X_SORT LIKE LINE OF IT_SORT.

*-To sort internal table based on Field Name

CLEAR X_SORT.

X_SORT-FIELDNAME = 'CLIENT'.

<b>X_SORT-SUBTOT = 'X'.</b>

X_SORT-SPOS = 1.

X_SORT-UP = 'X'.

APPEND X_SORT TO IT_SORT.

do 2 times.

CREATE DATA tabdref TYPE table of str.

ASSIGN tabDREF->* TO <tab>.

NUM1 = NUM1 + 10.

refresh: tab.

select mandt AS CLIENT matnr AS MAT BRGEW AS WEIGHT up to NUM1 rows from

mara into

CORRESPONDING FIELDS OF table <tab>.

W_LAYOUT-SUBTOTALS_TEXT = 'NEILS TOTS which '."any bigger will hide text

W_LAYOUT-TOTALS_TEXT = 'biggy TOTalS'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = W_LAYOUT

IT_FIELDCAT = tab1

IT_SORT = IT_SORT

I_TABNAME = 'TAB'

IT_EVENTS = tab2

TABLES

T_OUTTAB = <tab>.

enddo.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.

FORM WRITE_TOP_PAGE.

NUM = NUM + 1.

WRITE: / ,

/ 'TABLE NUMBER :', NUM.

ENDFORM.