‎2006 Nov 17 6:16 PM
Hello Experts,
I need to transfer data from one itab to another.
First Itab:
<b>MATNR LIFNR EBELN EBELP POQTY
-
</b>
10440 10101 13001 00010 400.00
10440 10101 13001 00020 100.00
10440 10101 13002 00050 125.00
10440 12054 19004 00010 560.00
10440 12054 19005 00010 340.00
16005 10101 21055 00010 545.00
16005 12054 21065 00010 976.00
16005 13560 54102 00010 298.00
2nd Itab:
<b>MATNR LIFNR QTY
-
</b>
10440 10101 000.00
10440 12054 000.00
16005 10101 000.00
16005 12054 000.00
16005 13560 000.00
Now I have to add the PO's Qty for each "Material" and "Vendor" combination and transfer that total intto the 2nd Itab's Qty.
Could anybody of you please help me in getting the solution.
Thanks a lot.
‎2006 Nov 17 7:13 PM
I would just:
LOOP AT itab1.
MOVE: itab1-matnr TO itab2-matnr,
itab1-lifnr TO itab2-lifnr,
itab1-poqty TO itab2-qty.
COLLECT itab2.
ENDLOOP.
Rob
‎2006 Nov 17 6:52 PM
Assume itab1 and itab2:
SORT itab1.
LOOP AT itab1.
AT END OF lifnr.
SUM.
MOVE: itab1-matnr TO itab2-matnr,
itab1-lifnr TO itab2-lifnr,
itab1-poqty TO itab2-qty.
APPEND itab2.
ENDAT.
ENDLOOP.
Message was edited by:
Michael Malvey
‎2006 Nov 17 6:55 PM
try this..
SORT itab1.
LOOP AT itab1.
AT END OF matnr.
at end of lifnr.
SUM.
MOVE: itab1-matnr TO itab2-matnr,
itab1-lifnr TO itab2-lifnr,
itab1-poqty TO itab2-qty.
APPEND itab2.
ENDAT.
endat.
ENDLOOP.
~Suresh
‎2006 Nov 17 7:01 PM
You do not need to include both MATNR and LIFNR in separate AT END statements. Since MATNR is superior, the AT END OF lifnr will process if either MATNR or LIFNR changes.
‎2006 Nov 17 7:07 PM
I understand you already have 2 tables with the data specified. In this case you may want to transfer only the quantity and not the material and vendor. To add to the above code
data: l_index type sy-tabix.
SORT itab1.
LOOP AT itab1.
AT END OF lifnr.
SUM.
read table itab2 with key matnr = itab1-matnr
lifnr = itab1-lifnr.
if sy-subrc = 0.
l_index = sy-tabix.
itab2-qty = itab1-poqty.
modify itab2 index l_index transporting qty.
endif.
ENDAT.
ENDLOOP.
Hope this helps.
‎2006 Nov 17 8:17 PM
Srinivasa,
Is that 'SUM' function dependent on datatype?
I mean, I have: ITAB1-POQTY like EKET-WEMNG and
ITAB2-QTY like MDTB-MNG01.
I have changed these 2 fields datatypes to see if that works. But it didn't.
Thanks.
‎2006 Nov 17 7:13 PM
I would just:
LOOP AT itab1.
MOVE: itab1-matnr TO itab2-matnr,
itab1-lifnr TO itab2-lifnr,
itab1-poqty TO itab2-qty.
COLLECT itab2.
ENDLOOP.
Rob
‎2006 Nov 17 7:42 PM
Hi All,
Thanks you very much for the responses. Sorry for getting back to you late.
I was trying all the solutions.
Michael, Suresh.
As Srinivasa said, there are already records in the Itab2. All I have to add the QTY values to that. If I do APPEND, as suggested by my Itab2 is getting all the records of Itab1 duplicately and I'm getting ******** values for the records.
Srinivasa,
Thanks again for your response. I followed ur solution. It seemed to worked.
But I can see that is not <b>summing</b> the POQty values for some reason and it is just passing the <b>value</b> only to the QTY field in Itab2 not the <b>total</b>.
Could you please tell me what could be the reason for this.
Again, thnx all for the kind responses.
‎2006 Nov 17 8:14 PM
The sum statement will sum up all the numeric fields for the given condition.
In your case I only see one reason for displaying only the qty field which is that there should be only one record with the combination of MATNR and LIFNR.
Also always declare a variable and take the sum into that variable (this will avoid the sum overflow). i.e var1 = itab1-poqty will work fine. Please see that the variable var1 declared is sufficient to hold the sum of all the values.
Srini
‎2006 Nov 17 8:25 PM
Excellent Rob,
That worked. I'm sorry for not trying that one earlier. You made my day.
Thanks all.
I really appreciate all your help.
‎2006 Nov 17 7:51 PM
Hi,
Please try like this.
Declare ITAB3 same as ITAB2.
SORT ITAB1.
LOOP AT ITAB1
MOVE: ITAB1-MATNR TO ITAB3-MATNR,
ITAB1-LIFNR TO ITAB3-LIFNR,
ITAB1-POQTY TO ITAB3QTY.
COLLECT ITAB3.
ENDLOOP.
LOOP AT ITAB2.
READ TABLE ITAB3 WITH KEY MATNR = ITAB1-MATNR
LIFNR = ITAB1-LIFNR.
IF SY-SUBRC = 0.
ITAB2-QTY = ITAB3-QTY.
MODIFY ITAB2.
ENDIF.
ENDLOOP.
Regards,
Ferry Lianto
‎2006 Nov 17 8:13 PM
‎2006 Nov 17 8:14 PM
‎2006 Nov 17 8:17 PM
Why don't you try the code I posted? It's quite simple and should do exactly what you want. The COLLECT handles all the summing.
Rob
‎2006 Nov 17 8:17 PM
Hi Sey,
The collect statement will do sum of ITAB1-POQTY for unique MATNR and LIFNR combination. Have you tried?
Regards,
Ferry Lianto