No error while inserting record in child table with no match in master table in SAP

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, there is still no check at database level.

Foreign key constraint example in SE11

Application Level vs Database Level Validation

When you execute using an ABAP code, this checks consistency at application level and not at database level. Errors you see in SE16 show records rejected at application level, but direct database insertions bypass these checks.

Example ? Manual Validation Implementation

You need to perform validation by checking records from master table with foreign key of child table. Here's how to implement proper validation ?

DATA: lv_master_key TYPE your_master_key_type.

* Check if master record exists
SELECT SINGLE field_name 
  FROM master_table 
  INTO lv_master_key 
  WHERE key_field = child_foreign_key.

* If sy-subrc is not initial, master record doesn't exist
IF sy-subrc <> 0.
  MESSAGE 'Master record not found. Cannot insert child record' TYPE 'E'.
ELSE.
  * Proceed with child table insertion
  INSERT INTO child_table VALUES wa_child.
  IF sy-subrc = 0.
    MESSAGE 'Record inserted successfully' TYPE 'S'.
  ENDIF.
ENDIF.

In case sy-subrc is not initial, the record shouldn't be inserted to the child table and an error message should be displayed to maintain data integrity.

Conclusion

SAP ABAP programs require manual foreign key validation since database-level constraints are not enforced during programmatic insertions. Always validate master table records before inserting into child tables to maintain referential integrity.

Updated on: 2026-03-13T17:40:37+05:30

361 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements