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: 

Top n record of vallue size by date

Former Member
0 Kudos

Hi ,

I would like to show top n records date wise .

Could u please help me ??

Like table woul;d have following entries

Location TS Date Size

UK /BIC/TS1 01.07.2005 10

NW /BIC/TS1 01.07.2005 110

UK /BIC/TS2 02.07.2005 20

NW /BIC/TS2 02.07.2005 20

NW /BIC/TS1 02.07.2005 200

UK /BIC/TS3 03.07.2005 20

NW /BIC/TS3 03.07.2005 30

NW /BIC/TS2 03.07.2005 12

INDIA /BIC/TS3 03.07.2005 130

and Top 2 Records for size by date

Location TS Date Size

NW /BIC/TS1 1072005 110

UK /BIC/TS1 1072005 10

NW /BIC/TS1 2072005 200

NW /BIC/TS2 2072005 20

INDIA /BIC/TS3 3072005 130

NW /BIC/TS3 3072005 30

Every 1 would get point .

Thaks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

look at the help of the sort command and you will quickly realize that this is ur answer.

You can specify what fields you want ur itab to be sorted by and if it is ascending or descending.

eg. sort itab by date descending size ascending .

Hope this helps.

Reg,

PP.

13 REPLIES 13

Former Member
0 Kudos

Hi, to meet your requirement in select statement maybe complex.

You can try to achieve it in a internal table.

First, select out all the entries associated,

store like following:

Date Size Location TS

01.07.2005 10 UK /BIC/TS1

....

Then do like following:

sort XXX by Date ascending Size descending.

Loop at XXX.

At New Date.

flag = 0.

EndAt.

if flag >= 0 and flag < 2.

flag = flag + 1.

  • get the date you want here

endif.

Endloop.

The code is just reflect my thinking, hope it will be helpful.

Message was edited by: zhenglin gu

Former Member
0 Kudos

Hi,

You can use following query to get the top n records from table depending upon date.

select * from VBAK

up to n rows

order by erdat descending.

write : /1 VBAK-VBELN, VBAK-ERDAT.

endselect.

Regards,

Gagan

0 Kudos

it is not really helped me

thanks

cool

Former Member
0 Kudos

Thanks for the reward you gave even my reply is not really helpful.

Have you solved it now?

If so, how do you achieve it? share with us

Thanks

Former Member
0 Kudos

look at the help of the sort command and you will quickly realize that this is ur answer.

You can specify what fields you want ur itab to be sorted by and if it is ascending or descending.

eg. sort itab by date descending size ascending .

Hope this helps.

Reg,

PP.

0 Kudos

Hi all

Thanks for tryin this problem

I hate myself to tell u that , no has understand my problem perfectly .

kindly have a closer look on my requirement ie i/p and o/p .

Hope i will get an answew/

Thanx

Gain_Ponits

0 Kudos

Prafful,

look at standard rep's RM06LB00 or RM06LBEU

Andreas

0 Kudos

If nobody has answered ur question, pls do give ur requirement more clearly. and we will b able to help you.

U say top 2 records, but there r abotu 5-6 records displayed. So clarify.

Top 2 records by size or by date ?

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

sort internal_table by size descending date descending.

loop at internal_table into wa.

write : / wa.

endloop.

Former Member
0 Kudos

hehe, some misunderstanding.

You can see I also do the ascending and descending sort in my solution.

But I thought you only want to get two top entries in every kind of Date.

Looks like that I misunderstanding your requirement.

Sorry.

Regards

0 Kudos

Hi,

If u wanted only top 10, use this...

LOOP AT ITAB FROM 1 TO 10.

write:/ itab.

ENDLOOP.

Reg,

PP

Former Member
0 Kudos

Hi,

U can retrieve top n records by the following ways:

 DATA: lv_count TYPE I.
   SORT itab BY TSdate.
   lv_count = 0.
   LOOP AT itab into w_itab.
   lv_count = lv_count + 1.
   if lv_count <= 10.
     Perform.....
   endif.
   Clear: w_itab.
  ENDLOOP.

Hope this will solve ur probelm.

If ur problem got solved kindly reward points and close the thread.

Former Member
0 Kudos

Hi ,

Try this :

data : count type i.

sort itab by date size descending.

Loop at itab.

count = count + 1.

on change of date.

count = 0.

endon.

if count > n.

continue.

endif.

write : /1 itab-location, itab-ts, itab-date, itab-size.

endloop.