2015 May 12 6:55 AM
I want to improve performance of below code.
Please help..
LOOP AT gt_qmel_qmih INTO gs_qmel_qmih.
lt_jcds[] = lt_jcds_tmp[].
DELETE lt_jcds[] WHERE objnr NE gs_qmel_qmih-objnr.
READ TABLE lt_jcds INTO ls_jcds WITH KEY objnr = gs_qmel_qmih-objnr.
IF sy-subrc EQ 0.
lv_index2 = sy-tabix.
ELSE.
EXIT.
ENDIF.
LOOP AT lt_jcds INTO ls_jcds FROM lv_index2.
IF sy-tabix EQ 1.
gs_tj30t-qmnum = gs_qmel_qmih-qmnum.
gs_tj30t-txt04 = ls_jcds-txt04.
APPEND gs_tj30t TO gt_tj30t.
ENDIF.
CLEAR:gs_tj30t,
ls_jcds,
gs_qmel_qmih.
FREE :gt_jcds.
ENDLOOP.
ENDLOOP.
2015 May 12 7:03 AM
Well, first rewrite this awful code (and don't panic)
lt_jcds[] = lt_jcds_tmp[].
DELETE lt_jcds[] WHERE objnr NE gs_qmel_qmih-objnr.
When there are many notifications loaded, that will kill the performance (n times copy the whole itab and then delete records not required...) better use a sorted/hashed key on objnr and use a simple LOOP WHERE. (which will be optimized to use the key)
Regards,
Raymond
2015 May 12 7:09 AM
Please show sample code.
It will be really helpful...
Thanks,
Darshan.
2015 May 12 7:14 AM
No code required, just define the table for JCDS data as a TYPE SORTED or HASHED, then use a simple LOOP ON lt_jcds WHERE condition on OBJNR. (reference for performance on LOOP/WHERE)
Regards,
Raymond
2015 May 12 7:56 AM
Don't ask for sample code - search and you will find. Read the sap help on tables and indexes. If you want to know about secondary indexes, I wrote a blog about it. You can find that by searching as well.
The more effort you personally put into finding answers, the better you will learn.
2015 May 12 8:11 AM
Hi Darshan panchal,
Once have a look at this code.
types : r_objnr type range of objnr,
lt_jcds[] = lt_jcds_tmp[].
LOOP AT gt_qmel_qmih INTO gs_qmel_qmih.
r_objnr-sign = 'I'.
r_objnr-option = 'EQ'.
r_objnr-low = gs_qmel_qmih-objnr.
clear r_onjnr.
endloop.
delete lt_jcds[] where objnr not in r_objnr.
LOOP AT gt_qmel_qmih INTO gs_qmel_qmih.
READ TABLE lt_jcds INTO ls_jcds WITH KEY objnr = gs_qmel_qmih-objnr.
IF sy-subrc EQ 0.
lv_index2 = sy-tabix.
ELSE.
EXIT.
ENDIF.
LOOP AT lt_jcds INTO ls_jcds FROM lv_index2.
IF sy-tabix EQ 1.
gs_tj30t-qmnum = gs_qmel_qmih-qmnum.
gs_tj30t-txt04 = ls_jcds-txt04.
APPEND gs_tj30t TO gt_tj30t.
ENDIF.
CLEAR:gs_tj30t,
ls_jcds,
gs_qmel_qmih.
FREE :gt_jcds.
ENDLOOP.
ENDLOOP.
And There is no need of read statement for parallel cursor.Pls try this on your own