2006 Dec 05 2:37 PM
Hi,
I have one internal table populated with a list of material codes and another with all the material numbers.
ITAB1: MCODE KSCHL KNUMH MATNR
ITAB2: MCODE MATNR
The matnr field in itab1 is blank initially. It needs to be populated with all the material numbers from itab2. How can I achieve this?
Thanks,
ap
2006 Dec 05 2:41 PM
Try this code
Loop at itab1 into wa_itab1
readt table itab2 into wa_itab2 with key mcode = wa_itab1-mcode.
IF sy-subrc eq 0.
wa_itab1-matnr = wa_itab2-matnr
ENDIF.
modify itab1 from wa_itab1.
endloop
Hi,
I have one internal table populated with a list of material codes and another with all the material numbers.
ITAB1: MCODE KSCHL KNUMH MATNR
ITAB2: MCODE MATNR
The matnr field in itab1 is blank initially. It needs to be populated with all the material numbers from itab2. How can I achieve this?
Thanks,
ap
2006 Dec 05 2:41 PM
Try this code
Loop at itab1 into wa_itab1
readt table itab2 into wa_itab2 with key mcode = wa_itab1-mcode.
IF sy-subrc eq 0.
wa_itab1-matnr = wa_itab2-matnr
ENDIF.
modify itab1 from wa_itab1.
endloop
2006 Dec 05 2:47 PM
In both tables, is there a one to one relationship between MCODE and MATNR?
Rob
2006 Dec 05 2:48 PM
Hi,
Please try this.
DATA: WA_ITAB2 LIKE ITAB2.
LOOP AT ITAB1.
READ TABLE ITAB2 INTO WA_ITAB2
WITH KEY MCODE = ITAB1-MCODE.
IF SY-SUBRC = 0.
MODIFY ITAB1 FROM WA_ITAB2 TRANSPORTING MATNR.
ENDIF.
ENDLOOP.Regards,
Ferry Lianto
2006 Dec 05 2:49 PM
data: v_tabix like sy-tabix.
sort itab1 by mcode.
sort itab2 by mcode.
loop at itab1.
v_tabix = sy-tabix.
read table itab2 with key mcode = itab1-mcode.
if sy-subrc = 0.
itab1-matnr = itab2-matnr.
modify table itab1 index v_tabix.
endif.
clear: itab1, itab2, v_tabix.
endloop.
2006 Dec 05 2:49 PM
HI,
Loop at Itab2.
read table itab1 with key MCODE = itab2-MCODE.
if sy-subrc = 0.
itab2-Matnr = itab1-matnr.
modify Itab2 index sy-tabix.
endif.
endloop.Regards
Sudheer
2006 Dec 05 3:30 PM
Hi,
The above solutions are for a one to one relationship. The material code will have many material numbers under it. e.g. If the material in itab1 is ABC, it will have 10 material numbers in itab2. So the one record in itab1 should become 10. I hope this is clear.
a.p.
2006 Dec 05 3:40 PM
The best way to get this done is use a inner join statement.
thanks,
2006 Dec 05 3:51 PM
Hi
Lets say that there is only one record in itab1 and for that there is correspondingly 10 records in itab2.
that means that the one record in itab1 should be changed to the first material number in itab2 and there should be nine more records created in itab1 according to the values in itab2.
Hope this is what you mean.
If this is the logic then the following code should work
then lets have a third internal table the same type as itab1
Loop at itab1 into wa_itab1
*readt table itab2 into wa_itab2 with key mcode = wa_itab1-mcode.
*IF sy-subrc eq 0.
loop at itab2 into wa_itab2 where mcode = wa_itab1-mcode.
wa_itab1-matnr = wa_itab2-matnr
append wa_itab1 to itab3.
endloop.
*ENDIF.
*modify itab1 from wa_itab1.
endloop.
itab3 will contain all the values that you require
2006 Dec 05 3:47 PM
try this,
SELECT tab1~matnr
tab2~mcode
tab1~kschl
tab1~knumh
INTO TABLE ittab
FROM tab1
INNER JOIN tab2
ON tab1mcode EQ tab2mcode
WHERE (your condition).
2006 Dec 05 4:12 PM
Thanks Dominic! And congratulations on your 1000 points milestone!
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |