Skip to Content
0
Former Member
Jul 10, 2007 at 06:04 AM

calculating the total in alv and displaying the date

32 Views

Hi,

I am trying to calculate the totals of netwr and fkimg in a report but the following coding cannot giv me the right answer so if there is anyone with the solution for this problem may you please help me out and how can i display the date on my report......here is my coding:

REPORT Z_DAILY_STOCK_NEW.

TYPE-POOLS: SLIS.

----


  • TABLES

----


TABLES: vbrk, kna1,vbrp,vbap,vbak, sflight.

----


  • ALV FIELDS

----


DATA: it_fieldcat TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

wa_fieldcat TYPE slis_fieldcat_alv.

DATA: w_cnt LIKE sy-tabix.

  • total ref to data.

  • t_alv LIKE TABLE OF s_error WITH HEADER LINE.

DATA: gr_layout TYPE slis_layout_alv,

gr_tab_group TYPE slis_t_sp_group_alv,

gr_repid LIKE sy-repid,

gr_events TYPE slis_t_event,

gr_print TYPE slis_print_alv,

gr_user TYPE slis_formname VALUE 'USER_COMMAND'.

----


  • SELECTION SCREEN

----


SELECT-OPTIONS:

s_werks FOR vbrp-werks,

s_auart FOR vbak-auart.

----


  • DEFINITION OF AN INTERNAL TABLE

----


DATA: begin of i_stocktab occurs 0,

kunag LIKE vbrk-kunag,

name1 LIKE kna1-name1,

ort01 LIKE kna1-ort01,

inco1 LIKE vbrk-inco1,

vkgrp LIKE vbrp-vkgrp,

fkimg LIKE vbrp-fkimg,

netwr LIKE vbrk-netwr,

end of i_stocktab.

----


  • START OF SELECTION

----


SELECT vbrkkunag kna1name1 kna1ort01 vbrkinco1 vbrp~vkgrp

vbrpfkimg vbrknetwr

FROM kna1 inner join vbrk on kna1kunnr EQ vbrkkunrg

inner join vbak on kna1kunnr EQ vbakkunnr

inner join vbrp on vbrkvbeln EQ vbrpvbeln

INTO i_stocktab

WHERE vbrp~werks IN s_werks

AND vbak~auart IN s_auart.

APPEND i_stocktab.

ENDSELECT.

*DATA tb_alv TYPE i_stocktab WITH HEADER LINE.

PERFORM build_fieldcatalog.

PERFORM build_layout.

PERFORM build_event.

PERFORM build_print.

PERFORM calc_total.

PERFORM display_alv_report.

&----


FORM build_fieldcatalog.

&----


w_cnt = 1.

it_fieldcat-fieldname = 'KUNAG'.

it_fieldcat-seltext_m = 'Soldtp'.

it_fieldcat-col_pos = w_cnt.

it_fieldcat-emphasize = 'X'.

it_fieldcat-key = 'X'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

w_cnt = w_cnt + 1.

it_fieldcat-fieldname = 'NAME1'.

it_fieldcat-seltext_m = 'Name'.

it_fieldcat-col_pos = w_cnt.

it_fieldcat-emphasize = 'X'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

w_cnt = w_cnt + 1.

it_fieldcat-fieldname = 'ORT01'.

it_fieldcat-seltext_m = 'City'.

it_fieldcat-col_pos = w_cnt.

it_fieldcat-emphasize = 'X'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

w_cnt = w_cnt + 1.

it_fieldcat-fieldname = 'INC01'.

it_fieldcat-seltext_m = 'Incoterms'.

it_fieldcat-col_pos = w_cnt.

it_fieldcat-emphasize = 'X'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

w_cnt = w_cnt + 1.

it_fieldcat-fieldname = 'VKGRP'.

it_fieldcat-seltext_m = 'Sales Group'.

it_fieldcat-col_pos = w_cnt.

it_fieldcat-emphasize = 'X'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

w_cnt = w_cnt + 1.

it_fieldcat-fieldname = 'FKIMG'.

it_fieldcat-seltext_m = 'Invoiced Qty'.

it_fieldcat-col_pos = w_cnt.

it_fieldcat-emphasize = 'X'.

  • *it_fieldcat-do_sum = 'x'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

w_cnt = w_cnt + 1.

it_fieldcat-fieldname = 'NETWR'.

it_fieldcat-seltext_m = 'Invoiced Value'.

it_fieldcat-col_pos = w_cnt.

it_fieldcat-emphasize = 'X'.

  • it_fieldcat-do_sum = 'x'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

ENDFORM.

&----


FORM build_layout.

&----


gr_layout-no_input = 'X'.

gr_layout-colwidth_optimize = 'X'.

gr_layout-totals_text = 'Totals: '(201).

gr_layout-detail_popup = 'X'.

ENDFORM.

&----


FORM build_event.

&----


DATA i_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = gr_events[].

READ TABLE gr_events WITH KEY name = slis_ev_user_command

INTO i_event.

if sy-subrc = 0.

MOVE gr_user TO i_event-form.

APPEND i_event TO gr_events.

endif.

ENDFORM.

&----


*FORM calc_total.

&----


  • LOOP AT it_fieldcat into wa_fieldcat

  • WHERE fieldname EQ 'FKIMG' OR

  • fieldname EQ 'NETWR'.

  • wa_fieldcat-do_sum = 'X'.

  • wa_fieldcat-datatype = 'QUAT'.

  • modify it_fieldcat from wa_fieldcat.

  • ENDLOOP.

*ENDFORM.

FORM build_print.

gr_print-reserve_lines = '2'.

gr_print-no_coverpage = 'X'.

ENDFORM.

----


FORM calc_total.

----


DATA: total type ref to data,

subtotal1 type ref to data.

field-symbols <fkimg> like sflight.

field-symbols <netwr> like sflight.

call method grid1-> get_subtotals

importing

ep_collect00 = subtotal

ep_collect01 = total.

assign total to <fkimg>.

assign total to <netwr>.

ENDFORM.

&----


*& FUNCTION ALV DISPLAY

&----


FORM display_alv_report.

gr_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = gr_repid

I_CALLBACK_USER_COMMAND = slis_ev_user_command

I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE' " see FORM

IS_LAYOUT = gr_layout

IT_FIELDCAT = it_fieldcat[]

IT_SPECIAL_GROUPS = gr_tab_group

I_SAVE = 'X'

IT_EVENTS = gr_events

IS_PRINT = gr_print

TABLES

t_outtab = i_stocktab

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

ENDFORM.

&----


FORM top-of-page.

&----


*ALV Header deaclarations

DATA: t_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader,

t_line LIKE wa_header-info,

ld_lines TYPE i,

ld_linesc TYPE c.

*Title

wa_header-typ = 'H'.

wa_header-info = 'Report for daily Stock Returns'.

APPEND wa_header TO t_header.

CLEAR wa_header.

*Total No. Records Selected

DESCRIBE TABLE i_stocktab LINES ld_lines.

ld_linesc = ld_lines.

CONCATENATE 'Total No. of Records Selected:' ld_linesc

INTO t_line SEPARATED BY space.

wa_header-typ = 'A'.

wa_header-info = t_line.

APPEND wa_header TO t_header.

CLEAR: wa_header, t_line.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header.

ENDFORM.