‎2010 Apr 02 12:08 AM
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.
‎2010 Apr 02 2:41 AM
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....
‎2010 Apr 02 12:49 AM
‎2010 Apr 02 1:27 AM
Hi,
Use Modify statement with internal table varaint.
capture index
idx - sy-tabix.
MODIFY TABLEa INDEX idx FROM RECORDa
TRANSPORTING lw_status.
Regards,
Diwakar
‎2010 Apr 02 1:38 AM
can I write the code as below?
LOOP AT TABLEa INTO RECORDa.
RECORDa-xxx = yyy.
MODIFY TABLEa
....
ENDLOOP.
‎2010 Apr 02 2:16 AM
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
‎2010 Apr 02 2:37 AM
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
‎2010 Apr 02 2:41 AM
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....
‎2010 Apr 02 5:49 AM
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
‎2010 Apr 02 7:13 AM
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