2006 Aug 23 7:15 PM
hi,
I want to send summarized data from one table (ztable) to another table. Could you please
help me in writing ABAP code for the following funtionality.
-
TABLE 1
-
-
metricId, CalenderMonth, LOCATION, ValueType, V1, V2, V3
-
ABC FEB-2005 A 10 XX XX XX
ABC FEB-2005 A 50 XX XX XX
ABC FEB-2005 A 60 XX XX XX
ABC FEB-2005 B 60 XX XX XX
ABC MAR-2005 A 10 XX XX XX
ABC APR-2005 D 50 XX XX XX
ABC APR-2005 D 60 XX XX XX
-
-
sum AA BB CC
-
V1 - Real value1
v2- Real value2
v3- Real value3
Please note I need summation based on value type,month and metric id.
In above table, location is unique (composite key) to a particular value type (10 or 50 or 60) within a given month and metric id.
I want to send summarized data into another table based on value type, within a given month and metric id.
Final summation value = Summation of (value1 + value2 +
value3)
= AA + BB + CC
-
TABLE 2
-
-
(metric Id) (Calender month) (Value type) (Final Value)
-
ABC FEB-2005 10 XX
ABC FEB-2005 50 XX
ABC FEB-2005 60 XX
I would really appreciate if any one can help me.
Thanks,
Avneet
2006 Aug 23 7:41 PM
report zrep.
data : begin of itab occurs 0,
metricid like ztable-metricid,
calid like ztable-calid,
valtype like ztable-valtype,
location like ztable-location,
v1 like ztable-v1,
v2 like ztable-v2,
v3 like ztable-v3,
end of itab.
data : begin of ltab,
metricid like ztable-metricid,
calid like ztable-calid,
valtype like ztable-valtype,
end of ltab.
start-of-selection.
select * into itab from ztable.
loop at itab.
at new valtype.
clear ltot.
endat.
move corresponding itab into ltab.
ltot = itab-v1 + itab-v2 + itab-v3 + ltot.
at end of valtype.
move-corresponding ltab into ztable1.
ztable1-final = ltot.
insert ztable1.
endat.
endloop.
Regards
Anurag
2006 Aug 23 7:36 PM
Hello Avneet
SAP provides us with the ABAP statement COLLECT statement to summarize data.
If, for example, the fields containing ABC FEB-2005 A 10 constitute a unique key within the itab then the COLLECT statement will summarize all values for this unique key.
If, however, the key is unique as described above, but you want to summarize the values for 10 50 60 together then you have to replace 10 50 60 with an alternative unique key (e.g. 'XX').
How do you collect?. The only thing you need is a second table in which you collect your data.
data:
gt_ztable_collect TYPE TABLE OF ... (like ztable)
LOOP at ztable INTO gs_line.
COLLECT gs_line INTO gt_ztable_collect.
ENDLOOP.
Note that the collect fields must be on the end of the structure and the key fields at the beginning of the structure.
Please read the SAP documentation for the COLLECT statement carefully.
Regards
Uwe
2006 Aug 23 7:41 PM
report zrep.
data : begin of itab occurs 0,
metricid like ztable-metricid,
calid like ztable-calid,
valtype like ztable-valtype,
location like ztable-location,
v1 like ztable-v1,
v2 like ztable-v2,
v3 like ztable-v3,
end of itab.
data : begin of ltab,
metricid like ztable-metricid,
calid like ztable-calid,
valtype like ztable-valtype,
end of ltab.
start-of-selection.
select * into itab from ztable.
loop at itab.
at new valtype.
clear ltot.
endat.
move corresponding itab into ltab.
ltot = itab-v1 + itab-v2 + itab-v3 + ltot.
at end of valtype.
move-corresponding ltab into ztable1.
ztable1-final = ltot.
insert ztable1.
endat.
endloop.
Regards
Anurag
2006 Aug 23 8:38 PM
Thanks UWE and anurag for your quick reply.
Anurag, the code you sent is summarizing values only based on value type. However, I want to summarize the data based on value type, month and metric id.
Please correct me if am wrong.
I mean, many metric id,many months, three value types are there.
could you pls help me.
Regards,
Avneet
2006 Aug 23 8:42 PM
The AT event is different than On change events...
AT is triggered when any of the fields to the left of the one defined changes ...hence you can see my definition of the internal table, if either of metricid/calendar or valtype changes it would be triggered i.e. for each unique combination of metricidcalidvaltype the total would be inserted in ztable1
ON Change is triggered on change of the particular field only.
--Please note that you need to sort the internal table
Regards
Anurag
Note : Please reward help answers
Message was edited by: Anurag Bankley
Message was edited by: Anurag Bankley
2006 Aug 23 8:46 PM
hi Uwe,
Thanks for your help and suggestion.
Could you be able to explain me in detail and send me code. I would greatly appreciate your help.
Regards,
Avneet
2006 Aug 23 9:10 PM
hi Anurag,Uwe
Thanks for your help and I have awarded points.
Regards,
Avneet