How can I improve the performace of this <fs> code?

Question: Hallo

This code is taking ages to run:



FIELD-SYMBOLS: <STUFE1>, <STUFE2>.

*REF_TAB contains values of |1,2|
* |2,3|
* |3,4|
* and |4,5|
DATA: BEGIN OF REF_TAB OCCURS 0,
STUFE1(2) TYPE N,
STUFE2(2) TYPE N,
END OF REF_TAB.


LOOP AT REF_TAB.
ASSIGN: REF_TAB-STUFE1 TO <STUFE1>,
REF_TAB-STUFE2 TO <STUFE2>.

LOOP AT TAB1 WHERE HZUOR = <STUFE1>.
SELECT * FROM KNVH
WHERE HITYP = 'A'
AND DATBI GE SY-DATUM
AND VKORG = P_ORG
AND HKUNNR = TAB1-KUNNR
AND HZUOR = <STUFE2>.

MOVE-CORRESPONDING KNVH TO TAB1.
APPEND TAB1.

ENDSELECT.
ENDIF.

ENDLOOP.
ENDLOOP.

Would anyone know how this could be improved?

Thanks!

Answer:
Can we not remove the field symbols completely?

Answer:
*REF_TAB contains values of |1,2|
* |2,3|
* |3,4|
* and |4,5|

DATA: BEGIN OF REF_TAB OCCURS 0,
STUFE1(2) TYPE N,
STUFE2(2) TYPE N,
END OF REF_TAB.

LOOP AT REF_TAB.

LOOP AT TAB1 WHERE HZUOR = REF_TAB-STUFE1.

SELECT <only the fields you require> FROM KNVH
APPENDING CORRESPONDING FIELDS OF TABLE TAB1
WHERE HITYP = 'A'
AND DATBI GE SY-DATUM
AND VKORG = P_ORG
AND HKUNNR = TAB1-KUNNR
AND HZUOR = REF_TAB-STUFE2.

ENDLOOP.
ENDLOOP.


Answer:
before reading the data using select from the table build a intermittent internal table only with stufe1 and stufe2 and then

Use FOR ALL ENTRIES in ur select statement which will not require the field symbols.

Also try to avoid nested loops .


hope this helps.

Answer:
be careful with FOR ALL ENTRIES as you may not bring back all the entries that you want. If there are duplicates, the FOR ALL ENTRIES only brings back one entry. To get around the problem, bring back all the key fields even if you do not need these key fields later on. That way you are sure to bring back all the entries that you want.

regards

mrg
Copyright ?2007 - 2008 www.jt77.com