Skip to Content
0
Former Member
Jul 11, 2007 at 05:11 AM

calculating the number of records in a report......

14 Views

Hi everyone,

I am trying to display the number of records in a report but i seem to be strugling with i am using alv's, so please anyone who can help i would appreciate that.....here is the sample of my coding:

TYPE-POOLS: SLIS.

----


  • TABLES

----


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

----


  • 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.

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 default 'zson'.

----


  • 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 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 = 'INCO1'.

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-ref_tabname = 'VBRP' .

it_fieldcat-ref_fieldname = 'FKIMG'.

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-ref_tabname = 'VBRK' .

it_fieldcat-ref_fieldname = 'NETWR' .

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 build_print.

----


gr_print-reserve_lines = '2'.

gr_print-no_coverpage = 'X'.

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_HTML_TOP_OF_PAGE = 'HTML_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 html_top_of_page

&----


FORM html_top_of_page USING document TYPE REF TO cl_dd_document.

DATA: text TYPE sdydo_text_element.

CALL METHOD document->add_gap

EXPORTING

width = 100.

text = 'Cadbury: Daily Stock Returns'.

CALL METHOD document->add_text

EXPORTING

text = text

sap_style = 'HEADING'.

CALL METHOD document->new_line.

CALL METHOD document->new_line.

CALL METHOD document->new_line.

text = 'User Name : '.

CALL METHOD document->add_text

EXPORTING

text = text

sap_emphasis = 'Strong'.

CALL METHOD document->add_gap

EXPORTING

width = 6.

text = sy-uname.

CALL METHOD document->add_text

EXPORTING

text = text

sap_style = 'Key'.

CALL METHOD document->add_gap

EXPORTING

width = 50.

text = 'Date : '.

CALL METHOD document->add_text

EXPORTING

text = text

sap_emphasis = 'Strong'.

CALL METHOD document->add_gap

EXPORTING

width = 6.

text = sy-datum.

CALL METHOD document->add_text

EXPORTING

text = text

sap_style = 'Key'.

CALL METHOD document->add_gap

EXPORTING

width = 50.

text = 'Time : '.

CALL METHOD document->add_text

EXPORTING

text = text

sap_emphasis = 'Strong'.

CALL METHOD document->add_gap

EXPORTING

width = 6.

text = sy-uzeit.

CALL METHOD document->add_text

EXPORTING

text = text

sap_style = 'Key'.

ENDFORM.