‎2008 Feb 26 4:02 PM
LOOP AT it_iseg
INTO wa_iseg
WHERE iblnr = wa_ikpf-iblnr.
SORT it_marc BY matnr.
LOOP AT it_marc
INTO wa_marc
WHERE matnr = wa_iseg-matnr.
wa_item-zeili = wa_iseg-zeili.
wa_item-matnr = wa_iseg-matnr.
wa_item-charg = wa_iseg-charg.
READ TABLE it_makt
INTO wa_makt
WITH KEY matnr = wa_iseg-matnr.
wa_item-maktx = wa_makt-maktx.
IF wa_marc-sernp <> space.
IF wa_ikpf-xbufi = 'X'.
LOOP AT it_ser07
INTO wa_ser07
WHERE iblnr = wa_iseg-iblnr
AND mjhar = wa_ikpf-gjahr
and oltpi = 1.
READ TABLE it_objk
INTO wa_objk
WITH KEY obknr = wa_ser07-obknr.
IF sy-subrc EQ 0.
READ TABLE it_equi
INTO wa_equi
WITH KEY equnr = wa_objk-equnr.
IF sy-subrc EQ 0.
wa_item-sernr = wa_equi-sernr.
wa_item-invnr = wa_equi-invnr.
wa_item-menge = space.
ENDIF. "readtable it_ser07
ENDIF. "read table it_objk.
IF wa_item IS NOT INITIAL.
APPEND wa_item TO it_item.
CLEAR wa_item.
ENDIF.
ENDLOOP.
ELSEIF wa_ikpf-xbufi EQ space.
LOOP AT it_equi
INTO wa_equi
WHERE matnr = wa_iseg-matnr.
READ TABLE it_eqbs
INTO wa_eqbs
WITH KEY equnr = wa_equi-equnr
b_werk = wa_equi-werk
b_lager = wa_equi-lager.
IF sy-subrc = 0.
wa_item-sernr = wa_equi-sernr.
wa_item-invnr = wa_equi-invnr.
IF wa_item IS NOT INITIAL.
APPEND wa_item TO it_item.
ENDIF.
ENDIF. "read it_eqbs
ENDLOOP. "loop at it_equi table.
ENDIF. "wa_ikpf-xbufi EQ space
ELSE. "if wa_marc-sernp is blank.
IF wa_item IS NOT INITIAL.
APPEND wa_item TO it_item.
CLEAR wa_item.
ENDIF.
CONTINUE.
ENDIF. "serial number is present.
ENDLOOP. "loop at it_marc.
ENDLOOP. "loop at it_iseg.
‎2008 Feb 26 4:17 PM
hi,
First of all, there are many thinks to do here..
"Sort" statament must to be outside the "LOOP".
Take out the all of them and put "While" in insted of.
"WHILE" is faster than "LOOP" statement.
e.g., in this case you have a basic loop, you can set the "FROM index" to help the performance.
LOOP AT it_marc
INTO wa_marc
WHERE matnr = wa_iseg-matnr.
But, the better idea is if you change insides LOOPs for WHILE.
sort it_marc by matnr > Outside the main LOOP.
Main loop
LOOP AT it_iseg
INTO wa_iseg
WHERE iblnr = wa_ikpf-iblnr.
READ TABLE IT_MARC INTO wa_marc WITH KEY MATNR = wa_iseg-matnr BINARY SEACH.
lv_tabix = sy-tabix.
While ( wa_marc-matnr = wa_iseg-matnr AND sy-subrc eq 0).
.
.
.
Your code....
.
.
add 1 to lv_tabix.
READ TABLE IT_MARC INDEX LV_TABIX.
endwhile.
ENDLOOP. "MAIN LOOP
Read index is faster than read binary search or Loop.
Regards,
Alexandre