Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  Classic Objects in ABAP Dictionary →  Database Tables →  Dictionary DDL for Defining Database Tables →  DEFINE TABLE →  DEFINE TABLE - field 

DEFINE TABLE - foreign_key

Other versions: 7.31 | 7.40 | 7.54


...  WITH FOREIGN KEY [[n,m]] check_table 
       WHERE check_field1 = dbtab.field1
         [AND check_field2 = dbtab.field2 ...] ...


Assigns a check table to a table field whose data type is defined by a data element in the definition of a database table using the Dictionary DDL statement DEFINE TABLE. Here, check_table is an existing database table in ABAP Dictionary. This statement turns check_table into a check table and turns the current database table into a foreign key table. The current table field is turned into a foreign key field of the foreign key of the current table.

  • The associated fields of the check table must be assigned to the foreign key fields of the foreign key table after WHERE.
  • [n,m] can be used to define the cardinality of the foreign key.
  • The possible values for n are 1 for 1 and [0..1] for C.
  • The possible values for m are 1 for 1, [0..1] for C, [1..*] for N, and [0..*] for CN.

Further properties of the foreign key can be specified using foreign_key_annos.


The addition WITH FOREIGN KEY can be used, with the same meaning, in the definition of a structure using DEFINE STRUCTURE.


Dictionary DDL for specifying the check table SCARR of the foreign key field CARRID of the foreign key table SPFLI.

define table spfli {
  @AbapCatalog.foreignKey.label : 'Check Against Airline'
  @AbapCatalog.foreignKey.keyType : #KEY
  @AbapCatalog.foreignKey.screenCheck : true
  key carrid : s_carr_id not null
    with foreign key [0..*,1] scarr
      where mandt = spfli.mandt
        and carrid = spfli.carrid;