‎2008 Jun 24 9:18 AM
Hi all,
i have an issue regarding performance. let us say i have an internal table itab with 5 values. for those values there is a standard table yrank which have a column as rank and for every value of itab there is a rank given in table yrank. here i have to retrieve the values from my itab based on the rank given to the value.(i.e in assending order ).
i have written this sample code but from perfomance it seems to me as bad coding. (i am using select in the loop) can any one give some alternative code.
data: t_mcode like ymeltcode occurs 0 with header line.
data: wa_mcode type ymeltcode.
data: t_meltrank like ymeltrank occurs 0 with header line.
t_mcode-Y_MELTCODE = '720-1'.
append t_mcode.
t_mcode-Y_MELTCODE = '720-2'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-1'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-2'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-5'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-8'.
append t_mcode.
loop at t_mcode into wa_mcode.
select * from ymeltrank into table t_meltrank for all entries in t_mcode where Y_MELTCODE eq t_mcode-y_meltcode.
endloop.
sort t_meltrank by y_rank.
regards,
‎2008 Jun 24 9:24 AM
hi,
do this way ... Loop and endloop statement is not required ...
if not t_mcode[] is initial.
select * from ymeltrank into table t_meltrank for all entries in t_mcode where Y_MELTCODE eq t_mcode-y_meltcode.
endif.
‎2008 Jun 24 9:20 AM
loop at t_mcode into wa_mcode.
select * from ymeltrank into table t_meltrank for all entries in t_mcode where Y_MELTCODE eq t_mcode-y_meltcode.
endloop.inside loop i have necer seen *select * * .
you may use for all entries instead.
Amit.
‎2008 Jun 24 9:24 AM
hi,
do this way ... Loop and endloop statement is not required ...
if not t_mcode[] is initial.
select * from ymeltrank into table t_meltrank for all entries in t_mcode where Y_MELTCODE eq t_mcode-y_meltcode.
endif.
‎2008 Jun 24 9:29 AM
Hi,
You have to write your code is ok except one thing i.e. you have used the Select with all entries statement inside loop.
Below is the correct code.
***************************************************
data: t_mcode like ymeltcode occurs 0 with header line.
data: wa_mcode type ymeltcode.
data: t_meltrank like ymeltrank occurs 0 with header line.
t_mcode-Y_MELTCODE = '720-1'.
append t_mcode.
t_mcode-Y_MELTCODE = '720-2'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-1'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-2'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-5'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-8'.
append t_mcode.
select * from ymeltrank into table t_meltrank for all entries in t_mcode where Y_MELTCODE = t_mcode-y_meltcode.
sort t_meltrank by y_rank.
************************************************************
I hope this will help you.
Help children of U.N World Food Program by rewarding points and encourage others to answer your queries.
‎2008 Jun 24 9:34 AM
Hi,
you need the data based on t_mcode.
there is no need of LOOP, if you are using FAE.
data: t_mcode like ymeltcode occurs 0 with header line.
data: wa_mcode type ymeltcode.
data: t_meltrank like ymeltrank occurs 0 with header line.
t_mcode-Y_MELTCODE = '720-1'.
append t_mcode.
t_mcode-Y_MELTCODE = '720-2'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-1'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-2'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-5'.
append t_mcode.
t_mcode-Y_MELTCODE = '725-8'.
append t_mcode.
select * from ymeltrank
into table t_meltrank
for all entries in t_mcode
where Y_MELTCODE eq t_mcode-y_meltcode.
if sy-subrc = 0.
sort t_meltrank by y_rank.
endif.regards,
madhu