2007 Jul 07 11:15 AM
Hi everybody,
select s012matnr sum( s012menge ) sum( s012wemgm ) from s012 into corresponding fields of table it1 group by s012matnr.
i am having problem with the query mentioned above.
grouping by matnr is successful but summing of menge and wemge dont take place.
it comes as 0 in these two fields.
can somebody kindly let me know the right way of summing these two fields grouped by the material?
thanks,
max
2007 Jul 07 11:38 AM
Hi max
Try like this
DATA : BEGIN OF IT1 OCCURS 0,
MATNR LIKE S012-MATNR,
MENGE LIKE S012-MENGE,
WEMNG LIKE S012-WEMGM ,
END OF IT1.
SELECT S012MATNR SUM( S012MENGE ) SUM( S012WEMGM ) FROM S012 INTO TABLE IT1 GROUP BY S012MATNR.
LOOP AT IT1.
WRITE : / IT1-MATNR,
IT1-MENGE,
IT1-WEMNG.
ENDLOOP.
if its useful reward points
Thanks
senthil
2007 Jul 07 11:21 AM
it may be because of into corresponding fields of table declaration...
do like this..
data : begin of it1 occurs 0,
matnr like s012-matnr,
menge like s012-menge,
wemng like s012-wemgm ,
end of it1.
select s012matnr sum( s012menge ) sum( s012wemgm ) from s012 into table it1 group by s012matnr.
regards
shiba dutta
Message was edited by:
SHIBA DUTTA
2007 Jul 07 11:25 AM
Hi Max
try like this
data : begin of itab1 occurs 0,
matnr like s012-matnr,
menge like s012-menge,
wemng like s012~wemgm ,
end of itab1.
select s012~matnr sum( s012~menge ) sum( s012~wemgm ) from s012 into table itab1 group by s012~matnr.
Reward all helpfull answers
Regards
Pavan
2007 Jul 07 11:32 AM
Hi,
To use the GROUP BY clause, you must specify all of the relevant columns in the SELECT clause. In the GROUP BY clause, you list the field names of the columns whose contents must be the same. You can only use the field names as they appear in the database table. Alias names from the SELECT clause are not allowed.
All columns of the SELECT clause that are not listed in the GROUP BY clause must be included in aggregate functions. This defines how the contents of these columns is calculated when the lines are summarized.
Refer to help link for more information.
Regards,
Srilatha.
2007 Jul 07 11:35 AM
Thers is no data in s012~wemgm. Actually do you want to add that two fields.I am giving code for just display datas, just try this.
tables : s012.
data : it1 type table of s012,
wa type s012.
select * from s012 into table it1.
loop at it1 into wa.
write : / wa-matnr,
wa-menge,
wa-wemgm.
endloop.
if its useful reward points,
Thanks
senthil
2007 Jul 07 11:38 AM
Hi max
Try like this
DATA : BEGIN OF IT1 OCCURS 0,
MATNR LIKE S012-MATNR,
MENGE LIKE S012-MENGE,
WEMNG LIKE S012-WEMGM ,
END OF IT1.
SELECT S012MATNR SUM( S012MENGE ) SUM( S012WEMGM ) FROM S012 INTO TABLE IT1 GROUP BY S012MATNR.
LOOP AT IT1.
WRITE : / IT1-MATNR,
IT1-MENGE,
IT1-WEMNG.
ENDLOOP.
if its useful reward points
Thanks
senthil
2007 Jul 09 5:10 AM
thanks guys, i found the problem and fixed it. i declared other fields also in the internal table and that turns out to be the reason why the suming doesnt take place properly.