Application Development and Automation 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: 
Read only

itab

Former Member
0 Likes
1,414

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,389

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

14 REPLIES 14
Read only

Former Member
0 Likes
1,389

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

Read only

0 Likes
1,389

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

Read only

0 Likes
1,389

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.

Read only

Former Member
0 Likes
1,389

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.

Read only

0 Likes
1,389

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.

Read only

Former Member
0 Likes
1,390

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

Read only

0 Likes
1,389

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.

Read only

0 Likes
1,389

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

Read only

0 Likes
1,389

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.

Read only

ferry_lianto
Active Contributor
0 Likes
1,389

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

Read only

0 Likes
1,389

Ferry,

But we have to SUM up the POQty, right?

Read only

0 Likes
1,389

Ferry,

But we have to SUM up the POQty, right?

Thanks.

Read only

0 Likes
1,389

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

Read only

ferry_lianto
Active Contributor
0 Likes
1,389

Hi Sey,

The collect statement will do sum of ITAB1-POQTY for unique MATNR and LIFNR combination. Have you tried?

Regards,

Ferry Lianto