‎2007 Sep 19 9:45 AM
Hi all,
Please tell me a very simple logic or already existing system function for the following situation.
I am putting ranks for a class. The ranks should be like 1,2,3...
If same total comes, then they hould share the same ranks...
For eg,
Name Total Rank
a 480 1
b 470 2
c 470 2
d 470 2
e 460 5
Hope u understand....
‎2007 Sep 19 10:01 AM
hi arun,
according your total sort your marklist in descending order .
get three temporary variable.
all the temporary variable initializes with zero.
loop <marklist>
if total = temp1.
rank = temp2.
temp3 = temp3 + 1.
else
rank = temp2 + temp3 + 1.
temp2 = rank.
temp1 = total.
endloop.
reward points if helpful....
regards,
velu
‎2007 Sep 19 9:49 AM
hi try like this,
rank = 1.
sort itab by marks.
loop at itab.
at new marks
itab-rank = rank.
append itab.
rank = rank +1.
endat.
endloop.
‎2007 Sep 19 9:50 AM
small correction.
hi try like this,
rank = 1.
sort itab by marks.
loop at itab.
at new marks
itab-rank = rank.
rank = rank +1.
endat.
append itab.
endloop.
‎2007 Sep 19 9:52 AM
hi
loop at itab
at new rank
rank = rank + 1
endat
endloop
it may works
‎2007 Sep 19 10:01 AM
hi arun,
according your total sort your marklist in descending order .
get three temporary variable.
all the temporary variable initializes with zero.
loop <marklist>
if total = temp1.
rank = temp2.
temp3 = temp3 + 1.
else
rank = temp2 + temp3 + 1.
temp2 = rank.
temp1 = total.
endloop.
reward points if helpful....
regards,
velu
‎2007 Sep 19 10:02 AM
Try like this.
Data : counter type i.
data: t_total type total.
SORT ITAB BY TOTAL.
LOOP AT itab.
IF t_total NE total.
counter = counter + 1.
ENDIF.
t_total = itab-total.
Write:/ itab-name, itab-total, counter.
ENDLOOP.
Regards,
Sairam
‎2007 Sep 19 10:08 AM
CHECK THE CODE BELOW, I HOPE IT SERVES YOUR PURPOSE
DATA:
BEGIN OF ITAB OCCURS 0,
NAME(1),
TOTAL TYPE I,
RANK TYPE I,
END OF ITAB.
DATA W_RANK LIKE ITAB-RANK.
ITAB-NAME = 'a'. ITAB-TOTAL = 480. APPEND ITAB.
ITAB-NAME = 'b'. ITAB-TOTAL = 470. APPEND ITAB.
ITAB-NAME = 'c'. ITAB-TOTAL = 470. APPEND ITAB.
ITAB-NAME = 'd'. ITAB-TOTAL = 470. APPEND ITAB.
ITAB-NAME = 'e'. ITAB-TOTAL = 460. APPEND ITAB.
SORT ITAB BY TOTAL DESCENDING.
LOOP AT ITAB.
ON CHANGE OF ITAB-TOTAL.
W_RANK = W_RANK + 1.
ENDON.
ITAB-RANK = W_RANK.
MODIFY ITAB.
WRITE:/ ITAB-NAME,ITAB-TOTAL,ITAB-RANK.
ENDLOOP.
Reward points if useful, get back in case of query...
Cheers!!!
‎2007 Sep 19 10:28 AM
Hi,
Check this code.
data: begin of itab occurs 0,
class type c,
total type i,
end of itab.
data: begin of itab1 occurs 0,
class type c,
total type i,
rank type i,
end of itab1.
data: v_rank type i,
v_total type i,
v_temp_rank type i.
start-of-selection.
itab-class = 'a'.
itab-total = 480.
append itab.
itab-class = 'b'.
itab-total = 470.
append itab.
itab-class = 'c'.
itab-total = 470.
append itab.
itab-class = 'd'.
itab-total = 470.
append itab.
itab-class = 'e'.
itab-total = 460.
append itab.
itab-class = 'f'.
itab-total = 460.
append itab.
itab-class = 'g'.
itab-total = 450.
append itab.
loop at itab.
v_temp_rank = v_temp_rank + 1.
itab1-class = itab-class.
itab1-total = itab-total.
if v_total <> itab-total.
v_rank = v_temp_rank.
v_total = itab-total.
itab1-rank = v_rank.
else.
itab1-rank = v_rank.
endif.
append itab1.
clear itab1.
endloop.
loop at itab1.
write:/5 itab1-class,
15 itab1-total,
35 itab1-rank.
endloop.