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 MAX not working properly

Former Member
0 Likes
2,978

Hi,

I am writing the following select statement and it is returning wrong value.

Select max( QMNUM ) from QMEL into (lv_qmnum) groupby qmnum.

Is it because the field qmnum is of type char. I also tried without groupby.

Thanks,

Vinod.

4 REPLIES 4
Read only

Nawanandana
Active Contributor
0 Likes
2,020

Hi,

you should used Select group by otherwise it will be wrong anyway.

If you used aggregate function like(SUM,MAX....) with the group by you have to put rest of the field with group by close . I mean rest of the all field with group by.

"DEPT", SUM("SALARY") from"KABIL_PRACTICE"."DEMO_EMP"Groupby"DEPT";

"here with group by you have to put only 'DEPT' not SALARY. because SALARY goes with aggregate function.

https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/0579a6540e89468998e0ecfaff6...

Regards,

Nawa.

Read only

SimoneMilesi
Active Contributor
2,020

Read and analyze your code.

You are selecting the max value QMNUM inside a group formed by QMNUM, so, basically, you are doing a select single.. since QMNUM is the split criteria.

Read only

Sandra_Rossi
Active Contributor
2,020

I don't have any error with the code you mention, and it does what any SQL developer would expect. A character field is not an issue for MAX:

DATA lv_qmnum TYPE qmel-qmnum.
SELECT MAX( qmnum ) FROM qmel INTO (lv_qmnum).
Read only

DoanManhQuynh
Active Contributor
0 Likes
2,020

how wrong it return?