The INSERT command adds lines to the DB table as long as there are no duplicate keys present, if there are it will throw an ABAP DUMP.
The MODIFY command changes behavior depending on the existence or not of the record when comparing key fields:
- If the key field values are already present in the table, it will change the record that exists in the table
- If the key field values are new, then it will add that new record to the table.
In your code, you only do a straight insert in the first loop, the other two will most likely change the same existing DB record when finding the same key values.