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

How to code this

Former Member
0 Likes
667

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
647

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

5 REPLIES 5
Read only

matt
Active Contributor
0 Likes
647

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.

Read only

Former Member
0 Likes
648

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

Read only

Former Member
0 Likes
647


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.
Read only

Former Member
0 Likes
647

Plz use query as below.

SELECT MATNR PERIOD FROM <table>

INTO TABLE it_data

UPTO <n> ROWS.

rgds

Rajesh

Read only

Former Member
0 Likes
647

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