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-
Step:2-
Step:3-
Step:-4
Object assign into your Transport request and click on Finish.
Repeat step from 1 to 4 to create 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.
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