Note that when you perform an insertion using an ABAP program, there is no check on foreign key constraint. Even when you define checks in data dictionary SE11 still there is no check at database level.
When you execute using an ABAP code, this checks consistency at application level and not at database level. Errors you see in SE16 shows record rejected at application level.
You need to perform validation by checking record from master table with foreign key of child table and incase sy-subrc is not initial then record shouldn’t be inserted to the child table and shows an error message.