Application Development 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: 

improve performace

Former Member
0 Kudos

hallow

how can i improve this performace for this select loop.

Regards

LOOP AT zempkostlprice_rec INTO wa_zem.

SELECT SINGLE ktext

FROM cskv

INTO wa_zem-ktext

WHERE resrc IN g_r_resrc.

IF sy-subrc = 0.

MODIFY zempkostlprice_rec FROM wa_zem TRANSPORTING ktext.

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi!

  • put the select single outside of the loop, if the g_r_resrc is not changing within

  • your loop

DATA: gt_cskv LIKE STANDARD TABLE OF cskv,

wa_cskv LIKE LINE OF gt_cskv.

SELECT SINGLE ktext

FROM cskv

INTO TABLE gt_cskv

WHERE resrc IN g_r_resrc AND

spras = sy-langu. "to avoid duplicated entries

LOOP AT zempkostlprice_rec INTO wa_zem.

READ TABLE gt_cskv TO wa_cskv

WITH KEY resrc = wa_zem-resrc.

IF sy-subrc = 0.

MOVE wa_cskv-ktext TO wa_zem-ktext.

MODIFY zempkostlprice_rec FROM wa_zem TRANSPORTING ktext.

ENDIF.

ENDLOOP.

It will be good now.

Regards

Tamás

Message was edited by:

Tamás Nyisztor

5 REPLIES 5

Former Member
0 Kudos

Hi!

  • put the select single outside of the loop, if the g_r_resrc is not changing within

  • your loop

DATA: gt_cskv LIKE STANDARD TABLE OF cskv,

wa_cskv LIKE LINE OF gt_cskv.

SELECT SINGLE ktext

FROM cskv

INTO TABLE gt_cskv

WHERE resrc IN g_r_resrc AND

spras = sy-langu. "to avoid duplicated entries

LOOP AT zempkostlprice_rec INTO wa_zem.

READ TABLE gt_cskv TO wa_cskv

WITH KEY resrc = wa_zem-resrc.

IF sy-subrc = 0.

MOVE wa_cskv-ktext TO wa_zem-ktext.

MODIFY zempkostlprice_rec FROM wa_zem TRANSPORTING ktext.

ENDIF.

ENDLOOP.

It will be good now.

Regards

Tamás

Message was edited by:

Tamás Nyisztor

0 Kudos

A small correction to Tamas's Code

SELECT ktext " SINGLE not necessary
FROM cskv
INTO TABLE gt_cskv
WHERE resrc IN g_r_resrc AND 
spras = sy-langu.

Hope Tamas does not mind.

Regards

Gopi

0 Kudos

Yea, just forget the single in the code It has to be removed of course.

SELECT * "it is the best way I think

Tamá

former_member194613
Active Contributor
0 Kudos

Please in the performance forum you should recommend performance improvements, not how to make it worse!

DATA: gt_cskv LIKE STANDARD TABLE OF cskv,

SELECT SINGLE ktext

FROM cskv

INTO TABLE gt_cskv

WHERE resrc IN g_r_resrc AND

spras = sy-langu. "to avoid duplicated entries

LOOP AT zempkostlprice_rec INTO wa_zem.

READ TABLE gt_cskv TO wa_cskv

WITH KEY resrc = wa_zem-resrc.

This is a typical example for quadratic coding, which is the worst you can do!!!!!

Plus the select single it will not even be functionally correct!

The nested loop works fine if the table gt_cskv is a hashed table or a sorted table with unique key resrc! Or a standard table with binary search.

The single is a bug.

But these things are not the performance, it will be related to the SQL execution plan for the view. Is the view really properly supported by indexes. Did you check the SQL trace?

Siegfried

former_member194613
Active Contributor
0 Kudos

The single is a simple bug!

The nested loop is a big bug, worse than the original.

And the 10 points is a joke.