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

Optmizing the codes..

Former Member
0 Likes
681

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 .

5 REPLIES 5
Read only

dhruv_shah3
Active Contributor
0 Likes
661

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

Read only

Former Member
0 Likes
661

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.

Read only

Former Member
0 Likes
661

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 .

Read only

Former Member
0 Likes
661

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 .

Read only

Former Member
0 Likes
661

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.