Today’s tip is how to append tables with ABAP. This is simple to do and all it takes is just a simple modification to the INSERTING INTO TABLE syntax.
TYPES: Begin of part_number_tb,
MATNR type MATNR,
END OF part_number_tb.
data: part_numbers type table of part_number_tb,
wa like LINE OF part_numbers.
" First, we will select the initial data into the table.
select matnr from mseg into table part_numbers where matnr ne space.
" Next, we will append the additional records into the table..
select matnr from mseg APPENDING TABLE part_numbers where matnr ne space.
" Now as a good step, clear out any duplicates
sort part_numbers by matnr.
delete adjacent duplicates from part_numbers comparing matnr.
" Now, output the data to the screen
loop at part_numbers into wa.
write: / 'Part number: ', wa-matnr.
And that’s all you do to append records into an existing table when you do a select. Just remember, “APPENDING” is the key word but if you do this step, you should look for duplicates as well.