07-15-2008 4:58 AM
hi all
i want to group by vblnr how to do it ? this is my select statement
SELECT * from reguh into table it_reguh
WHERE ZBUKR eq p_bukrs
AND laufd eq p_laufd
AND laufi eq p_laufi
and RZAWE eq p_zlsch
and xvorl eq space
and vblnr ne space.
IF it_reguh[] IS INITIAL.
MESSAGE i000 WITH 'no data for that selection'.
EXIT.
ENDIF.
IF NOT it_reguh[] IS INITIAL.
select * from regup into table it_regup
for ALL ENTRIES IN it_reguh
where laufd eq it_reguh-laufd
and laufi eq it_reguh-laufi
and zlsch eq it_reguh-rzawe
and xvorl eq it_reguh-xvorl
and vblnr eq it_reguh-vblnr.
endif.
thanks in advance
cheers
uday
07-15-2008 5:04 AM
hi,
Check out the below related link to understand the same
http://help.sap.com/erp2005_ehp_03/helpdata/EN/44/78baf6f7d2424fa78fd67860a18b26/frameset.htm
Regards,
Santosh
07-15-2008 5:17 AM
Hi,
see the bellow ex
Read out how many flights go to and from a city. The SELECT command is implemented only once in a sub-program. The column data, including aggregate function and the data after GROUP BY, is dynamic. Instead of adding the column data to an internal l_columns table, you could just as easily concatenate it in a character-type l_columns field.
PERFORM my_select USING `CITYFROM`.
ULINE.
PERFORM my_select USING `CITYTO`.
FORM my_select USING l_group TYPE string.
DATA: l_columns TYPE TABLE OF string,
l_container TYPE string,
l_count TYPE i.
APPEND l_group TO l_columns.
APPEND `count( * )` TO l_columns.
SELECT (l_columns)
FROM spfli
INTO (l_container, l_count)
GROUP BY (l_group).
WRITE: / l_count, l_container.
ENDSELECT.
ENDFORM.
hope it will help..
07-15-2008 5:23 AM
Hi Uday,
Add the GROUP BY statement before WHERE Statement.
SELECT * from reguh into table it_reguh
GROUP BY vblnr
WHERE ZBUKR eq p_bukrs
...
Hope this helps you.
Regards,
Chandra Sekhar
07-15-2008 5:32 AM
Hi,
You can specify the columns in the GROUP BY clause either statically or dynamically.
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.
Try this,
SELECT * from reguh into table it_reguh
WHERE ZBUKR eq p_bukrs
AND laufd eq p_laufd
AND laufi eq p_laufi
and RZAWE eq p_zlsch
and xvorl eq space
and vblnr ne space
GROUP BY VBLNR.
Regards,
Sujit
07-15-2008 6:17 AM
hi sujit and chandra sekhar
i already tried both of u r suggestions but this messages is cooming 'the addition "group by" only makes sense with a field list'
cheers
uday
07-16-2008 8:09 AM