2008 Dec 03 6:35 AM
Hi Experts,
Please guide me on how the following:
I have created a Ztable into which i want to upload the Stock in a summary format i.e.
i have got the above values in an internal table. now i want to insert the sum of results into another internal table.
*PLANT MATERIAL BATCH STORAGE QUANTITY MONTH_END_DATE*
0001 ABC-001 12345 RM 500 30.04.2008
0001 ABC-001 12345 RM 1500 30.04.2008
0001 ABC-002 23456 PM 1000 30.04.2008
0002 XYZ-001 12345 RM 500 30.04.2008
0002 XYZ-001 12345 RM 500 30.04.2008
0002 ABC-001 23456 PM 500 30.04.2008
0002 ABC-001 23456 RM 500 30.04.2008At the end of Plant, Material, Batch & Storage Location system should sum up the quantity and insert into the Internal table. Format is as below
*PLANT MATERIAL BATCH STORAGE QUANTITY MONTH_END_DATE*
0001 ABC-001 12345 RM 2000 30.04.2008
0001 ABC-002 23456 PM 1000 30.04.2008
0002 XYZ-001 12345 RM 1000 30.04.2008
0002 XYZ-001 23456 PM 500 30.04.2008
0002 XYZ-001 23456 RM 500 30.04.2008I will then insert the above value into a Ztable.
I have tried doing it but i just do not get the summary values.
Please guide on how to achieve it.
I hope i have given you an idea of how i want the data,
Any queries please let me know.
Thank You,
Jitesh
2008 Dec 03 7:08 AM
Hi,
First of all make sure based on which field's changes you want to sum up. If its is the first one in your internal table as in your example is plant, Then sort internal table based on plant & then use tha following code as:
loop at itab into wa.
wa1 = wa. " To get char values as they are(Not *** as it comes after SUM stmnt)
at new plant.
sum.
wa1-quantity = wa-quantity.
append wa1 to new_itab.
endat.
clear : wa, wa1.
endloop.
if you want it on some other field, then sort internal table based on that field and use "on change of" instead of "at new".
Hope will help you out to solve ur problem.
Regards,
Pankaj
Hi,
First of all make sure based on which field's changes you want to sum up. If its is the first one in your internal table as in your example is plant, Then sort internal table based on plant & then use tha following code as:
loop at itab into wa.
wa1 = wa. " To get char values as they are(Not *** as it comes after SUM stmnt)
at new plant.
sum.
wa1-quantity = wa-quantity.
append wa1 to new_itab.
endat.
clear : wa, wa1.
endloop.
if you want it on some other field, then sort internal table based on that field and use "on change of" instead of "at new".
Hope will help you out to solve ur problem.
Regards,
Pankaj
2008 Dec 03 6:41 AM
Hi,
Just use an aggregate function sum( quantity_field ) and append into internal table. It will work
Thanks
2008 Dec 03 6:42 AM
Hi,
sort the itab based on your requirement and use collect it will add the numeric fields
or
you can use AT NEW or ON CHANGE OF etc
please go through the KEY word documentaion
regards
Ramchander Rao.K
2008 Dec 03 7:12 AM
I HAVE USED AS YOU SUGGESTED.
i am first giving the data what is there in the Internal Table IT_FINAL.
then i am giving the output after the code suggested has been written.
finally i am giving the output as and how i want it.
plant material batch storagelocation quantity
1 100050 NEWBATCH02 RM01 10,000.000-
1 100050 NEWBATCH01 RM01 50.000-
1 100050 NEW10 RM01 50.000-
1 100050 NEWBATCH01 RM01 100.000-
1 100050 NEW561 PM01 10.000-
1 100050 BATCH1 RM01 10.000-
1 100050 NEW561 PM01 1.000-
1 100050 123456 RM01 10.000-
1 100050 NEW561 PM01 10
1 100050 NEW10 RM01 50
1 100050 NEW10 RM01 50
1 100050 NEW561 PM01 10
1 100050 NEWBATCH02 RM01 10,000.00
1 100050 NEWBATCH02 RM01 10,000.00
1 100050 NEWBATCH01 RM01 100,000.00
1 100050 NEWBATCH01 RM01 10,000.00
1 100050 NEWBATCH01 RM01 100
1 100050 NEWBATCH01 PM01 200
1 100050 NEWBATCH01 PM01 41
1 100050 NEWBATCH01 RM01 100
1 100050 BATCH1 RM01 10
1 100050 BATCH1 RM01 10
1 100050 123456 RM01 10
1 100050 123456 RM01 10
120,370.00
PLEASE FIND HEREWITH THE CODE
it_final1[] = it_Final[].
DATA: WA_MANDT TYPE MANDT,
WA_MATNR TYPE MARA-MATNR,
WA_WERKS TYPE MSEG-WERKS,
WA_LGORT TYPE MSEG-LGORT,
WA_CHARG TYPE MSEG-CHARG,
WA_BUDAT TYPE BUDAT,
WA_MEINS TYPE MSEG-MEINS.
loop at it_final1.
MOVE: IT_FINAL1-MATNR TO WA_MATNR,
IT_FINAL1-CHARG TO WA_CHARG,
IT_FINAL1-LGORT TO WA_LGORT.
on change of it_final1-MATNR.
sum.
I_STOCK-MATNR = WA_MATNR.
I_STOCK-CHARG = WA_CHARG.
I_STOCK-LGORT = WA_LGORT.
I_STOCK-lbkum = IT_FINAL1-DR_STOCK - IT_FINAL1-CR_STOCK.
APPEND I_STOCK.
ENDon.
endloop.
Output after the code.
plant material batch storagelocation quantity
1 100050 NEWBATCH02 RM01 120,370.00
1 100050 NEWBATCH01 RM01 120,370.00
1 100050 NEW10 RM01 120,370.00
1 100050 NEWBATCH01 RM01 120,370.00
1 100050 NEW561 PM01 120,370.00
1 100050 BATCH1 RM01 120,370.00
1 100050 NEW561 PM01 120,370.00
1 100050 123456 RM01 120,370.00
1 100050 NEW561 PM01 120,370.00
1 100050 NEW10 RM01 120,370.00
1 100050 NEW561 PM01 120,370.00
1 100050 NEWBATCH02 RM01 120,370.00
1 100050 NEWBATCH01 RM01 120,370.00
1 100050 NEWBATCH01 PM01 120,370.00
1 100050 NEWBATCH01 RM01 120,370.00
1 100050 BATCH1 RM01 120,370.00
1 100050 123456 RM01 120,370.00Below is the actual output summary i want
plant material batch storagelocation quantity
1 100050 123456 RM01 10
1 100050 BATCH1 RM01 10
1 100050 NEW10 RM01 50
1 100050 NEW561 PM01 9
1 100050 NEWBATCH01 PM01 241
1 100050 NEWBATCH01 RM01 110,050.00
1 100050 NEWBATCH02 RM01 10,000.00
120,370.00This is how i want. Please advise where i am wrong.
Thank You,
Jitesh
2008 Dec 03 7:08 AM
Hi,
First of all make sure based on which field's changes you want to sum up. If its is the first one in your internal table as in your example is plant, Then sort internal table based on plant & then use tha following code as:
loop at itab into wa.
wa1 = wa. " To get char values as they are(Not *** as it comes after SUM stmnt)
at new plant.
sum.
wa1-quantity = wa-quantity.
append wa1 to new_itab.
endat.
clear : wa, wa1.
endloop.
if you want it on some other field, then sort internal table based on that field and use "on change of" instead of "at new".
Hope will help you out to solve ur problem.
Regards,
Pankaj
2008 Dec 03 7:17 AM
i want the sum to be based on Plant,Material,StorageLocation & Batch. What should i do?
Pl suggesst.
Regards,
Jitesh
2008 Dec 03 7:29 AM
Ok then Sort your internal table by plant, material, batch and storage location(all the fields on which u want it).
after that try the code as i have given in above reply
except "at new plant" use "at new storage".
use the rest code same as in my previous reply.
& i didnt understand wat u r doing by the below stsmnt in ur code:
I_STOCK-lbkum = IT_FINAL1-DR_STOCK - IT_FINAL1-CR_STOCK.
if this is ur quantity field then u ll get the total qty after sum into the work area(wa) u r using.
plz try this one if it works 7 let me know for more details if some problem.
regards,
Pankaj
2008 Dec 03 7:38 AM
it_final1] = it_Final[.
DATA: WA_MANDT TYPE MANDT,
WA_MATNR TYPE MARA-MATNR,
WA_WERKS TYPE MSEG-WERKS,
WA_LGORT TYPE MSEG-LGORT,
WA_CHARG TYPE MSEG-CHARG,
WA_BUDAT TYPE BUDAT,
WA_MEINS TYPE MSEG-MEINS.
sort it_final1 by werks matnr charg lgort.
loop at it_final1.
i_stock = it_final1.
at new lgort.
sum.
l_stock-menge = it_final1-menge. " This is the sume of the Quantity u r looking for
I_STOCK-lbkum = IT_FINAL1-DR_STOCK - IT_FINAL1-CR_STOCK.
APPEND I_STOCK.
ENDat.
endloop.
i think this ll be the code in ur case with the field names of ur table as u defined while defining interanal table & work area.
if still any problem plz let me know, & wat is the problem or o/p u r getting.
Regards,
Pankaj
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |