Technical Articles
Create a Table with foreign key relationship in Eclipse.
Motivation:-
In this blog you will learn how to create foreign key relationship between two table’s.
Overview:- Many of time we need to create Header and Item table with foreign key relationship on ABAP Could so might be this scenario will help to create relationship.
Business Scenario:- Creating two table first as Header and second as Item table in Eclipse.
Step:1-
Create a Header Table in Eclipse
Step:2-
Select Database Table
Step:3-
Give Database Table Name
Step:-4
Object assign into your Transport request and click on Finish.
Header Table
Repeat step from 1 to 4 to create Item Table
Item Table
Note:-
with foreign key [1..*,1] zheader_vbak
here [1..*,1] – Presenting 1 Sales Order will have one or more than one items for one sales order.
Now its time to see check table option in Table browser.
Header Table
Item table with Check Table option
Here Item has check table option which is presenting the foreign key relationship with Header ZHEADER_VBAK table.
Header Table Code
@EndUserText.label : 'Sales Order Header'
@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zheader_vbak {
key mandt : abap.clnt not null;
key vbeln : vbeln not null;
erdat : abap.dats;
ernam : abap.char(12);
vkorg : abap.char(4);
vtweg : abap.char(2);
spart : abap.char(2);
@Semantics.amount.currencyCode : 'zheader_vbak.waerk'
netwr : abap.curr(13,2);
waerk : abap.cuky;
faksk : abap.char(2);
last_changed_timestamp : timestampl;
}
Item Table Code
@EndUserText.label : 'Item Table'
@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zitem_vbap {
key mandt : abap.clnt not null;
@AbapCatalog.foreignKey.screenCheck : false
key vbeln : vbeln not null
with foreign key [1..*,1] zheader_vbak
where mandt = zitem_vbap.mandt
and vbeln = zitem_vbap.vbeln;
key posnr : abap.numc(6) not null;
matnr : abap.char(18);
arktx : abap.char(40);
@Semantics.amount.currencyCode : 'zitem_vbap.waerk'
netpr : abap.curr(13,2);
@Semantics.amount.currencyCode : 'zitem_vbap.waerk'
netwr : abap.curr(13,2);
waerk : abap.cuky;
@Semantics.quantity.unitOfMeasure : 'zitem_vbap.kmein'
kpein : abap.quan(13,2);
kmein : abap.unit(3);
last_changed_timestamp : timestampl;
}
Summary:
This blog can help you to understand how to create foreign key relationship between two table using ADT tool.
Hope this blog may help you in your use cases. Please do like follow and comment if you have an any query on this topic.
Thanks
Dinesh Kumar







Hi Dinesh,
this blog is very useful for understanding foreign key relationship in ADT.
Thanks
Really helpful, thanks for this blog, its simple and easy to understand.
This post shows clearly how SE11 remains to be superior to ADT. Just "point and click", not a single line of code to be written and it actually proposes relationships. Next time someone is like " why do you still want to use SAP GUI, LOL". That's why. In times of low-code/no-code it feels bizarre to have text-based table definition.
You're right. I really agree with you if just define a normal transport table, it's easier via SE11 than ADT.
But, when I need to define a CDS View, or something that I can't use SE11, I still have to use text-based define in ADT.
Therefore, maybe it's better to define all DDIC Objects in one place, like text-based define in ADT.
Chad
Yes, for CDS there is no other option, which is fine. I find CDS definition much more intuitive than table.
I honestly just keep switching between two environments (and I know we can actually run SAP GUI transactions from Eclipse but I have SAP GUI anyway, so it's a moot point). Thankfully, we don't need to define new tables frequently. But it's just soooo much easier in SE11. Domain, data element, all dependencies, text tables, maintenance generator, all in one place, with no code. Still patiently waiting for ADT to catch up. 🙂