Application Development 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: 

SELECT SUM not working

Former Member
0 Kudos
1,083

Hello,

I've got the bellow code that works ok and gets 159 rows from the database:


  SELECT a~werks a~fecha_dist b~matnr b~bdmng b~meins
    FROM zmtraz1 AS a INNER JOIN resb AS b
      ON a~resnr_01 = b~rsnum
    INTO TABLE gt_cargas
    WHERE a~fecha_dist IN gt_fechas_cargas.

But I want to use SUM with the field bdmng but it doesn't return me any result, only sy-subrc = 4 because nothing has been selected, what I'm doing wrong?

The code:


  SELECT a~werks a~fecha_dist b~matnr SUM( b~bdmng ) b~meins
    FROM zmtraz1 AS a INNER JOIN resb AS b
      ON a~resnr_01 = b~rsnum
    INTO TABLE gt_cargas
    WHERE a~fecha_dist IN gt_fechas_cargas
    GROUP BY a~werks a~fecha_dist b~matnr b~meins.

2 REPLIES 2

Former Member
0 Kudos
199

Ups sorry, the code was OK my error was not in the statement.

Former Member
0 Kudos
199

After GROUP BY, the same column identifiers must be specified as after SELECT. The specification can either be specified statically as a list col1 col2 ... or dynamically as a brackted data object column_syntax that - at execution of the statement - contains the syntax of the staticspecification or is set to initial value. For column_syntax, the same applies as for the dynamic column specification after SELECT.

move the sum ( ) field to last i.e after meins.

and even change it in the internal table also.