Skip to Content
avatar image
Former Member

My collect does not work. please help....

Hello experts,

I am wondering what I am doing wrong here. Based on the logic below, I want to write the results of subtotal and grand total based on my collect. But when I run my report it does not work. it does not collect the values. Below is my code:

it_finaltab TYPE STANDARD TABLE OF t_finaltab WITH HEADER LINE,

wa_finaltab type standard table of t_finaltab with header line.

FORM display_results.

SORT it_finaltab BY funcloc asset_dum DESCENDING

asset DESCENDING parent DESCENDING.

*local variables

DATA: lv_color TYPE i VALUE 1,

lv_subtot(1),

lv_total(1),

lv_flag(1),

lv_lines TYPE i,

subtot LIKE anlc-kansw,

total LIKE anlc-kansw,

gtotal LIKE anlc-kansw,

lv_old LIKE iloa-tplnr,

lv_new LIKE iloa-tplnr.

*check number of records in itab

DESCRIBE TABLE it_finaltab LINES lv_lines.

IF lv_lines > 1.

lv_flag = 1.

ENDIF.

*write results

LOOP AT it_finaltab.

COLLECT it_finaltab into wa_finaltab.

AT END OF asset_dum.

lv_subtot = 1.

ENDAT.

AT END OF funcloc.

lv_total = 1.

ENDAT.

lv_new = it_finaltab-funcloc.

IF NOT lv_old IS INITIAL.

IF lv_new <> lv_old.

NEW-PAGE.

FORMAT COLOR COL_HEADING.

WRITE: / sy-uline(sy-linsz) NO-GAP,

sy-vline,

(17) 'Asset' CENTERED,

(17) 'Parent' CENTERED,

(40) 'Description' CENTERED,

(15) 'Asset Sub-class' CENTERED,

(40) 'Location' CENTERED,

(15) 'Cost' CENTERED,

(20) 'Acc. Depreciation' CENTERED,

(20) 'Net Book Value' CENTERED,

sy-vline,

sy-uline(sy-linsz) NO-GAP.

FORMAT COLOR OFF.

ENDIF.

ENDIF.

lv_old = lv_new.

IF lv_color = 1.

lv_color = 2.

ELSE.

lv_color = 1.

ENDIF.

FORMAT INTENSIFIED OFF COLOR = lv_color.

WRITE: / sy-vline,

(17) it_finaltab-asset_subnum CENTERED,

(17) it_finaltab-parent_subnum CENTERED,

(40) it_finaltab-description CENTERED,

(15) it_finaltab-asset_sub CENTERED,

(40) it_finaltab-location CENTERED,

(15) it_finaltab-accq_cost CENTERED,

(20) it_finaltab-acc_dep CENTERED,

(20) it_finaltab-asset_book_val CENTERED,

sy-vline.

  • ADD: it_finaltab-asset_book_val TO subtot,

  • it_finaltab-asset_book_val TO gtotal.

*write subtotal

**if there is only one record in itab, subtotal would not be displayed

IF lv_subtot = 1 AND lv_flag = 1.

CLEAR lv_subtot.

FORMAT COLOR COL_TOTAL.

WRITE: / sy-vline,

'Sub-total:',

AT 137(15) wa_finaltab-accq_cost CENTERED,

AT 153(20) wa_finaltab-acc_dep CENTERED,

AT 174(20) wa_finaltab-asset_book_val CENTERED,

sy-vline.

  • CLEAR subtot.

FORMAT COLOR OFF.

ENDIF.

*write grand total

IF lv_total = 1.

FORMAT COLOR COL_TOTAL INTENSIFIED ON.

WRITE: / sy-uline(sy-linsz),

sy-vline,

'Grand Total:', it_finaltab-funcloc,

AT 137(15) wa_finaltab-accq_cost CENTERED,

AT 153(20) wa_finaltab-acc_dep CENTERED,

AT 174(20) wa_finaltab-asset_book_val CENTERED,

sy-vline,

sy-uline(sy-linsz).

CLEAR gtotal.

FORMAT COLOR OFF.

ENDIF.

ENDLOOP.

ENDFORM.

By the way, I tried using add but it is tedious so I am experementing with collect statement. Again, thank you guys and take care!

Message was edited by: viraylab

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    May 19, 2006 at 04:52 AM

    Hi Viraylab,

    U can refer the following code.

    types: begin of wa_vbap,

    matnr like vbap-matnr,

    uepos like vbap-uepos,

    mvgr1 like vbap-mvgr1,

    mvgr2 like vbap-mvgr2,

    mvgr3 like vbap-mvgr3,

    serail like vbap-serail,

    updkz like vbapvb-updkz,

    kwmeng like vbap-kwmeng,

    end of wa_vbap.

    types: begin of wa_vbapx,

    matnr like vbap-matnr,

    kwmeng like vbap-kwmeng,

    end of wa_vbapx.

    data t_vbap type table of wa_vbapx with header line.

    loop at xvbap.

    move-corresponding xvbap to t_vbap.

    collect t_vbap.

    endloop.

    Reward points if helpful.

    Rgds,

    Sumana

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 19, 2006 at 04:11 AM

    Try using ADD between AT END OF <field> and ENDAT.

    For the collect statemnet to be usefull all the fields BEFORE the numeric fields should be Character fields.

    hope it helps ............ pls award points

    Anirban

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 19, 2006 at 04:02 AM

    The internal table in which u collect,should have

    on the LEFT MOST,only matnr and werks.

    rest the system will automatically sum up based on their distinct combination

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 19, 2006 at 04:07 AM

    'Collect' sums up the numeric values based on all the non-numeric fields. See to it that your internal table has only those fields on which you want to do the sum and the amount fields.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 19, 2006 at 04:51 AM

    Hi Viraylab,

    U can refer the following code.

    types: begin of wa_vbap,

    matnr like vbap-matnr,

    uepos like vbap-uepos,

    mvgr1 like vbap-mvgr1,

    mvgr2 like vbap-mvgr2,

    mvgr3 like vbap-mvgr3,

    serail like vbap-serail,

    updkz like vbapvb-updkz,

    kwmeng like vbap-kwmeng,

    end of wa_vbap.

    types: begin of wa_vbapx,

    matnr like vbap-matnr,

    kwmeng like vbap-kwmeng,

    end of wa_vbapx.

    data t_vbap type table of wa_vbapx with header line.

    loop at xvbap where updkz ne 'D'.

    move-corresponding xvbap to t_vbap.

    collect t_vbap.

    endloop.

    Reward points if helpful.

    Rgds,

    Sumana

    Add comment
    10|10000 characters needed characters exceeded