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

Matching data for two internal Table

Former Member
0 Likes
1,115

hi guru's,

i have two internal table that is ITAB and itab1, and both has more than 2000 records, but MATNR is common field in both, so i want to update itab from itab1 according to matnr. can anyone please help me? actually i was using read table but it was not doing correct.

regards Nitin.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,093

Hi,

Try this,

LOOPat itab into wa-itab.
 read itab1 into wa-itab1 with key pernr = wa-itab-pernr.

 Put your code for modification.

clear: wa-itab, wa-itab1.
ENDLOOP.

  • wa--> work area compatible to corresponding internal table.

Reagrds,

Anirban

12 REPLIES 12
Read only

Former Member
0 Likes
1,094

Hi,

Try this,

LOOPat itab into wa-itab.
 read itab1 into wa-itab1 with key pernr = wa-itab-pernr.

 Put your code for modification.

clear: wa-itab, wa-itab1.
ENDLOOP.

  • wa--> work area compatible to corresponding internal table.

Reagrds,

Anirban

Read only

0 Likes
1,093

hi all,

thanx for reply, actually i m using the code below.. is it neccessary to define WA.?

LOOP AT itab.

READ TABLE itab3 WITH KEY matnr = itab-matnr.

IF sy-subrc = 0.

ITAB-BELNR1 = ITAB3-BELNR.

ITAB-EBELN1 = ITAB3-EBELN.

itab-wrbtr1 = itab3-wrbtr.

itab-menge1 = itab3-menge.

itab-unit_price1 = itab3-wrbtr / itab3-menge.

MODIFY itab INDEX sy-tabix TRANSPORTING BELNR1 EBELN1 wrbtr1 menge1 unit_price1.

ELSE.

CONTINUE.

ENDIF.

ENDLOOP.

regards nitin.

Read only

0 Likes
1,093

Its better to use the Workarea.

Regards

Sasi

Read only

0 Likes
1,093

hi,

little changes are there....try this


LOOP AT itab.
READ TABLE itab3 WITH KEY matnr = itab-matnr.
IF sy-subrc = 0.
ITAB-BELNR1 = ITAB3-BELNR.
ITAB-EBELN1 = ITAB3-EBELN.
itab-wrbtr1 = itab3-wrbtr.
itab-menge1 = itab3-menge.
itab-unit_price1 = itab3-wrbtr / itab3-menge.
MODIFY itab  TRANSPORTING BELNR1 EBELN1 wrbtr1 menge1 unit_price1 *belnr ebeln*.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.

Arunima

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,093

Hello,

I think the stmt might be causing the problem.

MODIFY itab INDEX sy-tabix TRANSPORTING BELNR1 EBELN1 wrbtr1 menge1 unit_price1.

Modify your code as follows:


DATA: v_index TYPE sy-tabix.

LOOP AT itab.

v_index = sy-tabix.
READ TABLE itab3 WITH KEY matnr = itab-matnr.
IF sy-subrc = 0.
ITAB-BELNR1 = ITAB3-BELNR.
ITAB-EBELN1 = ITAB3-EBELN.
itab-wrbtr1 = itab3-wrbtr.
itab-menge1 = itab3-menge.
itab-unit_price1 = itab3-wrbtr / itab3-menge.
* MODIFY itab INDEX sy-tabix TRANSPORTING BELNR1 EBELN1 wrbtr1 menge1 unit_price1.
MODIFY itab INDEX v_index TRANSPORTING BELNR1 EBELN1 wrbtr1 menge1 unit_price1.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.

Hope this helps.

BR,

Suhas

Read only

0 Likes
1,093

dear all,

thanx for reply again...but still same problem. actually i m making a report for material price comparison

purchased in current month and same material if purchased in before months. so i need maintain the final ITAB with including same material if purchased in previus months.

ITAB1 : EBELN BLDAT MATNR WRBTR

100023 20080101 abcd 100.00

100025 20080106 xyzr 250.00

100028 20080102 abcd 100.00

100129 20080117 xyzr 150.00

100159 20080126 uvwx 170.00

ITAB2 : EBELN BLDAT1 MATNR WRBTR1

200026 20080201 abcd 105.00

200024 20080206 xyz_r4 250.00

200023 20080201 abcd 100.00

200129 20080217 xyzrw 150.00

200152 20080225 uvwx 190.00

Final record which i need.

ITAB3: EBELN BLDAT MATNR WRBTR WRBTR1

100023 20080101 abcd 100.00 105.00

100023 20080101 abcd 100.00 105.00

100159 20080126 uvwx 170.00 190.00

please suggest me accordingly...

regards nitin.

Read only

0 Likes
1,093

Hi,

try this...


DATA: v_index TYPE sy-tabix.
 
LOOP AT itab.
 

READ TABLE itab3 WITH KEY matnr = itab-matnr.
v_index = sy-tabix.
IF sy-subrc = 0.
ITAB-BELNR1 = ITAB3-BELNR.
ITAB-EBELN1 = ITAB3-EBELN.
itab-wrbtr1 = itab3-wrbtr.
itab-menge1 = itab3-menge.
itab-unit_price1 = itab3-wrbtr / itab3-menge.
* MODIFY itab INDEX sy-tabix TRANSPORTING BELNR1 EBELN1 wrbtr1 menge1 unit_price1.
MODIFY itab INDEX v_index TRANSPORTING BELNR1 EBELN1 wrbtr1 menge1 unit_price1.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.

Arunima

Read only

Former Member
0 Likes
1,093

Hi,

try this code..



loop at itab1 into wa1.
   read table itab into wa with key matnr = wa1-matnr.
   wa1-new_field = wa-old_field.
   modify itab1 from wa1 transporting new_field.
   clear: wa,wa1.
endloop.

Arunima

Read only

Former Member
0 Likes
1,093

Define one more internal table with all fields let us say Itab3.

Loop at itab1

itab3-matnr = itab1-matnr...
and all the fields

read table itab2 with key matnr = itab1-matnr binary search

itab3-otherfields = itab2-other fields

Append Itab3.

endloop

Regards

Sasi

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,093

Hello Saurabh,

Why is it not working with READ stmt? Try this code:


SORT ITAB BY MATNR.

SORT ITAB1 BY MATNR.

LOOP AT ITAB ASSIGNING <FS>.
  READ TABLE ITAB1 INTO WA1
  WITH KEY MATNR = <FS>-MATNR BINARY SEARCH.
  IF SY-SUBRC = 0.
    <FS>-FIELD1 = WA1-FIELD1.
    <FS>-FIELD2 = WA1-FIELD2.
  ENDIF.
ENDLOOP.

If you use field-symbols no need to write the modify stmt as well.

BR,

Suhas

Read only

Former Member
0 Likes
1,093

hi suhas....

i m not comfortable with field string...so please can u tell me with one complete example?

regards nitin.

Read only

former_member585060
Active Contributor
0 Likes
1,093

Hi,

Try this

LOOP AT itab INTO wa_itab.
READ TABLE itab2 INTO wa_itab2 WITH KEY matnr = wa_itab-matnr BINARY SEARCH.
IF sy-subrc = 0.

       put code
wa_itab-field = wa_itab2-field.

ENDIF.

MODIFY it_itab INDEX sy-tabix FROM wa_itab TRANSPORTING field. " field is updated field

ENDLOOP.

Regards

Bala Krishna

Edited by: Bala Krishna on Dec 30, 2008 12:37 PM