Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

avoide nested loops in this program

hi how to avoide the nested loops in this coding

LOOP AT itb_ekpo.

READ TABLE itb_marc WITH KEY

matnr = itb_ekpo-matnr

werks = itb_ekpo-werks BINARY SEARCH.

CHECK sy-subrc = 0.

itb_pca-ebeln = itb_ekpo-ebeln.

itb_pca-ebelp = itb_ekpo-ebelp.

itb_pca-lifnr = itb_ekpo-lifnr. "+FAE26446

itb_pca-ekgrp = itb_ekpo-ekgrp. "+FAE26446

itb_pca-dispo = itb_ekpo-dispo. "+FAE26446

itb_pca-matnr = itb_ekpo-matnr.

itb_pca-werks = itb_ekpo-werks.

READ TABLE itb_makt

WITH KEY matnr = itb_ekpo-matnr

spras = text-fra

BINARY SEARCH.

IF sy-subrc = 0.

itb_pca-maktx = itb_makt-maktx.

ELSE.

READ TABLE itb_makt

WITH KEY matnr = itb_ekpo-matnr

spras = text-ang

BINARY SEARCH.

IF sy-subrc = 0.

itb_pca-maktx = itb_makt-maktx.

ENDIF.

ENDIF.

IF NOT itb_ekpo-bpumn IS INITIAL.

itb_pca-menge = itb_ekpo-menge * itb_ekpo-bpumz /

itb_ekpo-bpumn.

ENDIF.

CLEAR w_temoin_ar.

CLEAR w_etens.

LOOP AT itb_ekes

FROM w_index_ekes.

IF itb_ekes-ebeln = itb_ekpo-ebeln

AND itb_ekes-ebelp = itb_ekpo-ebelp.

IF itb_ekes-ebtyp = text-arn.

itb_pca-eindt = itb_ekes-eindt.

w_temoin_ar = 'X'.

ELSE.

IF itb_ekes-dabmg < itb_ekes-menge.

itb_pca-qtran = itb_pca-qtran + itb_ekes-menge -

itb_ekes-dabmg.

ENDIF.

IF itb_ekes-etens > w_etens.

w_etens = itb_ekes-etens.

itb_pca-dtran = itb_ekes-eindt.

ENDIF.

ENDIF.

ELSEIF itb_ekes-ebeln > itb_ekpo-ebeln

OR ( itb_ekes-ebeln = itb_ekpo-ebeln

AND itb_ekes-ebelp > itb_ekpo-ebelp ).

w_index_ekes = sy-tabix.

EXIT.

ENDIF.

ENDLOOP.

LOOP AT itb_eket

FROM w_index_eket.

IF itb_eket-ebeln = itb_ekpo-ebeln

AND itb_eket-ebelp = itb_ekpo-ebelp.

IF w_temoin_ar IS INITIAL.

itb_pca-eindt = itb_eket-eindt.

ENDIF.

itb_pca-slfdt = itb_eket-slfdt.

itb_pca-attdu = itb_pca-attdu + itb_eket-menge -

itb_eket-wemng.

itb_pca-netpr = itb_ekpo-netpr * itb_pca-attdu.

IF itb_ekpo-peinh NE 0.

itb_pca-netpr = itb_pca-netpr / itb_ekpo-peinh.

ENDIF.

itb_pca-wemng = itb_pca-wemng + itb_eket-wemng.

ADD 1 TO itb_eket-eindt.

IF NOT itb_pca-attdu IS INITIAL

AND itb_eket-eindt LT sy-datum.

CLEAR w_retard.

CALL FUNCTION 'Z_00_BC_WORKDAYS_PER_PERIOD'

EXPORTING

date_deb = itb_eket-eindt

date_fin = sy-datum

IMPORTING

jours = w_retard.

itb_pca-rtard = itb_pca-rtard + w_retard .

ENDIF.

ELSEIF itb_eket-ebeln > itb_ekpo-ebeln

OR ( itb_eket-ebeln = itb_ekpo-ebeln

AND itb_eket-ebelp > itb_ekpo-ebelp ).

w_index_eket = sy-tabix.

EXIT.

ENDIF.

ENDLOOP.

LOOP AT itb_mseg

FROM w_index_mseg.

IF itb_mseg-ebeln = itb_ekpo-ebeln

AND itb_mseg-ebelp = itb_ekpo-ebelp.

READ TABLE itb_mkpf

WITH KEY mblnr = itb_mseg-mblnr

mjahr = itb_mseg-mjahr

BINARY SEARCH.

IF sy-subrc = 0.

IF itb_mkpf-bldat > itb_pca-bldat.

itb_pca-bldat = itb_mkpf-bldat.

ENDIF.

ENDIF.

ELSEIF itb_mseg-ebeln > itb_ekpo-ebeln

OR ( itb_mseg-ebeln = itb_ekpo-ebeln

AND itb_mseg-ebelp > itb_ekpo-ebelp ).

w_index_mseg = sy-tabix.

EXIT.

ENDIF.

ENDLOOP.

APPEND itb_pca.

CLEAR itb_pca.

ENDLOOP.

thanks in advance all

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question