Skip to Content
0
Jul 30, 2012 at 08:58 AM

Cannot get total text in ALV grid

31 Views

Hi all,

Anyone knows how to get total text for alv output? Right now all the codes I found on the web does not seems to work. Can only display green dot at the total row. Attached is the output and code. The alv event seems not to be calling the subtotal_text form. Anyone have any idea? Thanks.




REPORT ZNSC_GRANDTOTAL_TEXT_ALV.


TYPE-POOLS:SLIS,

truxs.


TYPES:BEGIN OF TY_SBOOK,

CARRID TYPE S_CARR_ID,

LUGGWEIGHT TYPE S_LUGWEIGH,

LOCCURAM TYPE S_L_CUR_PR,

END OF TY_SBOOK.





TYPES:BEGIN OF TY_FINAL,

total type char20,

CARRID TYPE S_CARR_ID,

LUGGWEIGHT TYPE S_LUGWEIGH,

LOCCURAM TYPE S_L_CUR_PR,

COLOR TYPE SLIS_T_SPECIALCOL_ALV,

END OF TY_FINAL.



TYPES:TT_SBOOK TYPE STANDARD TABLE OF TY_SBOOK,

TT_FINAL TYPE STANDARD TABLE OF TY_FINAL.



DATA:IT_SBOOK TYPE TT_SBOOK,

IT_FINAL TYPE TT_FINAL.



DATA:FS_SBOOK TYPE TY_SBOOK,

FS_FINAL TYPE TY_FINAL.



DATA:IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,

FS_FCAT LIKE LINE OF IT_FCAT.



DATA:IT_SORT TYPE SLIS_T_SORTINFO_ALV,

FS_SORT LIKE LINE OF IT_SORT.



DATA:SUB_TEXT TYPE slis_subtot_text.

DATA:IT_TOOLBAR TYPE SLIS_T_EXTAB,

FS_TOOLBAR LIKE LINE OF IT_TOOLBAR.



DATA FS_LAYOUT TYPE SLIS_LAYOUT_ALV.



DATA:IT_EVENT TYPE SLIS_T_EVENT,

FS_EVENT LIKE LINE OF IT_EVENT.

DATA FS_SCOL TYPE SLIS_SPECIALCOL_ALV.

DATA ls_listhead TYPE ty_final.

DATA ls_subtotal TYPE slis_subtot_text.



FS_EVENT-NAME = 'SUBTOTAL_TEXT'.

FS_EVENT-FORM = 'ZSUBTOT'.

APPEND FS_EVENT TO IT_EVENT.

CLEAR FS_EVENT.



fs_layout-no_totalline = 'X'.

fs_layout-subtotals_text = 'Sub Total'.

fs_layout-totals_text = 'Grand Total'.



perform fill_fcat using '0' 'TOTAL' '' 'Grand Total' 'X' 'X'.

PERFORM FILL_FCAT USING '1' 'CARRID' 'Carried ID' SPACE 'X' SPACE.

* PERFORM FILL_FCAT USING '1' 'EBELN1' 'PURCHASE.DOC' SPACE SPACE.

PERFORM FILL_FCAT USING '2' 'LUGGWEIGHT' 'LUGGAGE WEIGHT' 'X' SPACE SPACE.





PERFORM FILL_FCAT USING '3' 'LOCCURAM' 'AMOUNT' 'X' SPACE SPACE.





SELECT CARRID

LUGGWEIGHT

LOCCURAM

FROM SBOOK

INTO TABLE IT_SBOOK

UP TO 5 ROWS

WHERE CARRID EQ 'AA'.





LOOP AT IT_SBOOK INTO FS_SBOOK.

fs_final-TOTAL = 'Grand Total'.

FS_FINAL-CARRID = FS_SBOOK-CARRID.

FS_FINAL-LUGGWEIGHT = FS_SBOOK-LUGGWEIGHT.

FS_FINAL-LOCCURAM = FS_SBOOK-LOCCURAM.



APPEND FS_FINAL TO IT_FINAL.

CLEAR FS_FINAL.

ENDLOOP.



FS_SORT-SPOS = '00'.

FS_SORT-FIELDNAME = 'TOTAL'.

FS_sort-up = 'X'.

FS_SORT-SUBTOT = 'X'.

APPEND FS_SORT TO IT_SORT.

CLEAR FS_SORT.



FS_SORT-SPOS = '01'.

FS_SORT-FIELDNAME = 'LUGGWEIGHT'.

FS_sort-up = 'X'.

FS_SORT-SUBTOT = 'X'.

APPEND FS_SORT TO IT_SORT.

CLEAR FS_SORT.



FS_TOOLBAR-FCODE = '&ALL'.

APPEND FS_TOOLBAR TO IT_TOOLBAR.

FS_LAYOUT-COLTAB_FIELDNAME = 'COLOR'.



PERFORM zsubtot USING ls_listhead ls_subtotal.



LOOP AT IT_FINAL INTO FS_FINAL.

* IF FS_FINAL-FIELDNAME = 'TOTAL'.

FS_SCOL-FIELDNAME = 'TOTAL'.

FS_SCOL-COLOR-COL = 5.

FS_SCOL-COLOR-inv = 1.

FS_SCOL-COLOR-int = 0.

modify it_final from fs_final transporting color.

* ENDIF.

ENDLOOP.



CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-CPROG

IS_LAYOUT = fs_layout

IT_FIELDCAT = IT_FCAT

IT_EXCLUDING = IT_TOOLBAR

IT_SORT = IT_SORT

IT_EVENTS = IT_EVENT

TABLES

t_outtab = IT_FINAL.





form FILL_FCAT using COL_POS FIELDNAME SELTEXT_M DO_SUM NO_OUT TECH.

fs_fcat-col_pos = col_pos.

fs_fcat-fieldname = fieldname.

fs_fcat-seltext_m = seltext_m.

fs_fcat-do_sum = do_sum.

FS_FCAT-NO_OUT = NO_OUT.

fs_fcat-tech = tech.

append fs_fcat to it_fcat.

Clear fs_fcat.

endform. " FILL_FCAT



FORM ZSUBTOT USING i_listhead STRUCTURE FS_FINAL

i_subtotal TYPE slis_subtot_text.

CONSTANTS: c_formname_subtotal_text TYPE slis_formname VALUE 'SUBTOTAL_TEXT'.





DATA ls_event TYPE slis_alv_event.

DATA ls_lineinfo TYPE slis_lineinfo.



CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 4

IMPORTING

et_events = it_event

EXCEPTIONS

list_type_wrong = 1

OTHERS = 2.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.



READ TABLE it_event INTO ls_event WITH KEY name = slis_ev_subtotal_text.

IF sy-subrc = 0.

MOVE c_formname_subtotal_text TO ls_event-form.

MODIFY it_event FROM ls_event INDEX sy-tabix.

ENDIF.





* PERFORM subtotal_text CHANGING ls_subtotal.



ENDFORM.



FORM subtotal_text CHANGING

p_total TYPE any

p_subtot_text TYPE slis_subtot_text.



* Material level sub total

IF p_subtot_text-criteria = 'LUGGWEIGHT'.

p_subtot_text-display_text_for_subtotal

= 'total weight'(009).

ENDIF.

* * Plant level sub total

IF p_subtot_text-criteria = 'LOCCURAM'.

p_subtot_text-display_text_for_subtotal = 'total amount'(010).

ENDIF.



ENDFORM. "subtotal_text

Attachments

alv total text.jpg (38.8 kB)