# Using ABAP, changing a value in itab by getting data from database table

SAPABAPSAP APO

You should do this using a Modify statement as in below −

LOOP AT itab.
SELECT SINGLE matnr INTO itab-matnr
FROM zlldet WHERE palet = itab-palet.
MODIFY itab.
ENDLOOP.


Also note that when you have an internal table itab with a header line, it means that you have a table itab and structure itab and usage of this depends on the situation. Few of the commands like MODIFY and LOOP AT uses both at the same time.

DATA itab TYPE TABLE OF [something].
DATA wa TYPE [something].
LOOP AT itab INTO wa. " copies each line into wa
SELECT SINGLE matnr INTO wa-matnr
FROM zlldet WHERE palet = itab-palet.
MODIFY itab FROM wa.  " writes the changed line back to the table
ENDLOOP.


Also, note the below points.

• You can also use field symbol instead of using MODIFY.
• To keep your code performance optimize, avoid using Select statement inside the loop. You should use range tables and use Select statement only before the loop.
Published on 24-Apr-2018 05:42:54