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

reg: performace

Former Member
0 Likes
504

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,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
479

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.

4 REPLIES 4
Read only

Former Member
0 Likes
479
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.

Read only

Former Member
0 Likes
480

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.

Read only

Former Member
0 Likes
479

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.

Read only

Former Member
0 Likes
479

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