‎2008 Mar 07 10:44 AM
Is there any ways to optimize the following codes?
I mean may be by removing the LOOP, or writing select statements "FOR ALL ENTRIES "may be???Please help.
LOOP AT it_matnr .
SELECT SINGLE lifnr FROM ekko INTO it_matnr-lifnr
WHERE ebeln EQ it_matnr-aufnr.
SELECT SINGLE name1 telf1 FROM lfa1 INTO (it_matnr-name1, it_matnr-telf1)
WHERE lifnr = it_matnr-lifnr .
MODIFY it_matnr .
CLEAR it_matnr .
ENDLOOP .
‎2008 Mar 07 10:48 AM
Hi,
Why there is need of writing the Select Queries in the Loop statement.
First you can have those select statements and then you can have loop statement and then read the table and modify it.
also use the for all entries when comparing two tables.
HTH,
Regards,
Dhruv Shah
‎2008 Mar 07 10:49 AM
Hi,
Check this.
SELECT lifnr FROM ekko INTO it_matnr-lifnr
for all entries in it_matnr
WHERE ebeln EQ it_matnr-aufnr.
SELECT name1 telf1 FROM lfa1 INTO (it_matnr-name1, it_matnr-telf1)
for all entries in it_matnr
WHERE lifnr = it_matnr-lifnr .
Reward if helpful.
Regards.
‎2008 Mar 07 10:54 AM
Hi
sort it_matnr.
Read it_matnr with key matnr binary search .
SELECT lifnr
FROM ekko
INTO table it_matnr-lifnr
WHERE ebeln EQ it_matnr-aufnr.
if not it_matnr-lifnr[] is initial.
SELECT name1 telf1
FROM lfa1
INTO table (it_matnr-name1, it_matnr-telf1)
for all entries in it_matnr-lifnr
WHERE lifnr = it_matnr-lifnr .
MODIFY it_matnr .
CLEAR it_matnr .
‎2008 Mar 07 10:56 AM
Write as :
if not it_matnr[] is initial.
SELECT lifnr ebeln FROM ekko INTO table it_matnr1
for all entries in it_matnr
WHERE ebeln EQ it_matnr-aufnr.
SELECT lifnr name1 telf1 FROM lfa1 INTO table it_matnr2
for all entries in it_matnr
WHERE lifnr = it_matnr-lifnr .
endif.
LOOP AT it_matnr .
read table it_matnr1 with key ebeln EQ it_matnr-aufnr.
if sy-subrc = 0.
it_matnr-lifnr = it_matnr1-lifnr
endif.
read table it_matnr2 with key lifnr = it_matnr-lifnr.
if sy-subrc = 0.
it_matnr-name1 = it_matnr2-name1
it_matnr-telf1 = it_matnr2-telf1.
endif.
MODIFY it_matnr index sy-tabix.
CLEAR : it_matnr ,it_matnr1,it_matnr2 .
ENDLOOP .
‎2008 Mar 10 6:12 AM
Akshya Raj's answer is ok but what i want is to keep the Select single statement alive.
So please help me by giving me answer in that perspective.
How can i optimise the code by selecting the lifnr,name1 & telf1 in Select single manner..
I hope i am quite clear this time.
If there's no possibility then please let me know.