cancel
Showing results for 
Search instead for 
Did you mean: 

No check on foreign key in ADT-defined database table

nicknf
Explorer
0 Kudos
870

Dear community,

I tried out a tutorial to define a foreign key definition) (until step 11). The defined table looks like this:

@EndUserText.label : 'Table of Bank Accounts'
@AbapCatalog.enhancementCategory : #EXTENSIBLE_CHARACTER_NUMERIC
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #NOT_ALLOWED
define table zaccounts {
  key client         : abap.clnt not null;
  key account_number : abap.numc(8) not null;
  @AbapCatalog.foreignKey.keyType : #KEY
  @AbapCatalog.foreignKey.screenCheck : false
  bank_customer_id   : /dmo/customer_id not null
    with foreign key [0..*,1] /dmo/customer
      where customer_id = zaccounts.bank_customer_id;
  bank_name          : z_bank_name;
  city               : /dmo/city;
  @Semantics.amount.currencyCode : 'zaccounts.currency'
  balance            : abap.curr(16,2);
  currency           : /dmo/currency_code;
  account_category   : abap.numc(2);
  lastchangedat      : timestampl;

}

The foreign key-related table /dmo/customer is empty in my system. Thus I should not be possible to insert a new line to zaccounts. However, I can add a line with the following code:

    DATA myzaccounts type zaccounts.
    DELETE FROM zaccounts.
    myzaccounts-account_number = `myaccount`.
    myzaccounts-bank_customer_id = 12345.
    INSERT zaccounts FROM @myzaccounts.

The code runs without an error and I can see the new line in zaccounts. Shouldn't the insert fail with a foreign key constraint violation?Am I missing something?

Thanks for your help!

nicknf
Explorer
0 Kudos
So I conclude two things: (1) The language to create a DDIC database table using ADT does not have a name (2) nor does it support classical foreign key constraints as used in RDBMS for decades?
horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

(1) The language to create a DDIC database table using ADT is named Dictionary DDL.

(2) It supports the definition of foreign key relationships as it was possible in SE11 for decades.

 

 

 

View Entire Topic
horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Let me try to explain some basic facts.

In ABAP we have two levels of metadata definitions:

  • ABAP Dictionary (DDIC)
    The old one. Here you can define global datatypes, classic DDIC database tables and DDIC database views. The tools are transaction SE11 and nowadays ADT. In ADT, a DDIC DDL is used that in the end does the same as transaction SE11. DDIC database tables can have a semantic property called foreign key relationship. The evaluation of that property is done by frameworks such as classic dynpros, classic database locks but not in the ABAP language (ABAP SQL) itself. ABAP SQL knows nothing of foreign keys.
  • ABAP CDS
    The new one. ABAP CDS is still largely based on DDIC. Up to now, you can define some types (but no structures) and CDS entities such as CDS Views, CDS Table Functions, CDS Hierarchies, ... that access DDIC database tables. The relations between CDS entities are modelled by CDS associations that are instantiated as physical joins when accessed in a path expression. It depends on the framework using the CDS entities, if the foreign key relations of the underlying DDIC database tables are considered at all. Up to now there are no CDS table entities available in ABAP CDS. That means, you cannot define an ABAP-managed database table directly with ABAP CDS. Once, this will be available, a concept regarding foreign key relationships between CDS table entities might become available too, probably based on associations then. 

In the tutorial, you were working on a DDIC database table, whose properties are described here:

https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_database_tables.h...

CDS entities are described here:

https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entities.htm

And finally, RAP is a programming model based on CDS described here:

https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_rap.htm

BTP is a SAP product using these technologies. 

ADT is just a tool. It does not make sense to speak about "ADT database tables" or to say "access the ABAP dictionary when developing with ADT". You can edit DDIC objects with ADT and access those in ABAP CDS, ABAP language and with frameworks built with ABAP.

 

nicknf
Explorer
0 Kudos

Sorry for my late reply and thanks for your extensive answer:

So means in a nutshell, when I create a database table in ADT, it is created using DDIC, correct?

If so this would mean when using ADT I do use DDIC but - however, can not make use of the foreign key relationship feature of DDIC. Is this correct?

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

You still mix the things up.

DDIC (short for ABAP Dictionary) is a metadata repository.

There are two tools for editing metadata such as DDIC database tables of the ABAP Dictionary:

  • SE11 in SAP GUI
  • Source code based editors as well as from based editors in ADT.

"when I create a database table in ADT, it is created using DDIC," is not correct.

Correct is: "you can use ADT (as well as SE11) to create a DDIC database table".

In fact, the source code that you see in ADT isn't even stored as such but created temporarily from the metadata in the ABAP Dictionary.

And also " using ADT I do use DDIC but - however, can not make use of the foreign key relationship feature of DDIC" simply makes no sense,

ADT is a tool for creating repository objects, not for using them. You use a DDIC database table in ABAP language, in ABAP CDS, in classic dynpros, etc. It depends on the usage in these frameworks, whether a foreign key relationship is considered, not on ADT.

 

 

 

nicknf
Explorer
0 Kudos
Ok. Thanks for the explanation.So what is the name of the source code to define a table in ADT?
horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

There is no name of the source code to define a DDIC database table in ADT. The source code is created on the fly when you call the editor and deleted after editing.

https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenddic_tools.htm