07-05-2006 12:18 PM
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
07-05-2006 12:39 PM
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
07-05-2006 12:21 PM
Hai,
Use select MAX(field) from table into field.
Regards,
Umasankar
07-05-2006 12:21 PM
SELECT field1 field2 MAX(version) INTO w_data
FROM ZTABLE
WHERE FIELD1 = VALUE1
AND ....
Hope this helps.
Sudha
07-05-2006 12:21 PM
Hi praneeth,
1. If u want only one field, then like this.
2. SELECT
MAX( FIELDNAME )
INTO MYVARIABLE
FROM ZTABLE.
regards,
amit m.
07-05-2006 12:22 PM
07-05-2006 12:23 PM
Hi Praneeth,
use like this
select max(version field)
into var
from dbtable.
where condition
07-05-2006 12:39 PM
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
07-05-2006 12:47 PM
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