2008 Apr 09 6:12 AM
Hi frds
I have 12 month amount field in itab for different WBS element .
i want sum all the 12 month amount for all WBS element ,wants to pass it to a variable as one value.
can anyone give me sample coding for these or give some tips.
Thanks
Pari
Hi frds
I have 12 month amount field in itab for different WBS element .
i want sum all the 12 month amount for all WBS element ,wants to pass it to a variable as one value.
can anyone give me sample coding for these or give some tips.
Thanks
Pari
2008 Apr 09 6:17 AM
Hi,
do like this.
loop at itab.
total = total + itab-amount.
endloop.
rgds,
bharat.
2008 Apr 09 6:21 AM
HI Bharat.
This is my coding ,ur statement well work for these .
kindly tell me....
DATA: BEGIN OF ICOSP OCCURS 0,
OBJNR LIKE COSP-OBJNR,
GJAHR LIKE COSP-GJAHR,
WRTTP LIKE COSP-WRTTP,
BEKNZ LIKE COSP-BEKNZ,
WTG001 LIKE COSP-WTG001,
WTG002 LIKE COSP-WTG002,
WTG003 LIKE COSP-WTG003,
WTG004 LIKE COSP-WTG004,
WTG005 LIKE COSP-WTG005,
WTG006 LIKE COSP-WTG006,
WTG007 LIKE COSP-WTG007,
WTG008 LIKE COSP-WTG008,
WTG009 LIKE COSP-WTG009,
WTG010 LIKE COSP-WTG010,
WTG011 LIKE COSP-WTG011,
WTG012 LIKE COSP-WTG012,
WTG013 LIKE COSP-WTG013,
WTG014 LIKE COSP-WTG014,
WTG015 LIKE COSP-WTG015,
WTG016 LIKE COSP-WTG016,
END OF ICOSP.
SELECT OBJNR GJAHR WRTTP BEKNZ WTG001 WTG002 WTG003 WTG004 WTG005 WTG006 WTG007
WTG008 WTG009 WTG010 WTG011
WTG012 WTG013 WTG014 WTG015
WTG016 FROM COSP INTO TABLE ICOSP
WHERE OBJNR = PRPS-OBJNR
AND WRTTP = '1'.
Pls correct my mistake,if any..
Thanks
Pari
2008 Apr 09 6:28 AM
Hi,
write like this.
SELECT * FROM COSP INTO CORRESPONDING FIELDS OF TABLE ICOSP
WHERE OBJNR = PRPS-OBJNR
AND WRTTP = '1'.
LOOP AT icosp.
total = total + icosp-wtg001 + icosp-wtg002 + ... + icosp-wtg016.
ENDLOOP.
rgds,
bharat.
2008 Apr 09 6:42 AM
Try Like this,
DATA: BEGIN OF icosp OCCURS 0,
objnr LIKE cosp-objnr,
gjahr LIKE cosp-gjahr,
wrttp LIKE cosp-wrttp,
beknz LIKE cosp-beknz,
wtg001 LIKE cosp-wtg001,
wtg002 LIKE cosp-wtg002,
wtg003 LIKE cosp-wtg003,
wtg004 LIKE cosp-wtg004,
wtg005 LIKE cosp-wtg005,
wtg006 LIKE cosp-wtg006,
wtg007 LIKE cosp-wtg007,
wtg008 LIKE cosp-wtg008,
wtg009 LIKE cosp-wtg009,
wtg010 LIKE cosp-wtg010,
wtg011 LIKE cosp-wtg011,
wtg012 LIKE cosp-wtg012,
wtg013 LIKE cosp-wtg013,
wtg014 LIKE cosp-wtg014,
wtg015 LIKE cosp-wtg015,
wtg016 LIKE cosp-wtg016,
sum TYPE currency ,
END OF icosp.
SELECT objnr gjahr wrttp beknz wtg001 wtg002 wtg003 wtg004 wtg005 wtg006 wtg007
wtg008 wtg009 wtg010 wtg011
wtg012 wtg013 wtg014 wtg015
wtg016 FROM cosp INTO CORRESPONDING FIELDS OF TABLE icosp
.
LOOP AT icosp.
icosp-sum = icosp-wtg001 + icosp-wtg002 + icosp-wtg003 + .... + icosp-wtg016.
MODIFY icosp.
ENDLOOP.
in in your ITAB the field sum contains the sum of amounts.
2008 Apr 09 6:19 AM
You may use this command
COLLECT
Syntax
COLLECT wa INTO itab [result].
Effect
This statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key. As of Release 6.10, you can use result to set a reference to the inserted or changed row in form of a field symbol or data reference.
Prerequisite for the use of this statement is that wa is compatible with the row type of itab. The row type must be flat and all components that are not part of the table key must have a numeric data type ( i, p, f).
If the internal table does not already contain a row with an identical key, the COLLECT statement has the same effect as the following form of the INSERT statement:
INSERT wa INTO TABLE itab [result].
A row, whose position depends on the table key and the table type, is inserted and filled with the contents of wa.
If the internal table already contains one or more rows with an identical key, those values of the components of work area wa that are not part of the key, are added to the corresponding components of the uppermost existing row (in the case of index tables, this is the row with the lowest table index).
The COLLECT statement sets sy-tabix to the table index of the inserted or existing row, in the case of standard tables and sorted tables, and to the value 0 in the case of hashed tables.
Note
Outside of classes, you can omit wa INTO if the internal table has an identically-named header line itab. The statement then implicitly uses the header line as the work area.
Example
Compressed insertion of data from the database table sflight into the internal table seats_tab. The rows in which the key components carrid and connid are identical are compressed by adding the number of occupied seats to the numeric component seatsocc.
DATA: BEGIN OF seats,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
seatsocc TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE HASHED TABLE OF seats
WITH UNIQUE KEY carrid connid.
SELECT carrid connid seatsocc
FROM sflight
INTO seats.
COLLECT seats INTO seats_tab.
ENDSELECT.
do reward if helpful
2008 Apr 09 6:20 AM
hi...
from wat i hav understud from ur qn.....de ans i can giv u is dis
include 1 more field in ur int. table for storing the sum amt.
loop at that itab, and in the work area , for each WBS element u can sum up de amts for 12 months using de arithmetic operator and den assign it to ur new field for storin the sum value.
i think dis will help u out
Reward pts if useful
Regards
Winnie