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

about modify...

Former Member
0 Likes
834

Hi friends,

I have to internal tables itab1 ,itab2...

itab1 contains one record..

vbeln vkorg dele

342 MFS

itab2 contains two records

vbeln dele

342 1001

342 1002

Now i want modify itab1 ,the output would be

vbeln vkorg dele

342 MFS 1001

342 MFS 1002

please provide the logic for this.. <removed_by_moderator>

Thanks,

kishore.

Edited by: Julius Bussche on Jul 11, 2008 12:46 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
807

Defile another internal table itab3 type table of itab1. 

Loop at itab2 into wa2. 
    read table itab1 into wa1
                           with key vbeln = wa2-vbeln.
   If sy-subrc eq 0.
      wa3-vbeln = wa2-vbeln.
      wa3-vkorg = wa1-vkorg.
      wa3-dele = wa2-dele.
      append wa2 to itab3.
      clear: wa2, wa1, wa3.
   endif. 

endloop. 

clear: itab1[].
itab1[] =  itab3[]. 

8 REPLIES 8
Read only

Former Member
0 Likes
807

hiiii

use following code for itab 1

IF sy-subrc EQ 0.
    LOOP AT itab1 INTO wa_output.
      READ TABLE itab2 INTO wa_mard WITH KEY matnr = wa_output-matnr.
      wa_output-lgort = wa_mard-lgort.
      MODIFY itab1 FROM wa_output.
      CLEAR wa_output.
    ENDLOOP.                           " LOOP AT i_output
  ENDIF.                               " IF sy-subrc EQ 0

regards

twinkal

Read only

Former Member
0 Likes
808

Defile another internal table itab3 type table of itab1. 

Loop at itab2 into wa2. 
    read table itab1 into wa1
                           with key vbeln = wa2-vbeln.
   If sy-subrc eq 0.
      wa3-vbeln = wa2-vbeln.
      wa3-vkorg = wa1-vkorg.
      wa3-dele = wa2-dele.
      append wa2 to itab3.
      clear: wa2, wa1, wa3.
   endif. 

endloop. 

clear: itab1[].
itab1[] =  itab3[]. 

Read only

Former Member
0 Likes
807

Hi,

Twinkals answer is incorrect, you will still only get one entry per VBELN and you want as many as you have in ITAB2.

Abishek's solution will work, but it is an internal join. So, if you also want entries to remain in ITAB1 when there is no related item in ITAB2 it will not work. If you don't want this and need help in building it the way you need, just let us know.

Greetings,

Gert.

Read only

Former Member
0 Likes
807

Hi kishore,

you cam try it like the code given below:

loop at itab1 into wa.

  read table itab1 into wa1 with key vbeln eq wa-vbeln.
  if sy-subrc = 0.
    wa-dele = wa1-dele.
    modify itab1 from wa index sy-tabix.
 endif.
endloop.

With luck,

Pritam

Read only

Former Member
0 Likes
807

Hi,

Try this,


Loop at itab1 into wa1.
   Read table itab2 into wa2 with key vbeln = wa1-vbeln.
   if sy-subrc = 0.
    wa1-dele = wa2-dele.
    modify  itab1 from wa1 transporting dele.
  Endif.
Endloop.

Hope you will get your answer.

Regards,

Sujit

Read only

0 Likes
807

If for a single vbeln in itab1 table, there are multiple row in itab2 and you want all the instances of itab2 in itab1 ( as shown in the example), you are never going to achieve it by looping itab1 and reading ita2. Only, loop inside loop can do. Please check your logic before posting reply.

Read only

Former Member
0 Likes
807

hi check this..

types: begin of ttab ,

vbeln(10) type c ,

vkorg(4) type c,

dele(4) type c,

end of ttab ,

begin of ttab1 ,

vbeln(10) type c,

dele(4) type c,

end of ttab1 .

data: itab type table of ttab with header line,

itab1 type table of ttab1 with header line,

wa like line of itab ,

wa1 like line of itab1 .

itab-vbeln = '0000000001'.

itab-vkorg = '1000'.

itab-dele = 'DEL'.

append itab .

itab-vbeln = '0000000002'.

itab-vkorg = '1000'.

itab-dele = 'DEL'.

append itab .

itab-vbeln = '0000000003'.

itab-vkorg = '1000'.

itab-dele = 'DEL'.

append itab .

itab1-vbeln = '0000000001'.

itab1-dele = 'TST'.

append itab1 .

itab1-vbeln = '0000000002'.

itab1-dele = 'GRE'.

append itab1 .

sort itab by vbeln.

sort itab1 by vbeln.

loop at itab into wa.

data:v_index type sy-index .

v_index = sy-tabix.

read table itab1 into wa1 with key vbeln = wa+0(10).

wa14(4) = wa110(4).

modify itab index v_index from wa .

endloop.

loop at itab.

write:/ itab-vbeln,itab-vkorg,itab-dele .

endloop.

Read only

Former Member
0 Likes
807

You can use field-symbols like that:

FIELD-SYMBOLS: <fs_itab1> LIKE itab1.

LOOP AT itab1 ASSINGNING <fs_itab1>.
  CLEAR itab2.
  READ TABLE itab2 WITH KEY vbeln = <fs_itab1>-vbeln.
  IF sy-subrc EQ 0.
    <fs_itab1>-dele = itab2-dele.
  ENDIF.
ENDLOOP.

You don´t use MODIFY and is faster.