18 feb 2009

the worst ABAP code ever seen

I found this custom code on SAP ECC system...
Read the same internal table more times with the same selection!

REFRESH i_export.
LOOP AT i_temp INTO wa_temp.
l_ekko-ibebeln = wa_temp-ibebeln.
MOVE wa_temp-ibebeln TO wa_export-ibebeln.
l_ekpo-ibebelp = wa_temp-ibebelp.
MOVE wa_temp-ibebelp TO wa_export-ibebelp.

READ TABLE i_ekko INTO wa_ekko WITH KEY zzfgp_ibebeln = wa_temp-ibebeln.
IF sy-subrc EQ 0.
l_ekko-iblifnr = wa_ekko-zzfgp_iblifnr.
MOVE wa_ekko-zzfgp_iblifnr TO wa_export-iblifnr.
ENDIF.

READ TABLE i_lfa1 INTO wa_lfa1 INDEX 1.
IF sy-subrc EQ 0.
l_lfa1-name1 = wa_lfa1-name1.
MOVE wa_lfa1-name1 TO wa_export-name1.
ENDIF.


READ TABLE i_ekko INTO wa_ekko WITH KEY zzfgp_ibebeln = wa_temp-ibebeln.
IF sy-subrc EQ 0.
l_ekko-ibwaers = wa_ekko-zzfgp_ibwaers.
MOVE wa_ekko-zzfgp_ibwaers TO wa_export-ibwaers.
ENDIF.

READ TABLE i_ekpo INTO wa_ekpo WITH KEY zzfgp_ibebeln = wa_temp-ibebeln .
IF sy-subrc EQ 0.
l_ekpo-ibmatkl = wa_ekpo-zzfgp_ibmatkl.
MOVE wa_ekpo-zzfgp_ibmatkl TO wa_export-ibmatkl.
ENDIF.

READ TABLE i_ekpo INTO wa_ekpo WITH KEY zzfgp_ibebeln = wa_temp-ibebeln.
IF sy-subrc EQ 0.
l_ekpo-ibparnop = wa_ekpo-zzfgp_ibparnop.
MOVE wa_ekpo-zzfgp_ibparnop TO wa_export-ibparnop.
ENDIF.

READ TABLE i_ekpo INTO wa_ekpo WITH KEY zzfgp_ibebeln = wa_temp-ibebeln .
IF sy-subrc EQ 0.
l_ekpo-ibparnopt = wa_ekpo-zzfgp_ibparnopt.
MOVE wa_ekpo-zzfgp_ibparnopt TO wa_export-ibparnopt.
ENDIF.

READ TABLE i_ekpo INTO wa_ekpo WITH KEY zzfgp_ibebeln = wa_temp-ibebeln .
IF sy-subrc EQ 0.
IF oda5 EQ ''.
l_ekpo-ibnetpr = wa_ekpo-zzfgp_ibnetpr.
MOVE wa_ekpo-zzfgp_ibnetpr TO wa_export-ibnetpr.
* Il prezzo recepito è inizialmente uguale al prezzo base.
IF NOT l_check = 'X'.
l_ekpo-ibnetpr2 = l_ekpo-ibnetpr.
ENDIF.
MOVE wa_ekpo-zzfgp_ibnetpr TO wa_export-ibnetpr2.
ELSE.
l_ekpo-ibnetpr = v_netpr_oda5_tot.
IF NOT l_check = 'X'.
l_ekpo-ibnetpr2 = l_ekpo-ibnetpr.
ENDIF.
ENDIF.
ENDIF.

READ TABLE i_ekpo INTO wa_ekpo WITH KEY zzfgp_ibebeln = wa_temp-ibebeln.
IF sy-subrc EQ 0.
l_ekpo-ibpeinh = wa_ekpo-zzfgp_ibpeinh.
MOVE wa_ekpo-zzfgp_ibpeinh TO wa_export-ibpeinh.
ENDIF.

READ TABLE i_ekpo INTO wa_ekpo WITH KEY zzfgp_ibebeln = wa_temp-ibebeln.
IF sy-subrc EQ 0.
l_ekpo-ibmeins = wa_ekpo-zzfgp_ibmeins.
MOVE wa_ekpo-zzfgp_ibmeins TO wa_export-ibmeins.
ENDIF.
APPEND wa_export TO i_export.
CLEAR wa_ekpo.
CLEAR wa_ekko.
CLEAR wa_temp.
ENDLOOP.

1 commento:

Unknown ha detto...

You was lucky
I've seen something like:
step = 0.
do 3 times.
step = step + 1.
case step.
when 1.
"few hundreed lines of random code
when 2.
"few hundreed lines of random code
when 3.
"few hundreed lines of random code
endcase.
enddo.