‎2008 Aug 19 10:49 AM
Hi Friends:
Please see the data below.Its material no. & period(quarter)I've to fetch the records where period(quarter) is maximum. Like in this case first 8 records. How to write a select query for this.Please suggest.
Thanks
Material................... Period (Quarter)
000000000070000354 200803
000000000070000691 200803
000000000070000679 200803
000000000070000358 200803
000000000070000694 200803
000000000070000361 200803
000000000070000678 200803
000000000070000363 200803
000000000070000688 200802
000000000070000689 200802
000000000070000676 200802
000000000070000409 200802
000000000070000690 200802
000000000070000410 200802
000000000070000675 200802
000000000070000695 200802
000000000070000677 200801
000000000070000365 200801
000000000070000669 200801
000000000070000674 200801
000000000070000368 200801
‎2008 Aug 19 10:55 AM
Hi,
data : lv_period(6) type n.
select single max( Period ) from dbtable into lv_period.
if sy-subrc = 0.
Select matnr period from table into table itab where period = lv_period.
endif.
Thanks,
Durai.V
‎2008 Aug 19 10:52 AM
Before anyone gives you any code, go and read the ABAP help on SELECT. Hint: aggregation.
If you do your research first, and then try a few things, you can then post what you tried, and you'll find that you'll get helpful answers. Even better, because you put some effort in upfront, you'll LEARN far more effectively than if someone just gives you the answer.
‎2008 Aug 19 10:55 AM
Hi,
data : lv_period(6) type n.
select single max( Period ) from dbtable into lv_period.
if sy-subrc = 0.
Select matnr period from table into table itab where period = lv_period.
endif.
Thanks,
Durai.V
‎2008 Aug 19 10:55 AM
data: lv_max_period type i.
data: lt_matnr type table of matnr.
select max(period)
from table
into lv_max_period.
select matnr
from table
into corresponding fields of table lt_matnr
where period = lv_max_period.
‎2008 Aug 19 10:56 AM
Plz use query as below.
SELECT MATNR PERIOD FROM <table>
INTO TABLE it_data
UPTO <n> ROWS.
rgds
Rajesh
‎2008 Aug 19 11:00 AM
Hi,
Try with MAX aggregate function in select statement.
MAX( [DISTINCT] col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.
syntax:
Select MAX( [Distinct] col )
From dbtable
Where condition.
Regards,
Bhaskar