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

modify data in LOOP ...ENDLOOP

Former Member
0 Likes
25,806

Hi experts,

I want to modify data in internal table. I loop the internal table, and modify the record. How to write back to internal table?

<B>LOOP AT TABLEa INTO RECORDa.</B>

select status

from TABLEb

into lw_status

where valueZ=RECORDa-valueZ.

IF sy-subrc = 0.

RECORDa-status = lw_status.

exit.

ENDIF.

endselect.

how to write back RECORDa to TABLEa

....

<B> ENDLOOP.</B>

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
10,829
types: begin of mytab,
             field....
         end of mytab.

data: my_table type table of mytab.  "or of DDIC structure/table
field-symbols: <fs> type mytab.

loop at my_table assigning <fs>.
   <fs>-field = some_value.
endloop.

SAP best practice...update in place, no header, no work area, no copying data from place to place, no modify....index....

8 REPLIES 8
Read only

Former Member
0 Likes
10,829

You can use field symbols.

Read only

0 Likes
10,829

Hi,

Use Modify statement with internal table varaint.

  • capture index

idx - sy-tabix.

MODIFY TABLEa INDEX idx FROM RECORDa

TRANSPORTING lw_status.

Regards,

Diwakar

Read only

0 Likes
10,829

can I write the code as below?

LOOP AT TABLEa INTO RECORDa.
RECORDa-xxx = yyy.
MODIFY TABLEa
....
ENDLOOP.

Read only

0 Likes
10,829

Yes you can write, but the program need to identify which record of the table to change. For that use Index

LOOP AT TABLEa INTO RECORDa.
*l_index = sy-tabix*
RECORDa-xxx = yyy.
MODIFY TABLEa *index l_index*
....
ENDLOOP.

Regards

Kannaiah

Read only

Former Member
0 Likes
10,829

Sorry...unintentional double post...forum doesn't work well with Firefox 3.6.3.

Edited by: Short Dump on Apr 2, 2010 3:41 AM

Read only

Former Member
10,831
types: begin of mytab,
             field....
         end of mytab.

data: my_table type table of mytab.  "or of DDIC structure/table
field-symbols: <fs> type mytab.

loop at my_table assigning <fs>.
   <fs>-field = some_value.
endloop.

SAP best practice...update in place, no header, no work area, no copying data from place to place, no modify....index....

Read only

Former Member
0 Likes
10,829

Try this code


field-symbols : <fs_recorda> type <type definition of <tablea>.
LOOP AT TABLEa assigning <fs_RECORDa>
select status
from TABLEb
into lw_status
where valueZ=RECORDa-valueZ.
IF sy-subrc = 0.
<fs_RECORDa>-status = lw_status.
exit.
ENDIF.
endselect.
ENDLOOP.

Regards

Vinod

Read only

Former Member
0 Likes
10,829

Hi michaeltrans,

You might have got your answer by now but point from my side. In your example you are selecting inside loop, avoid doing it, find some other logic.

You are using select... endselect avoid this also. Use select into table.

Also modify table inside loop is not good, to avoid it use field symbol to modify.

You seems to be new to ABAP programing, so I believe these tips will be helpful for you