2009 Jan 28 7:38 PM
Hi,
Below is the code I am trying to get respective totals of cost elements.
but i am getting output as.
51000 120
51000 300
54000 700
54000 100
54000 400
I need following output
51000 420
54000 1200
REPORT YY.
tables: prps.
data: t_prps like prps occurs 0 with header line.
data: t_final like zjob occurs 0 with header line.
types: t_coep type coep.
data: it_coep TYPE STANDARD TABLE OF t_coep.
DATA : wa_coep TYPE t_coep.
DATA : wa1_coep TYPE t_coep.
select-options:
s_pspid for prps-psphi.
select * from PRPS into corresponding fields of table t_prps
where psphi in s_pspid.
***Actual Costs
select * from coep into corresponding fields of table it_coep
for all entries in t_prps
where objnr = t_prps-objnr.
sort it_coep by kstar.
loop at it_coep into wa1_coep.
wa1_coep-wtgbtr = wa1_coep-wtgbtr + wa_coep-wtgbtr .
AT END OF kstar.
ULINE.
WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar .
move wa1_coep-wtgbtr to t_final-CJTDAT.
move wa1_coep-kstar to t_final-kstar.
append t_final.
CLEAR wa1_coep.
SKIP.
ENDAT.
endloop.
loop at t_final.
write:/10 t_final-kstar, 40 t_final-cjtdat.
endloop.
What am i doing wrong?
rgds
vara
2009 Jan 28 7:42 PM
Hi,
Since kstar is not the first field in the internal table it_coep...the AT END OF event will be triggered even if there is any change in the previous columns..Please check the help for details..
to solve this..
1) you can use COLLECT..in which the intenal table should have only cost element and amount columns.
OR
2) change the internal table IT_COEP to have only cost element and amount columns..
Thanks
Naren
2009 Jan 28 7:42 PM
Hi,
Since kstar is not the first field in the internal table it_coep...the AT END OF event will be triggered even if there is any change in the previous columns..Please check the help for details..
to solve this..
1) you can use COLLECT..in which the intenal table should have only cost element and amount columns.
OR
2) change the internal table IT_COEP to have only cost element and amount columns..
Thanks
Naren
2009 Jan 28 7:44 PM
Hi,
loop at it_coep into wa1_coep.
wa_coep-wtgbtr = wa_coep-wtgbtr + wa1_coep-wtgbtr . " Change
AT END OF kstar.
ULINE.
WRITE: / wa_coep-wtgbtr , 30 wa1_coep-kstar . " Change
move wa_coep-wtgbtr to t_final-CJTDAT. " Change
move wa1_coep-kstar to t_final-kstar.
append t_final.
CLEAR : wa1_coep, wa_coep. " Change
SKIP.
ENDAT.
endloop.
2009 Jan 28 7:46 PM
REPORT YY.
tables: prps.
data: t_prps like prps occurs 0 with header line.
data: t_final like zjob occurs 0 with header line.
types: t_coep type coep.
data: it_coep TYPE STANDARD TABLE OF t_coep.
DATA : wa_coep TYPE t_coep.
DATA : wa1_coep TYPE t_coep.
select-options:
s_pspid for prps-psphi.
select * from PRPS into corresponding fields of table t_prps
where psphi in s_pspid.
***Actual Costs
select * from coep into corresponding fields of table it_coep
for all entries in t_prps
where objnr = t_prps-objnr.
sort it_coep by kstar.
CLEAR : l_wtgbt.
loop at it_coep into wa1_coep.
* wa1_coep-wtgbtr = wa1_coep-wtgbtr + wa_coep-wtgbtr . "Wrong use a temporary variable to do the summing
l_wtgbt = l_wtgbtr + wa_coep-wtgbtr/
AT END OF kstar.
ULINE.
WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar .
move l_wtgbtr to t_final-CJTDAT. " line changed
move wa1_coep-kstar to t_final-kstar.
append t_final.
CLEAR: wa1_coep, l_wtgbtr. "line changed
SKIP.
ENDAT.
endloop.
loop at t_final.
write:/10 t_final-kstar, 40 t_final-cjtdat.
endloop.
2009 Jan 28 7:58 PM
Avinash & Vishnu,
I tried both of your codes.. I am still getting same old output.
Narendra,
I followed your second suggestion and chnaged code like below.
Even though I see entries in my internal table.It is displaying zeros..
REPORT YY.
tables: prps.
data: t_prps like prps occurs 0 with header line.
data: t_final like zjob occurs 0 with header line.
*types: t_coep type coep.
types: begin of t_coep ,
kstar like coep-kstar,
wtgbtr like coep-wtgbtr,
end of t_coep.
data: it_coep TYPE STANDARD TABLE OF t_coep.
DATA : wa_coep TYPE t_coep.
DATA : wa1_coep TYPE t_coep.
select-options:
s_pspid for prps-psphi.
select * from PRPS into corresponding fields of table t_prps
where psphi in s_pspid.
***Actual Costs
select kstar wtgbtr from coep into corresponding fields of table it_coep
for all entries in t_prps
where objnr = t_prps-objnr.
loop at it_coep into wa1_coep.
wa1_coep-wtgbtr = wa1_coep-wtgbtr + wa_coep-wtgbtr .
AT END OF kstar.
ULINE.
WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar .
move wa1_coep-wtgbtr to t_final-CJTDAT.
move wa1_coep-kstar to t_final-kstar.
append t_final.
CLEAR wa1_coep.
SKIP.
ENDAT.
endloop.
loop at t_final.
write:/10 t_final-kstar, 40 t_final-cjtdat.
endloop.
Edited by: Vara K on Jan 28, 2009 8:58 PM
2009 Jan 28 8:04 PM
I got it.
I had to change LOOP.
loop at it_coep into wa_coep.
wa1_coep-wtgbtr = wa1_coep-wtgbtr + wa_coep-wtgbtr .
AT END OF kstar.
ULINE.
WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar .
move wa1_coep-wtgbtr to t_final-CJTDAT.
move wa_coep-kstar to t_final-kstar.
append t_final.
CLEAR wa1_coep.
SKIP.
ENDAT.
endloop.
Thank you all..
Rgds
Vara
2009 Jan 28 8:04 PM
Use COLLECT statement, before that you should declare the fields which you want to add as Numeric.
Let me know if you want answer in detail.
mubeen