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

Group by

Former Member
0 Likes
804

I m using group by clause in my report.

select ebeln ebelp belnr max( bwart ) budat menge matnr werks

into table itab_ekbe1

from ekbe where werks eq p_werks

group by ebeln ebelp bwart matnr .

But is it showing an error, when i m not using all fields in group by which i selected, plz tell me what will b the corresct syntax.

The field "EKBE~WERKS" from the SELECT list is missing in the GROUP BY clause. addition INTO wa or INTO (g1,...,gn) is required. fields of type "" or "MATNR".

definiitely rewards pts

5 REPLIES 5
Read only

Former Member
0 Likes
759

Hi,

When we use aggregate functions we need to include all the remaining fields in the group by clause.

Read only

Former Member
0 Likes
759

Hi

try this:

Select <field1> <field2> <field3> from db_table

Group by <field2> <field3> <field1>

The Fields which you are selecting all need to be mentioned in the Group by clause.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Jun 20, 2008 8:46 AM

Read only

Former Member
0 Likes
759

hi check this example...

report .

tables:sbook.

select-options: s_carrid for sbook-carrid,

s_connid for sbook-connid.

TYPES: BEGIN OF sbook_type,

fldate TYPE sbook-fldate,

smoker TYPE sbook-smoker,

smk_cnt TYPE i,

END OF sbook_type.

DATA: sbook_tab TYPE TABLE OF sbook_type,

sbook_type1 TYPE sbook_type .

SELECT fldate smoker COUNT( * ) AS smk_cnt

FROM sbook

INTO CORRESPONDING FIELDS OF TABLE sbook_tab

WHERE connid in s_connid

GROUP BY carrid fldate smoker

HAVING carrid in s_carrid

ORDER BY fldate smoker .

loop at sbook_tab into sbook_type1.

write:/ sbook_type1-fldate,

sbook_type1-smoker,

sbook_type1-smk_cnt .

endloop.

Read only

0 Likes
759

Hello Venkat,

when i m using max function for bwart with group by. While debugging it is not showing any entries for field bwart.

Plz tell me why it is not giving entries..

if eban_ekbe[] is not initial .

select ebeln ebelp max( bwart ) matnr werks

into corresponding fields of table itab_ekbe1

from ekbe where werks eq p_werks

and matnr = eban_ekbe-matnr

group by ebeln ebelp bwart matnr werks.

Read only

0 Likes
759

Why are you including BWART in the GROUP BY when you are applying the aggregate function MAX to it? Have you read the post further up which clearly tells you that you shouldn't do this?