‎2004 Oct 04 3:30 PM
Hi,
I am new to ABAP and was looking for some help.
Well we have data coming from a header and a line item table( delivery LIKP and LIPS).
I want to create an internal table one which can hold the data at line item level but sorted on plant so that all the data gets in order by plant and month of posting.
I need another internal table that will aggregate and give me the totals by plant on a month basis so that I can sum of quantities by month and by plant.
Then I need to divide the individual line items in the first internal table by the total quantities of internal table 2.
I dont seem to be making any progress. Can I get some help on the code for the best way to go about it.
Thanks in advance
Amit
‎2004 Oct 04 3:57 PM
I would suggest you you join those 2 tables in a select statement into 1 internal table.
Select a~field1
a~field2
b~field1
b~field2
into table gt_tab
from likp as a
inner join lips as b
on bvbeln = avbeln
where a~key1 = key_selection1
a~key2 = key_selection2
order by awerks amonthposting.
Then, you loop at this internal table (make LT_TAB same as GT_TAB)
LOOP at GT_TAB.
at new monthposting.
refresh LT_TAB.
endat.
append GT_TAB to LT_TAB.
at end of monthposting.
describe lt_tab lines lv_size.
loop at LT_TAB.
line_time_qty = LT_TAB-qty / LV_SIZE.
endloop.
write the summary per plant, monthposting.
endat.
ENDLOOP.
‎2004 Oct 04 4:43 PM
Hi Nablan,
Thanks for the prompt reply. I am lost a bit in the code that you sent.
describe lt_tab lines lv_size.
loop at LT_TAB.
line_time_qty = LT_TAB-qty / LV_SIZE.
endloop.
write the summary per plant, monthposting.
endat.
What does lv_size do. From what I got when we do the above statement we are not getting the total for a particular plant for that month and we need to divide the individual quantities after obtaining the total by month.
For ex:
customer material q1 q2 q3
123 m1 3 2 4
123 m2 4 1 2
456 m1 2 2 4
so i would want
customer material q1 q2 q3 %q1 %q2 %q3
123 m1 3 2 4 3/7 2/3 4/6
123 m2 4 1 2 4/7 1/3 2/6
456 m1 2 2 4 2/2 2/2 4/4
Thanks
Amit
‎2004 Oct 04 5:01 PM
In this case, you can do something like this
LOOP AT GT_TAB.
AT NEW MONTHPOSTING
CLEAR TOTAL
REFRESH LT_TAB
ENDAT.
APPEND GT_TAB TO LT_TAB
TOTAL = TOTAL + GT_TAB-qty
AT END OF MONTHPOSTIN
LOOP AT LT_TAB
PERCENT1 = MONTH1 / TOTAL.
PERCENT2 = MONTH1 / TOTAL.
PERCENT3 = MONTH1 / TOTAL.
WRITE: / CUSTOME, MATERIAL, MONTH1, MONTH2, MONTH3
PERCENT1, PERCENT2 PERCENT3.
ENDLOOP
ENDAT
ENDLOOP
‎2004 Oct 04 7:40 PM
Thanks Nablan,
Will try that out and will inform you of the same. How do I allot the points please so that you get credit for the help.
thanks
Amit
‎2004 Oct 04 7:45 PM
Hi Amit
You can reward points by pressing the yellow star icon at the header of each post.
You can give;
- one 10 points (solved)
- two 6 points (very helpful answer)
- many 2 points (helpful answer)
As soon as you give a 10 points, your question will seem as "solved".
*--Serdar
‎2004 Oct 04 7:57 PM
Nablan,
The code that you posted, will sort the record by plant
Select a~field1
a~field2
b~field1
b~field2
into table gt_tab
from likp as a
inner join lips as b
on bvbeln = avbeln
where a~key1 = key_selection1
a~key2 = key_selection2
order by awerks amonthposting
When we say at monthpostin that will give us just the total quantity for the entire month but not by plant.
LOOP AT GT_TAB.
AT NEW MONTHPOSTING
CLEAR TOTAL
REFRESH LT_TAB
ENDAT.
APPEND GT_TAB TO LT_TAB
TOTAL = TOTAL + GT_TAB-qty
AT END OF MONTHPOSTIN
LOOP AT LT_TAB
PERCENT1 = MONTH1 / TOTAL.
PERCENT2 = MONTH1 / TOTAL.
PERCENT3 = MONTH1 / TOTAL.
WRITE: / CUSTOME, MATERIAL, MONTH1, MONTH2, MONTH3
PERCENT1, PERCENT2 PERCENT3.
ENDLOOP
ENDAT
ENDLOOP
Please clarify that part. In the example that I sent across we divided the indivual line items by the totals for the plant at the end of the month.
customer material q1 q2 q3
123 m1 3 2 4
123 m2 4 1 2
456 m1 2 2 4
so i would want
customer material q1 q2 q3 %q1 %q2 %q3
123 m1 3 2 4 3/7 2/3 4/6
123 m2 4 1 2 4/7 1/3 2/6
456 m1 2 2 4 2/2 2/2 4/4
Here for plant 123 the total q1 was 7 ,total q2 was 3 and total q3 was 6.
But for plant 456 the total q1 was 2,total q2 was 2 and total q3 was 4.
I would be thankful if the above code can be modified so that we can do the above thing.
Thanks in advance
Amit
‎2004 Oct 04 8:14 PM
Try this one then
LOOP at GT_TAB.
AT NEW PLANT.
CLEAR: TOTAL_Q1, TOTAL_Q2, TOTAL_Q3.
REFRESH LT_TAB.
ENDAT.
TOTAL_Q1 = TOTAL_Q1 + GT_TAB-QTY1.
TOTAL_Q2 = TOTAL_Q2 + GT_TAB-QTY2.
TOTAL_Q3 = TOTAL_Q3 + GT_TAB-QTY3.
APPEND GT_TAB to LT_TAB.
AT END OF PLANT.
LOOP AT LT_TAB.
PERCENT1 = ( LT_TAB-QTY1 / TOTAL_Q1 ) * 100.
PERCENT2 = ( LT_TAB-QTY2 / TOTAL_Q2 ) * 100.
PERCENT3 = ( LT_TAB-QTY3 / TOTAL_Q3 ) * 100.
Write: customer, material, LT_TAB-QTY1, LT_TAB-QTY2, LT_TAB-QTY3, PERCENT1, PERCENT2, PERCENT3.
ENDLOOP.
ENDAT.
ENDLOOP.