‎2008 Apr 21 11:22 AM
i am having one internal table with following fields
bukrs,werks,kostl,arbpl,aufnr,gjahr,perio,tog001,wogtbr,megbtr
on this with changing of aufnr i need to add only tog001,wogbtr and megbtr
the record is as follows
Company Code Plant Cost.Centre Work.Centre Production.Order Activity .Plan.Price Total.Price Total.Qty Unit.of.measure
1090 2001 10906092 APACKAGE 7007089 145.34 145.34 1.992 HR
1090 2001 10906092 APACKAGE 7007089 277.17 277.17 1.992 HR
1090 2001 10906092 APACKAGE 7007090 121.11 121.11 1.660 HR
1090 2001 10906092 APACKAGE 7007090 230.97 230.97 1.660 HR
1090 2001 10906092 APACKAGE 7007091 102.95 102.95 1.411 HR
1090 2001 10906092 APACKAGE 7007091 196.33 196.33 1.411 HR
and i want the result as follows
Company Code Plant Cost.Centre Work.Centre Production.Order Activity .Plan.Price Total.Price Total.Qty Unit.of.measure
1090 2001 10906092 APACKAGE 7007089 422.51 422.51 3.984 HR
1090 2001 10906092 APACKAGE 7007090 352.08 352.08 3.32 HR
1090 2001 10906092 APACKAGE 7007091 299.28 299.28 2.822 HR
please give the solution.
‎2008 Apr 21 11:25 AM
Instead of appending to the internal table, you could try "collect into" to sum the numeric fields.
Jonathan
‎2008 Apr 21 11:37 AM
Dear Jonathan Coleman,
I dont think that COLLECT can be used..As the break-up will happen only on char fields for a collect...ok...so need to asssign that numeric value to a char for the same.
Reply if u note this..ok?
ullasuv @ yahoo . com
‎2008 Apr 21 11:26 AM
hi Mohan,
Use COLLECT statement ...check out the below link for usage ...
http://help.sap.com/saphelp_nwpi71/helpdata/en/fc/eb36d5358411d1829f0000e829fbfe/frameset.htm
Regards,
Santosh
‎2008 Apr 21 11:26 AM
Hi,
Try this.
On change of AUFNR.
SUM.
ENDON.
Reward if helpful.
Regards,
Ramya
‎2008 Apr 21 11:29 AM
Hi,
while appending the data into the internal table.
use COLLECT statement.
reward if helpful
raam
‎2008 Apr 21 11:34 AM
here i am getting the two price from two different selection and then append that into the final internal table.
so collect not working
‎2008 Apr 21 11:37 AM
The data sources shouldn't matter - why can't you fill a structure with the data from the various sources and "collect lst_my_data into gt_my_data" instead of "append lst_my_data to gt_my_data"?
Jonathan
‎2008 Apr 21 11:38 AM
Hi Mohan,
first u get all the data into one internal table and then u use collect to move the data to final internal table.
here u need to use two internal tables. then it will be easy i think so mohan.
reward if helpful
raam
‎2008 Apr 21 11:45 AM
Hi Mohan,
You can execute another loop on the same internal table and write a logic to add the three required fields until there is a change of AUFNR.
for example:
data: tempfield1 type i, tempfield2 type i, tempfield3 type i.
loop at <internal-table> into <workarea>.
tempfield1 = tempfield1 + workarea-field1.
tempfield2 = tempfield2 + workarea-field2.
tempfield3 = tempfield3 + workarea-field3.
on change of aufnr.
move <tempfields> to <new internaltablefields>.
clear: tempfield1, tempfield2, tempfield3.
endon.
endloop.
reward points if this helps,
Kiran
‎2008 Apr 21 11:52 AM
Perhaps this
DATA:
BEGIN OF my_rec,
bukrs TYPE bukrs,
werks TYPE werks_d,
kostl TYPE kostl,
arbpl(12) TYPE c,
aufnr TYPE aufnr,
gjahr TYPE WRBTR,
* perio type GJAHR,
tog001 TYPE WRBTR,
wogtbr TYPE WRBTR,
megbtr(2) TYPE c,
END OF my_rec,
my_rec_hold LIKE my_rec,
it_tab1 LIKE STANDARD TABLE OF my_rec,
it_tab2 LIKE STANDARD TABLE OF my_rec.
START-OF-SELECTION.
my_rec-bukrs = '1090'.
my_rec-werks = '2010'.
my_rec-kostl = '10906092'.
my_rec-arbpl = 'APACKAGE'.
my_rec-aufnr = '7007089'.
my_rec-gjahr = '145.34'.
my_rec-tog001 = '145.34'.
my_rec-wogtbr = '1.992'.
my_rec-megbtr = 'HR'.
APPEND my_rec TO it_tab1.
my_rec-bukrs = '1090'.
my_rec-werks = '2010'.
my_rec-kostl = '10906092'.
my_rec-arbpl = 'APACKAGE'.
my_rec-aufnr = '7007089'.
my_rec-gjahr = '277.17'.
my_rec-tog001 = '277.17'.
my_rec-wogtbr = '1.992'.
my_rec-megbtr = 'HR'.
APPEND my_rec TO it_tab1.
my_rec-bukrs = '1090'.
my_rec-werks = '2010'.
my_rec-kostl = '10906092'.
my_rec-arbpl = 'APACKAGE'.
my_rec-aufnr = '7007090'.
my_rec-gjahr = '121.11'.
my_rec-tog001 = '121.11'.
my_rec-wogtbr = '1.660'.
my_rec-megbtr = 'HR'.
APPEND my_rec TO it_tab1.
my_rec-bukrs = '1090'.
my_rec-werks = '2010'.
my_rec-kostl = '10906092'.
my_rec-arbpl = 'APACKAGE'.
my_rec-aufnr = '7007090'.
my_rec-gjahr = '230.97'.
my_rec-tog001 = '230.97'.
my_rec-wogtbr = '1.660'.
my_rec-megbtr = 'HR'.
APPEND my_rec TO it_tab1.
my_rec-bukrs = '1090'.
my_rec-werks = '2010'.
my_rec-kostl = '10906092'.
my_rec-arbpl = 'APACKAGE'.
my_rec-aufnr = '7007091'.
my_rec-gjahr = '102.95'.
my_rec-tog001 = '102.95'.
my_rec-wogtbr = '1.411 '.
my_rec-megbtr = 'HR'.
APPEND my_rec TO it_tab1.
my_rec-bukrs = '1090'.
my_rec-werks = '2010'.
my_rec-kostl = '10906092'.
my_rec-arbpl = 'APACKAGE'.
my_rec-aufnr = '7007091'.
my_rec-gjahr = '196.33'.
my_rec-tog001 = '196.33'.
my_rec-wogtbr = '1.411 '.
my_rec-megbtr = 'HR'.
APPEND my_rec TO it_tab1.
CLEAR my_rec_hold.
LOOP AT it_tab1 INTO my_rec.
IF my_rec_hold IS INITIAL.
my_rec_hold = my_rec.
CONTINUE.
ELSE.
IF my_rec_hold-bukrs EQ my_rec-bukrs
AND my_rec_hold-werks EQ my_rec-werks
AND my_rec_hold-kostl EQ my_rec-kostl
AND my_rec_hold-bukrs EQ my_rec-bukrs
AND my_rec_hold-aufnr EQ my_rec-aufnr
AND my_rec_hold-megbtr EQ my_rec-megbtr.
my_rec_hold-gjahr = my_rec_hold-gjahr + my_rec-gjahr.
my_rec_hold-tog001 = my_rec_hold-tog001 + my_rec-tog001.
my_rec_hold-wogtbr = my_rec_hold-wogtbr + my_rec-wogtbr.
ELSE.
APPEND my_rec_hold TO it_tab2.
my_rec_hold = my_rec.
ENDIF.
ENDIF.
ENDLOOP.
APPEND my_rec_hold TO it_tab2.
LOOP AT it_tab2 INTO my_rec.
WRITE:/1 my_rec-bukrs,
6 my_rec-werks,
12 my_rec-kostl,
25 my_rec-arbpl,
40 my_rec-aufnr,
55 my_rec-gjahr,
70 my_rec-tog001,
85 my_rec-wogtbr,
105 my_rec-megbtr.
ENDLOOP.
‎2008 Apr 21 11:44 AM
Dear mohan,
there r 2 ways to achive this..
1. Use Collect. But u cannot use it as easily bcoz in COLLECT the break-up will happen on each char fields. So better u create 1 more field in ur internal table with char20,and assign this aufnr to this char field and can use COLLECT stmt.
2. By keeeping this aufnr and the structure of this internal table so..
At end of aufnr
SUM
wa_new_it-bukrs = wa_it-bukrs.
etc.....
etc....
wa_new_it-aufnr = wa_it-aufnr.
To achive the output;u need to declere 1 more internal table(say new_it and its work area wa_new_it. ). here wa_it is the exiesting internal table u mentioned in ur query.