1
votes

I have created two tables ZTR_DEPT (master table) and ZTR_EMP (child table).

deptno(pk)    |  deptname                      
-------------------------             

empno(pk) | name | city | deptno(fk)    
------------------------------------  

When I insert a record into the child table not having matching record in the parent table through ABAP program it simply inserts into database without reporting any error. When I insert the record manually into the child table it is does show an error.

What is the reason of such a discrepancy?

1
...and the question being...? - vwegert

1 Answers

1
votes

I am not totally sure what you mean by manual insertion but I assume it might mean that you do this with a transaction like SE16N or SE16.

When it comes to a programmatic insertion, I have to worry you. There is absolutely no check on foreign key constraints even if you defined check fields in Data Dictionary (SE11). There are no validations on the database level. The errors that you get in (probably) SE16N are because this transaction checks the consistency on the application level, so there is a great chance there is a check in ABAP code that is executed on the application server you are working on. It is the application that rejects the record and not the database in this case.

So in order to do the same you would have to validate it by yourself by selecting the record from the master table with the foreign key of the child table. If the sy-subrc is not initial then you would not proceed to the INSERT statement for the child table and instead return an error message for example.