Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

Tags:
replied

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

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question