Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

MODYFYING ITAB LINE

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

former_member202957
Contributor
0 Kudos

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.

3 REPLIES 3

former_member202957
Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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