Hi!
You are correct...
Only change would be,
"delete itab1 where matnr is initial." should come after "sort itab1 by matnr."
So your code is:
itab1[] = itab2[].
sort itab1 by matnr.
delete itab1 where matnr is initial.
delete adjacent duplicates from itab1 comparing matnr.
delete itab2 where matnr is not initial.
append lines of itab2 to itab1.
Regards,
KS