06-17-2008 4:46 PM
Hi
I have a program which its execution is 'ok' if there are few record (for example 250), otherwise, system show a message of time out.
In this case, what I should do to get better performance for program?
These are code lines for data selection
SELECT ZLOTE BUKRS ANLN1 INVNR ORD41 ORD42 ORD43 ORD44 FROM zanla1
INTO TABLE ti_zanla1
WHERE INVNR IN p_invnr.
SORT ti_zanla1 BY INVNR.
LOOP AT ti_zanla1 INTO wa_zanla1.
READ TABLE ti_zinvnr WITH KEY BUKRS = wa_zanla1-bukrs
INVNR = wa_zanla1-invnr
ASSIGNING <zinvnr>.
IF SY-SUBRC = 0.
READ TABLE it_invnr_control WITH KEY ZLOTE = <zinvnr>-ZLOTE ASSIGNING <zcontrol_serial>.
IF sy-subrc = 0.
it_output-ZFECHAEC = <zcontrol_serial>-ZFECHAEC.
it_output-ZHORAEC = <zcontrol_serial>-ZHORAEC.
ENDIF.
it_output-EBELN = <zinvnr>-EBELN.
it_output-BISMT = <zinvnr>-BISMT.
READ TABLE ti_zcontrol_anla1 WITH KEY ZLOTE = wa_zanla1-ZLOTE ASSIGNING <zcontrol_anla1>.
IF sy-subrc = 0.
it_output-FECHAREC = <zcontrol_anla1>-ZFECHAEC.
ENDIF.
it_output-ZLOTE = wa_zanla1-ZLOTE.
* it_output-BUKRS = wa_zanla1-BUKRS.
it_output-ANLN1 = wa_zanla1-ANLN1.
it_output-INVNR = wa_zanla1-INVNR.
IF wa_zanla1-INVNR = ZINVNR.
it_output-TOTIN01 = 0.
ELSE.
it_output-TOTIN01 = 1.
ENDIF.
it_output-ORD41 = wa_zanla1-ORD41.
READ TABLE ti_t087t WITH KEY ordnr = '1' ord4x = ti_salida-ord41.
it_output-T_ORD41 = ti_t087t-ordtx.
it_output-ORD42 = wa_zanla1-ORD42.
READ TABLE ti_t087t WITH KEY ordnr = '2' ord4x = ti_salida-ord42.
it_output-T_ORD42 = ti_t087t-ordtx.
it_output-ORD43 = wa_zanla1-ORD43.
READ TABLE ti_t087t WITH KEY ordnr = '3' ord4x = ti_salida-ord43.
it_output-T_ORD43 = ti_t087t-ordtx.
it_output-ORD44 = wa_zanla1-ORD44.
READ TABLE ti_t087t WITH KEY ordnr = '4' ord4x = ti_salida-ord44.
it_output-T_ORD44 = ti_t087t-ordtx.
* it_output-STATUS = wa_zanla1-STATUS.
APPEND it_output.
CLEAR it_output.
ENDIF.
ENDLOOP.
Thanks in advance.
06-17-2008 4:53 PM
Sort the internal tables and then use the BINARY SEARCH option of the READ statement.
Rob
06-17-2008 4:53 PM
Sort the internal tables and then use the BINARY SEARCH option of the READ statement.
Rob
06-17-2008 4:56 PM
06-17-2008 4:59 PM
Every time you do a READ without the BINARY SEARCH option, it's like doing:
LOOP AT itab WHERE ...
EXIT.
ENDLOOP.
Adding the BINARY SEARCH will definitely help.
Rob
06-17-2008 4:59 PM
How large is table zanla1?
Is INVNR the primary or a secondary key of that table?
Thomas
06-17-2008 5:03 PM
Hi Thomas
How large is table zanla1?
397.312 in DEV, 437.905 PRD
Is INVNR the primary or a secondary key of that table?
INVNR is the primary
06-17-2008 5:06 PM
sounds good, so stick with Rob's suggestions.
A small additional gain might be possible by replacing
LOOP AT ti_zanla1 INTO wa_zanla1.
with
LOOP AT ti_zanla1 ASSIGNING <zanla1>.
and dependent statements of course.
Thomas
06-18-2008 10:04 AM
SORT ti_zanla1 BY INVNR.
LOOP AT ti_zanla1 INTO wa_zanla1.
READ TABLE ti_zinvnr WITH KEY BUKRS = wa_zanla1-bukrs
INVNR = wa_zanla1-invnr
ASSIGNING <zinvnr>.
I would recommend you to use Sorted tables for all tables which are used with the READs inside the LOOP.
If this is not possible, then sort the standard table before the LOOP starts and use BINARY SEARCH.
There is no real advantage that the large table ti_zanla1 is sorted, the LOOP processes anyway the complete LOOP.
Maybe there is some other logic, which profits of the sort. The APPEND could be such a logic, if the result-table should also be sorted then it makes sense to have
the sort on the LOOP-table.
Siegfried