‎2008 Aug 14 7:10 AM
Hi friends,
My itab contains ........
Sl No Mat No Net Weight Quantity price
1 900018 15.2 1 15000
2 900018 15.2 1 15000
Finally,My itab should contain .......
Sl No Mat No Net Weight Quantity price
1 900018 30.4 2 30000
How to add Net Weight - QUAN
Quantity - QUAN
Price - CURR fields.........
loop at itab.
at end of matnr.
endat.
endloop.
Pls help me.......
‎2008 Aug 14 7:16 AM
Hi,
declare ur itab fields as a charatcer excepet quantity .
and then in loop .
loop at itab.
onchage of matnr.
sum.
endon.
endloop.
thanks,
satish.
‎2008 Aug 14 7:18 AM
Hi
Use COLLECT statement your issuse will be resolved.
Regards
Pavan
‎2008 Aug 14 7:18 AM
‎2008 Aug 14 7:18 AM
Hi,
declare variables of respective type...
and do as following
loop at itab.
v_net_weigh = v_net_weight + net_weight.
v_price = v_price + price.
at end of matnr.
move v_net to wa_fianl-net_weight,
v_price to wa_final-price.
append wa_final to i_final.
clear v_net_weight,
v_price.
endat.
endloop.
‎2008 Aug 14 7:19 AM
Hosmath,
Do it like following :
data : itab1 like itab.
sort itab by s_no matnr.
loop at itab.
g_sum = g_sum + itab-qty.
g_sum1 = g_sum1 + itab-price.
g_sum2 = g_sum2 + itab-wt.
at end of matnr.
read table itab index sy-tabix.
move corresponding itab to itab1.
itab1-qty = g_sum.
itab1-price = g_sum1.
itab1-wt = g_sum2.
append itab1.
clear: itab,g_sum,g_sum1,g_sum2.
endat.
endloop.
Regards,
Talwinder
‎2008 Aug 14 7:20 AM
Hi Hosmath,
Why dont you try the statement Collect.
Collect statement will resolve your problem...
Regards,
Chidanand
‎2008 Aug 14 7:21 AM
hi,
use the collect statement
it is used to add all numeric fields when new record appered.
declare another internal table itab2 like same what u have
loop at itab into wa.
collect wa into itab2.
endloop.
if u have any issues refer this link
http://help.sap.com/saphelp_nw04/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
Regards,
jagadeesh.
‎2008 Aug 14 7:33 AM
loop at itab into wa_itab.
v_quantity = wa_itab + v_quantity.
at end of matnr.
wa_itab_total-quantity = v_quantity.
append wa_itab_total to itab2.
clear: wa_itab_total,v_quantity.
endat.
endloop.
‎2008 Aug 14 8:17 AM
Hi,
You can use COLLECT statement. You can reference the following code.
TYPES:
BEGIN OF ty_original,
si_no(1) TYPE c,
mat_no(6) TYPE c,
weig TYPE KTMNG,"Data Type QUAN
qty TYPE KTMNG,
price TYPE BPREI,"Data Type CURR
END OF ty_original,
BEGIN OF ty_new,
mat_no(6) TYPE c,
weig TYPE KTMNG,"Data Type QUAN
qty TYPE KTMNG,
price TYPE BPREI,"Data Type CURR
END OF ty_new.
TYPES:
ty_tb_original TYPE STANDARD TABLE OF ty_original,
ty_tb_new TYPE STANDARD TABLE OF ty_new WITH KEY mat_no.
DATA:
* original internal table
i_original TYPE ty_tb_original,
w_original TYPE ty_original,
* new internal table used to sum
i_new TYPE ty_tb_new,
w_new TYPE ty_new.
*data in orignial table
w_original-si_no = '1'.
w_original-mat_no = '900018'.
w_original-weig = '15.2'.
w_original-qty = '1'.
w_original-price = '15000'.
APPEND w_original TO i_original.
CLEAR w_original.
w_original-si_no = '2'.
w_original-mat_no = '900018'.
w_original-weig = '15.2'.
w_original-qty = '1'.
w_original-price = '15000'.
APPEND w_original TO i_original.
CLEAR w_original.
*Do Sum
LOOP AT i_original INTO w_original.
w_new-mat_no = w_original-mat_no.
w_new-weig = w_original-weig.
w_new-qty = w_original-qty.
w_new-price = w_original-price.
COLLECT w_new INTO i_new.
CLEAR w_new.
ENDLOOP.
*Display Result.
LOOP AT i_new INTO w_new.
WRITE: w_new-mat_no, w_new-weig, w_new-qty, w_new-price.
ENDLOOP.
‎2008 Aug 14 9:09 AM
Hi friends,
Now I'm able to get the sum .......................
DATA:itab TYPE TABLE OF j_1iexcdtl INITIAL SIZE 0 WITH HEADER LINE.
DATA:v_net_weight TYPE p DECIMALS 2,
v_gross_weight TYPE p DECIMALS 2,
v_menge(2),
v_price TYPE p DECIMALS 2,
v_exbed TYPE p DECIMALS 2,
v_exaddtax1 TYPE p DECIMALS 2,
v_ecs TYPE p DECIMALS 2.
LOOP AT itab.
v_net_weight = v_net_weight + itab-ntgew.
v_gross_weight = v_gross_weight + itab-brgew.
v_menge = v_menge + itab-menge.
v_price = v_price + itab-exbas.
v_exbed = v_exbed + itab-exbed.
v_exaddtax1 = v_exaddtax1 + itab-exaddtax1.
v_ecs = v_ecs + itab-ecs.
AT END OF matnr.
itab-ntgew = v_net_weight.
itab-brgew = v_gross_weight.
itab-menge = v_menge.
itab-exbas = v_price.
itab-exbed = v_exbed.
itab-exaddtax1 = v_exaddtax1.
itab-ecs = v_ecs.
MODIFY itab TRANSPORTING ntgew brgew menge exbas exbed exaddtax1 ecs.
ENDAT.
ENDLOOP.
Getting the correct total values at the last.....
like
if i have 5 same material nos.....getting for the 5th item.....
How to delete previous 4 same material nos from itab.
I'm not displaying the output.....condensing the data within itab(when see it debugg mode).Finally itab should contain one line which is last line in this case.
I need to transfer the contents of this table.....to other table which is dependent on this.