Skip to Content
author's profile photo Former Member
Former Member

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

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 11, 2007 at 05:15 AM

    hi,

    To count the number of records in a report we use DESCRIBE statement.

    DATA: FLD(8),

    LEN TYPE I.

    DESCRIBE FIELD FLD LENGTH LEN.

    Describe for table..This gives you number of rows in the internal table.

    Ex.

    DESCRIBE TABLE ITAB.

    WRITE: / ' Number of rows in ITAB', SY-TFILL.

    u need not sort the table before use of describe.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 11, 2007 at 05:14 AM

    hi,

    To do that use DESCRIBE table statement for your final internal table which gives you the number of records

    here is a sample code how to use it

    DATA: BEGIN OF TAB OCCURS 10,
            X,
          END OF TAB.
    DATA: LIN TYPE P.
    ...
    CLEAR TAB. REFRESH TAB.
    MOVE '?' TO TAB-X.
    APPEND TAB.
    DESCRIBE TABLE TAB LINES LIN.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 11, 2007 at 05:16 AM

    Hi,

    Hi

    Something like this:

    TYPE-POOLS SLIS.

    DATA: FROM_INDEX TYPE I,

    TO_INDEX TYPE I,

    TOT_INDEX TYPE I.

    DATA: MAX_RECORD TYPE I VALUE 500.

    DATA: BEGIN OF ITAB1 OCCURS 0,

    FIELD1,

    FIELD2,

    FIELDN,

    END OF ITAB1.

    DATA ITAB2 LIKE STANDARD TABLE OF ITAB1.

    DATA: GT_REPID TYPE SY-REPID.

    ...................................

    DESCRIBE TABLE ITAB1 LINES TOT_INDEX.

    PERFORM MOVE_FROM_ITAB1_TO_ITAB2 USING '+'.

    GT_REPID = SY-REPID.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = GT_REPID

    I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'

    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

    .........................................

    TABLES

    T_OUTTAB = ITAB2.

    ----


    • FORM set_pf_status *

    ----


    • ........ *

    ----


    • --> RT_EXTAB *

    • --> ENDFORM *

    ----


    FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

    • Here you set your own status gui, you have to copy from std ALV GRID

    • gui and then insert your new buttons

    SET PF-STATUS 'MY_STATUS' EXCLUDING RT_EXTAB.

    ENDFORM.

    ----


    • FORM user_command *

    ----


    • ........ *

    ----


    • --> R_UCOMM *

    • --> RS_SELFIELD *

    ----


    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

    RS_SELFIELD TYPE SLIS_SELFIELD.

    • Here manage your new buttons

    CASE R_UCOMM.

    WHEN 'P-'. "previuos 500 records

    PERFORM MOVE_FROM_ITAB1_TO_ITAB2 USING '-'.

    RS_SELFIELD-REFRESH = 'X'.

    WHEN 'P+'. "Next 500 records

    PERFORM MOVE_FROM_ITAB1_TO_ITAB2 USING '+'.

    RS_SELFIELD-REFRESH = 'X'.

    WHEN 'EXCEL'. "-----> Here download the ITAB1 to Excel file

    ENDCASE.

    ENDFORM.

    &----


    *& Form MOVE_FROM_ITAB1_TO_ITAB2

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM MOVE_FROM_ITAB1_TO_ITAB2 USING P_STEP.

    CASE P_STEP.

    WHEN '+'.

    IF FROM_INDEX = 0.

    • Initialize the counters

    FROM_INDEX = 1.

    IF TOT_INDEX < MAX_RECORD.

    TO_INDEX = TOT_INDEX.

    ELSE.

    TO_INDEX = MAX_RECORD.

    ENDIF.

    ELSE.

    • Set next block of 500 records

    FROM_INDEX = TO_INDEX + 1.

    IF FROM_INDEX > TOT_INDEX.

    FROM_INDEX = TO_INDEX = TOT_INDEX..

    ELSE.

    TO_INDEX = TO_INDEX + MAX_RECORD.

    IF TO_INDEX > TOT_INDEX.

    TO_INDEX = TOT_INDEX.

    ENDIF.

    ENDIF.

    ENDIF.

    WHEN '-'.

    FROM_INDEX = FROM_INDEX - MAX_RECORD.

    IF FROM_INDEX < 0.

    FROM_INDEX = 1.

    ENDIF.

    TO_INDEX = FROM_INDEX + MAX_RECORD - 1.

    IF TO_INDEX > TOT_INDEX. TO_INDEX = TOT_INDEX. ENDIF.

    ENDCASE.

    REFRESH ITAB2.

    APPEND LINES OF ITAB1 FROM FROM_INDEX TO TO_INDEX TO ITAB2.

    ENDFORM. " MOVE_FROM_ITAB1_TO_ITAB2

    check the link:

    https://forums.sdn.sap.com/click.jspa?searchID=3776011&messageID=1920829

    <b>Reward points</b>

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 11, 2007 at 05:17 AM

    You can use <b>DESCRIBE TABLE i_stocktab LINES w_lines</b>.

    Declare a variable <b>w_lines</b> to store the number of records in a table.

    Regards,

    Pavan.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.