Create a Table with foreign key relationship in Eclipse.
2023-11-27 18:25:0 Author: blogs.sap.com(查看原文) 阅读量:7 收藏

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%20a%20Header%20Table%20in%20Eclipse

Create a Header Table in Eclipse

Step:2-

Select%20Database%20Table

Select Database Table

Step:3-

Give%20Database%20Table%20Name

Give Database Table Name

Step:-4

Object assign into your Transport request and click on Finish.

Header%20Table

Header Table

Repeat step from 1 to 4 to create Item Table

Item%20Table

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%20Table

Header Table

Item%20table%20with%20Check%20Table%20option

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


文章来源: https://blogs.sap.com/2023/11/27/create-a-table-with-foreign-key-relationship-in-eclipse./
如有侵权请联系:admin#unsafe.sh