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

Optimizing for performance

Former Member
0 Likes
700

Hi,

I have this selection related to a report that outputs condition data. However, it runs for quite a long time, so any input to an optimization is appreciated:

START-OF-SELECTION.

SELECT prodh stufe

FROM t179

INTO CORRESPONDING FIELDS OF TABLE t_t179dat

WHERE stufe = 4.

SELECT knuma bukrs vkbur boart botext

FROM kona

INTO TABLE t_condtab

WHERE knuma IN so_knuma

AND datbi > sy-cdate.

SELECT knuma kschl vkorg kunnr zzprodh4 knumh

FROM kote502

INTO TABLE t_kotetab

FOR ALL ENTRIES IN t_condtab

WHERE knuma = t_condtab-knuma.

SORT t_condtab BY knuma.

SORT t_kotetab BY knuma.

LOOP AT t_condtab INTO wa_condtab.

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma.

wa_condtab-kschl = t_kotetab-kschl.

wa_condtab-vkorg = t_kotetab-vkorg.

wa_condtab-kunnr = t_kotetab-kunnr.

wa_condtab-zzprodh4 = t_kotetab-zzprodh4.

wa_condtab-knumh = t_kotetab-knumh.

SELECT SINGLE name1 INTO wa_condtab-name1

FROM kna1

WHERE kunnr = wa_condtab-kunnr.

MODIFY t_condtab FROM wa_condtab.

LOOP AT t_t179dat INTO wa_t179data. "copy t179 data to workarea

WRITE wa_t179data-prodh+9(3) TO wa_t179data-prodhkey. "3 last chars to prodhkey

MODIFY t_t179dat FROM wa_t179data. "Modify the internal table from workarea

READ TABLE t_t179dat WITH KEY prodhkey = wa_condtab-zzprodh4 "Find key in T179 data

.

SELECT SINGLE vtext INTO wa_condtab-vtext "Find vtext in t179t

FROM t179t

WHERE prodh = t_t179dat-prodh

AND spras = 'EN'.

wa_condtab-stufe = t_t179dat-stufe.

IF wa_condtab-stufe = 4.

MODIFY t_condtab FROM wa_condtab.

ENDIF.

ENDLOOP.

  • Read the partner group

SELECT parvw

INTO wa_condtab-parvw

FROM knvp

WHERE kunnr = wa_condtab-kunnr

AND parvw = 'Z9'.

IF sy-subrc = 0.

MODIFY t_condtab FROM wa_condtab.

ENDIF.

ENDSELECT.

  • Read the price grouping

SELECT SINGLE kunn2

INTO wa_condtab-kunn2

FROM knvp

WHERE kunnr = wa_condtab-kunnr

AND vkorg = wa_condtab-vkorg

AND parvw = wa_condtab-parvw.

  • Read the condition rate

SELECT kbrue FROM konp

INTO wa_condtab-zre1

WHERE knumh = wa_condtab-knumh

AND kopos = 1.

IF wa_condtab-zre1 NE 0.

MODIFY t_condtab FROM wa_condtab.

ENDIF.

ENDSELECT.

MOVE-CORRESPONDING wa_condtab TO wa_outtab.

INSERT wa_outtab INTO TABLE t_outtab.

ENDLOOP.

5 REPLIES 5
Read only

Former Member
0 Likes
630

use

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma binary search.

read the manual for the exact use of binary search. I don't know how big you're tables are but here they were quite big (>30.000 records) it made the report 2x faster with adding binary search to the read statement.

and use performance trace to see what is the most time consuming part of you're report

Message was edited by:

A. de Smidt

Read only

Former Member
0 Likes
630

Hi,

Just few corrections:

<b>If not t_condtab[] is initial.</b>

SELECT knuma kschl vkorg kunnr zzprodh4 knumh

FROM kote502

INTO TABLE t_kotetab

FOR ALL ENTRIES IN t_condtab

WHERE knuma = t_condtab-knuma.

<b>endif.</b>

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma

<b>BINARY SEARCH</b>.

Regards,

Anji

Read only

Former Member
0 Likes
630

hi

good

always use CORRESPONDING FIELDS OF TABLE ITAB.

Before read statement always use the SORT statement.

Thanks

mrutyun^

Read only

Former Member
0 Likes
630

hi peter,

after move-corresponding when u use modify statement u can use sy-tabix.

sy-tabix gives the faster execution.

LOOP AT RTAB.

LOOP AT KTAB WHERE MATNR = RTAB-MATNR.

MOVE-CORRESPONDING RTAB TO KTAB. MODIFY KTAB INDEX SY-TABIX.

ENDLOOP.

ENDLOOP.

regards

vijay dwivedi

Read only

Former Member
0 Likes
630

hi ,

1.) try to avoid ' into correspondig field of ' option in select query

use ' into table tanle_name'.

2.) fro all the select queries containing addition

' FOR ALL ENTRIES IN TABLE_NAME' check the condition

IF TABLE_NAME[] IS NOT INITIAL.

ENDIF

before the select query.

3.) before the read statement sort the table by any key field and

use the addition BINARY SEARCH with READ statement.

4.) For modifying the internal table always use index.

5.) <b>never use select statement inside loop.</b>

for ur case u can use internal table for selecting 'NAME1' from 'KNA1'.

Inside the loop perform the read operation for this internal table.

in the same way avoid the other select statement which u have used in the loop.