01-29-2008 6:50 AM
Hi Experts,
I have a 2 internal tables. 1st is itab & 2nd is itabf. itabf is initial. In ITAB I have MATNR, WERKS, PQTY. And ITABF has MATNR, PQTY1, PQTY2.
I am moving rows from ITAB to ITABF. If werks in ITAB is PLANT1 then PQTY should go in PQTY1 of ITABF or if werks is PLANT2 then PQTY should go in PQTY2.
If MATNR is same then it will update the same row in ITABF else append a new row in ITABF.
According to my code its appending a row but in second loop when it gets same MATNR but diffrent WERKS, it delete exixting row and append new PQTY in respective column.
***********************************
N = 1.
LOOP AT ITAB.
ON CHANGE OF ITAB-MATNR.
ITABF-MATNR = ITAB-MATNR.
ITABF-WERKS = ITAB-WERKS.
VMATNR = ITAB-MATNR.
APPEND ITABF.
ENDON.
IF VMATNR = ITAB-MATNR.
SY-TABIX = N.
IF ITAB-WERKS = 'PC01'.
ITABF-FPC01 = ITAB-PQTY.
ELSEIF ITAB-WERKS = 'PC02'.
ITABF-FPC02 = ITAB-PQTY.
MODIFY ITABF INDEX SY-TABIX.
CLEAR: ITAB, ITABF.
AT END OF MATNR.
N = N + 1.
ENDAT.
ENDIF.
ENDLOOP.
**************************************
PLz help. URGENT..
KHAN
01-29-2008 6:56 AM
Hi Khan,
dont use ON CHANGE it will give errors. Use AT NEW control break statement.
may be this will be useful.
<b>reward if useful</b>
Regards,
sunil kairam.
01-29-2008 6:56 AM
Hi Khan,
dont use ON CHANGE it will give errors. Use AT NEW control break statement.
may be this will be useful.
<b>reward if useful</b>
Regards,
sunil kairam.
01-29-2008 7:24 AM
Hi,
try this
sort itab by matnr werks.
loop at itab.
move : itab-matnr to itabf-matnr.
if itab-werks = 'PLANT1'.
move itab-pqty to itabf-pqty1.
elseif itab-werks = 'PLANT2'.
move itab-pqty to itabf-pqty2.
endif.
at end of matnr.
collect itabf.
endat.
endloop.
This ll work
Cheers,
Will.
Edited by: Will smith on Jan 29, 2008 8:39 AM
Edited by: Will smith on Jan 29, 2008 9:32 AM
01-29-2008 8:02 AM
Hi
You can also do like this..
LOOP AT ITAB.
READ TABLE ITABF WITH KEY matnr = ITAB-MATNR.
IF Sy-subrc NE 0 .
ITABF-MATNR = ITAB-MATNR.
ITABF-WERKS = ITAB-WERKS.
IF ITAB-WERKS = 'PC01'.
ITABF-FPC01 = ITAB-PQTY.
ELSEIF ITAB-WERKS = 'PC02'.
ITABF-FPC02 = ITAB-PQTY.
APPEND ITABF.
ELSE .
CONTINUE. ( as per your reqmt )
ENDIF .
ENDLOOP.
Hope it helps.
Praveen