08-04-2005 12:57 PM
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
08-05-2005 11:36 AM
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.
08-04-2005 1:44 PM
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
08-04-2005 2:40 PM
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
08-05-2005 11:25 AM
08-05-2005 11:31 AM
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
08-05-2005 11:36 AM
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.
08-05-2005 1:50 PM
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
08-05-2005 2:04 PM
08-08-2005 5:01 AM
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 ?
08-05-2005 11:38 AM
Hi,
sort internal_table by size descending date descending.
loop at internal_table into wa.
write : / wa.
endloop.
08-05-2005 11:49 AM
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
08-05-2005 12:23 PM
Hi,
If u wanted only top 10, use this...
LOOP AT ITAB FROM 1 TO 10.
write:/ itab.
ENDLOOP.
Reg,
PP
08-05-2005 12:31 PM
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.
08-05-2005 3:40 PM
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.