When analysing a performance issue in an SAP export script (SAP R/3, 4.06b) I found the following code which runs about 10 minutes in the test system. Might be a bit faster in production but I can not test it there.
LOOP AT ZMARD.
LOOP AT ZCOMB.
IF ZCOMB-MATNR = ZMARD-MATNR.
IF ZCOMB-LGORT = ZMARD-LGORT.
IF ZCOMB-IND = ' '.
IF ZCOMB-PLUMI = '+'.
ZMARD-LABST = ZMARD-LABST + ZCOMB-MNG01.
ELSEIF ZCOMB-PLUMI = '-'.
ZMARD-LABST = ZMARD-LABST - ZCOMB-MNG01.
ENDIF. "PLUMI
ENDIF. "IND
ENDIF. "LGORT
ENDIF. "MATNR
ENDLOOP.
IF ZMARD-LABST < 0.
ZMARD-LABST = 0.
ENDIF.
WRITE ZMARD-LABST DECIMALS 0 TO ZMARD-ZLABST.
MODIFY ZMARD.
ENDLOOP.
Do you have any advice on how this loops can be optimized / put together into one single loop?
Hello sure there are some possibilities.
First: You can conditionize the inner loop with "where outer looped struct-field" = "inner loop table field".
Second: You can use hashed tables. But those are more important for read table.