04-11-2009 11:21 AM
Hi all,
I have a requirement regarding data processing in a internal table,
internal table consists of filelds Vendor,Material and Scheduling Dates and Total Qty.
Here i need to fill the field Total Quantity, individual addition of quanties of that material for a particular vendor .
Let us consider intitially my internal table consists of data like this with these fields.
Vendor , Material , qty(individual), Total qty , Schedule dates
v1 , m1 , 10
v1 , m1 , 10
v1 , m1 , 20
v1 , m2 , 5
v1 , m2 , 10
v2 , m2 , 20
v2 , m2 , 15
v2 , m3 , 20
v2 , m3 , 10
Initiall the total qty field is empty i need to fill tht field for the last item for a particular material Like M1
for vendor v1 and total qty of m2 for vendor v1, total qty of m1 for v2, total qty of m2 for v2 and so on.
Requied output should be like this.
Vendor , Material , qty(individual) Total qty Schedule dates
v1 , m1 , 10 , 0
v1 , m1 , 10 , 0
v1 , m1 , 20 , 40(101020)
v1 , m2 , 5 , 0
v1 , m2 , 10 , 15(5+10)
v2 , m2 , 20 , 0
v2 , m2 , 15 , 35(20+15)
v2 , m3 , 20 , 0
v2 , m3 , 10 , 30(20+10)
Here i made one thing , i calculated the total qty of material for particular vendor.
Like
Vendor Material Total Qty
v1 , m1 , 40
v1 , m2 , 15
v2 , m2 , 35
v2 , m3 , 30
Finally i need the logic by using Control Events(At New , At End of ) to adjust that total qty of a material for a particular vendor by Modifying the internal table.
i hope my problem is clear , pls let me know if any clarifications needed. and
code for the same .
Thannks in advance,
Niranjan.
04-11-2009 11:33 AM
Use this code!
data: total type i.
loop at itab. " itab is assumed to be with header.
total = total + itab-quantity. " adding quantities
at end of material. " triggerred when material or vender ends (about to change)
itab2-total = total.
modify itab. "Modify the internal table
clear total.
endat.
endloop.
Delete itab where quantity = ' '.
So you get the entries like you mentioned.
If you want to retain the previous internal table also then copy internal table first and then manipulate.
Regards,
Lalit Mohan Gupta.
04-11-2009 11:33 AM
Use this code!
data: total type i.
loop at itab. " itab is assumed to be with header.
total = total + itab-quantity. " adding quantities
at end of material. " triggerred when material or vender ends (about to change)
itab2-total = total.
modify itab. "Modify the internal table
clear total.
endat.
endloop.
Delete itab where quantity = ' '.
So you get the entries like you mentioned.
If you want to retain the previous internal table also then copy internal table first and then manipulate.
Regards,
Lalit Mohan Gupta.
04-11-2009 11:36 AM
For control processing statements check this link
[Control processing|http://help.sap.com/saphelp_nw70/helpdata/EN/9f/db9f1f35c111d1829f0000e829fbfe/content.htm]
Regards,
Lalit Mohan Gupta.
04-11-2009 12:28 PM
Hi,
Solution is here.
sort itab by vendor material.
field-symbols: <itab> like line of itab.
loop at itab assigning <itab>.
on change of vendor.
clear flag.
endon.
add <itab>-quanity to lw_quantiy.
*--here pdate internal table end of each similar kind of record
at end of.
flag = 'x'.
<itab>-totalqty = lw_quantiy.
clear lw_quantiy
endat.
*--rest of record update zero by checking flag
if flag is initial.
<itab>-totalqty = 0.
endif.
endloop.
close this thread if you got solution.
Regards,
Peranandam