‎2006 Jan 02 1:53 PM
i have itab with a lot of data that include
material date qty
1233444 20051010 3
3423423 20050901 4
ext....
i need to arrange this data to a new table that look like
material jan feb mar apr ....
12334334 10 20 30 56
in each month i need to calc the qty of the matnr
any idea?
i'm broke.
‎2006 Jan 02 2:42 PM
here is the sample code i have developed,
check this. it will work
****
data : begin of itab1 occurs 0,
matnr like mara-matnr,
ersda like mara-ersda,
quan like mara-ntgew,
end of itab1.
data : begin of itab2 occurs 0,
matnr like mara-matnr,
quan1 like mara-ntgew, "for January
quan2 like mara-ntgew, "for February
*--like this you have to add 12 for 12 months quantity.
end of itab2.
data : v_index like sy-tabix,
v_jan_qty like mara-ntgew,
v_feb_qty like mara-ntgew.
*--like this you have to create 12 variables to store
*--12 months quantity for a particular material.
itab1-matnr = 100.
itab1-ersda = '20050110'.
itab1-quan = 10.
append itab1.
itab1-ersda = '20050212'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050111'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050112'.
itab1-quan = 20.
append itab1.
itab1-matnr = 101.
itab1-ersda = '20050110'.
itab1-quan = 10.
append itab1.
itab1-ersda = '20050112'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050111'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050112'.
itab1-quan = 20.
append itab1.
*--this must be done before loooping itab1.
sort itab1 by matnr ersda.
loop at itab1.
v_index = sy-tabix.
if itab1-ersda+4(2) = '01'.
*--i assume MONTH IS in 5,6th places in Date. change according to your month place. default month location is 5&6th positions in Datum field
*--material quantity in jan
v_jan_qty = v_jan_qty + itab1-quan.
elseif itab1-ersda+4(2) = '02'.
v_feb_qty = v_feb_qty + itab1-quan.
*--here write elseif ..for 03,04, etcc. till 12(december
endif.
at end of matnr.
read table itab1 index v_index.
itab2-matnr = itab1-matnr.
itab2-quan1 = v_jan_qty.
itab2-quan2 = v_feb_qty.
append itab2.
clear : v_jan_qty, v_feb_qty.
endat.
endloop.
loop at itab2.
write :/1(20) itab2-matnr,
22(20) itab2-quan1,
42(20) itab2-quan2.
endloop.
****
this will give output like below
100 50.000 20.000
101 70.000 0.000
added output for the above program
Message was edited by: Srikanth Kidambi Maruthi
added some documentation
Message was edited by: Srikanth Kidambi Maruthi
Message was edited by: Srikanth Kidambi Maruthi
‎2006 Jan 02 1:58 PM
Hi Liat,
can you please let me know how the data will be present in internal table
with little more data..
Thanks
vijay
‎2006 Jan 02 2:19 PM
in the last internal table it will present like this:
matnr jan feb march .....
21354 15 12 12
23132 12 10 10
68475 11 11 15
‎2006 Jan 02 2:02 PM
Hi
U can acheive it using control-break statements (At New At first ...) which is used to calculate sub-total and grand total.
use the keyword documentation
‎2006 Jan 02 2:37 PM
Hi sort the internal table containing data on date field.
now
loop at itab.
at new date.
concatenate data to final interanl tale.
at last.
append the record.
endloop.
satish
‎2006 Jan 02 2:44 PM
‎2006 Jan 02 2:48 PM
this logic will give you,
each material per month.
you can follow my logic, it will give you
for each material how much quantity in each month,irrespective of date in that month.
check this & revert,if you still facing the problem
regards
srikanth
‎2006 Jan 02 2:42 PM
here is the sample code i have developed,
check this. it will work
****
data : begin of itab1 occurs 0,
matnr like mara-matnr,
ersda like mara-ersda,
quan like mara-ntgew,
end of itab1.
data : begin of itab2 occurs 0,
matnr like mara-matnr,
quan1 like mara-ntgew, "for January
quan2 like mara-ntgew, "for February
*--like this you have to add 12 for 12 months quantity.
end of itab2.
data : v_index like sy-tabix,
v_jan_qty like mara-ntgew,
v_feb_qty like mara-ntgew.
*--like this you have to create 12 variables to store
*--12 months quantity for a particular material.
itab1-matnr = 100.
itab1-ersda = '20050110'.
itab1-quan = 10.
append itab1.
itab1-ersda = '20050212'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050111'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050112'.
itab1-quan = 20.
append itab1.
itab1-matnr = 101.
itab1-ersda = '20050110'.
itab1-quan = 10.
append itab1.
itab1-ersda = '20050112'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050111'.
itab1-quan = 20.
append itab1.
itab1-ersda = '20050112'.
itab1-quan = 20.
append itab1.
*--this must be done before loooping itab1.
sort itab1 by matnr ersda.
loop at itab1.
v_index = sy-tabix.
if itab1-ersda+4(2) = '01'.
*--i assume MONTH IS in 5,6th places in Date. change according to your month place. default month location is 5&6th positions in Datum field
*--material quantity in jan
v_jan_qty = v_jan_qty + itab1-quan.
elseif itab1-ersda+4(2) = '02'.
v_feb_qty = v_feb_qty + itab1-quan.
*--here write elseif ..for 03,04, etcc. till 12(december
endif.
at end of matnr.
read table itab1 index v_index.
itab2-matnr = itab1-matnr.
itab2-quan1 = v_jan_qty.
itab2-quan2 = v_feb_qty.
append itab2.
clear : v_jan_qty, v_feb_qty.
endat.
endloop.
loop at itab2.
write :/1(20) itab2-matnr,
22(20) itab2-quan1,
42(20) itab2-quan2.
endloop.
****
this will give output like below
100 50.000 20.000
101 70.000 0.000
added output for the above program
Message was edited by: Srikanth Kidambi Maruthi
added some documentation
Message was edited by: Srikanth Kidambi Maruthi
Message was edited by: Srikanth Kidambi Maruthi
‎2006 Jan 02 2:47 PM