Skip to Content

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

looping...

Hi all,

i wish to loop thr my it_bseg and it_bkpf table...so that it will firstly read its text from PO table and then update the record into the FI table.But my printout result has two duplicate so i reckon that my loop statement is wrong..

SELECT * FROM ekpo INTO TABLE it_ekpo
  WHERE ebeln in p_ebeln AND ebelp in p_ebelp.



  SELECT * FROM bseg INTO TABLE it_bseg
  WHERE belnr in p_belnr AND bukrs in p_bukrs AND gjahr in p_gjahr.


  IF it_bseg[] IS NOT INITIAL.
SELECT TXZ01 FROM EKPO INTO CORRESPONDING FIELDS OF it_bseg
WHERE EBELN = BSEG-EBELN AND
EBELP = BSEG-EBELP.

IF SY-SUBRC EQ 0.
BSEG-SGTXT = EKPO-TXZ01.
ENDIF.
ENDSELECT.

  LOOP AT it_ekpo INTO it_ekpo.
LOOP AT it_bseg INTO it_bseg WHERE
BUKRS in p_bukrs AND
BELNR in p_belnr AND
GJAHR in p_gjahr.
MOVE it_ekpo-txz01 TO it_bseg-sgtxt.
MODIFY it_bseg FROM it_bseg TRANSPORTING sgtxt.
ENDLOOP.
 WRITE:/ it_bseg-belnr, it_bseg-gjahr, it_bseg-sgtxt, it_ekpo-ebeln.
ENDLOOP.
WRITE:/ it_bseg-belnr, it_bseg-gjahr, it_bseg-sgtxt, it_ekpo-ebeln.



  MODIFY bseg FROM TABLE it_bseg.
  COMMIT WORK.

ENDIF.
  IF sy-subrc EQ 0.
    WRITE:/3 'BSEG TABLE UPDATED SUCCESSFULLY WITH TEXT'.
  ENDIF.

Former Member
Former Member replied

Try coding as below -

SELECT * FROM ekpo INTO TABLE it_ekpo

WHERE ebeln in p_ebeln AND ebelp in p_ebelp.

SELECT * FROM bseg INTO TABLE it_bseg

WHERE belnr in p_belnr AND bukrs in p_bukrs AND gjahr in p_gjahr.

LOOP AT it_ekpo INTO it_ekpo.

LOOP AT it_bseg INTO it_bseg

WHERE EBELN = it_ekpo-EBELN

AND EBELP = it_ekpo-EBELP.

MOVE it_ekpo-txz01 TO it_bseg-sgtxt.

MODIFY it_bseg FROM it_bseg TRANSPORTING sgtxt.

WRITE:/ it_bseg-belnr, it_bseg-gjahr, it_bseg-sgtxt, it_ekpo-ebeln, it_ekpo-ebelP.

ENDLOOP.

ENDLOOP.

MODIFY bseg FROM TABLE it_bseg.

COMMIT WORK.

ENDIF.

IF sy-subrc EQ 0.

WRITE:/3 'BSEG TABLE UPDATED SUCCESSFULLY WITH TEXT'.

ENDIF.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question