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: 

selecting maximum value of a column

Former Member
0 Kudos

Hi All!

Can anybody give me the inexpensive select statement which gives the maxmimum value of that column.I am having a Z table and the column <b>version</b> in the table will have the following fixed value.

Y-1

Y-2

Y-3

Y-4

Y-5

Now everytime I run the report i have to select the maximum value of the version.Please advise,

Regards

Praneeth

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can use MAX with select to get the required result

SELECT MAX( version ) from Z-table into variable

WHERE condition

FYI,

SELECT - Syntax

... { MAX( [DISTINCT] col )

| MIN( [DISTINCT] col )

| AVG( [DISTINCT] col )

| SUM( [DISTINCT] col )

| COUNT( DISTINCT col )

| COUNT( * )

| count(*) } ... .

Effect

As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):

MAX( [DISTINCT] col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.

MIN( [DISTINCT] col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.

AVG( [DISTINCT] col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.

SUM( [DISTINCT] col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.

COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.

COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.

For more information, press F1 with the cursor over the keyword & look for the help documentation from the ABAP editor.

kind regards,

Thangesh

7 REPLIES 7

Former Member
0 Kudos

Hai,

Use select MAX(field) from table into field.

Regards,

Umasankar

Former Member
0 Kudos

SELECT field1 field2 MAX(version) INTO w_data

FROM ZTABLE

WHERE FIELD1 = VALUE1

AND ....

Hope this helps.

Sudha

Former Member
0 Kudos

Hi praneeth,

1. If u want only one field, then like this.

2. SELECT

MAX( FIELDNAME )

INTO MYVARIABLE

FROM ZTABLE.

regards,

amit m.

Former Member
0 Kudos

See the link==>

rgds,

TM.

Former Member
0 Kudos

Hi Praneeth,

use like this

select max(version field)

into var

from dbtable.

where condition

Former Member
0 Kudos

Hi,

You can use MAX with select to get the required result

SELECT MAX( version ) from Z-table into variable

WHERE condition

FYI,

SELECT - Syntax

... { MAX( [DISTINCT] col )

| MIN( [DISTINCT] col )

| AVG( [DISTINCT] col )

| SUM( [DISTINCT] col )

| COUNT( DISTINCT col )

| COUNT( * )

| count(*) } ... .

Effect

As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):

MAX( [DISTINCT] col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.

MIN( [DISTINCT] col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.

AVG( [DISTINCT] col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.

SUM( [DISTINCT] col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.

COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.

COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.

For more information, press F1 with the cursor over the keyword & look for the help documentation from the ABAP editor.

kind regards,

Thangesh

Former Member
0 Kudos

Hi Praneeth,

Use MAX on field to get the maximum value of the field in the table.

DATA V_VERSION TYPE ZTABLE-VERSION.

SELECT <b>MAX( VERSION )</b>

FROM ZTABLE

INTO V_VERSION.

<b>Note: There will be no space after MAX.

There will be space after begin and end of braces.</b>

Otherwise this results you to syntax error.

Thanks,

Vinay