Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

"SELECT" problem

Former Member
0 Likes
808

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
774

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

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

6 REPLIES 6
Read only

Former Member
0 Likes
774

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

Read only

Former Member
0 Likes
774

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

Read only

Former Member
0 Likes
774

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.

Read only

Former Member
0 Likes
774

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

Read only

Former Member
0 Likes
775

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

Read only

0 Likes
774

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.