Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Define subitem CDS View with association to head about dependent item table

0 Kudos

Dear Members,

i have created three tables in our system, which basically have the following structure:

The head table is linked to the item table via the join condition "HEAD.UUID = ITEM.HEAD_UUID" and the item table is linked to the subitem table via the join condition "ITEM.UUID = SUBITEM.ITEM_UUID".

Now I would like to create CDS views based on these tables, which should be consumed within a Fiori app using OData. To enable CRUD, a BO should be created in addition.

HEAD TABLE

...

@ObjectModel : {
  compositionRoot: true,
  transactionalProcessingEnabled: true,

  createEnabled: true,
  updateEnabled: true,
  deleteEnabled: true,

  semanticKey: ['product_id'],
  representativeKey: 'guid',
  writeActivePersistence: 'ZDM_PRDCT',

  draftEnabled: true,
  writeDraftPersistence: 'ZDM_PRDCT_D',
}

@VDM.viewType: #TRANSACTIONAL

@Metadata.allowExtensions: true
@OData.publish: true

// This is the HEAD TABLE
define view ZDM_PRODUCT
  // Basic CDS View for HEAD TABLE
  as select from ZB_DM_PRODUCT as Product
  ...
  association [0..*] to ZDM_P_SAP_COMP as _SapComponent on $projection.guid = _SapComponent.product_guid


{

  key Product.guid,
      Product.product_id,

      @ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
      _SapComponent
      ...
} 
 

ITEM_TABLE

@ObjectModel : {

  createEnabled: true,
  updateEnabled: true,
  deleteEnabled: true,

  semanticKey: ['component_id'],
  representativeKey: 'guid',
  writeActivePersistence: 'ZDM_PSC',
  writeDraftPersistence: 'ZDM_PSC_D'
}

@VDM.viewType: #TRANSACTIONAL
@Metadata.allowExtensions: true

define view ZDM_P_SAP_COMP
  as select from ZB_DM_P_SAP_COMP as Component
// HEAD TABLE
  association [1..1] to ZDM_PRODUCT      as _Product on $projection.product_guid = _Product.guid
// SUBITEM TABLE
  association [0..*] to ZDM_P_SAP_COMP_T as _Text    on $projection.guid = _Text.sap_component_guid

{

  key Component.guid,
      Component.product_guid,
      Component.component_id,

      @ObjectModel.association.type: [#TO_COMPOSITION_PARENT, #TO_COMPOSITION_ROOT]
      _Product,

      @ObjectModel.association.type: #TO_COMPOSITION_CHILD
      _Text
} 
 

SUBITEM TABLE

...

@ObjectModel : {

  createEnabled: true,
  updateEnabled: true,
  deleteEnabled: true,

  semanticKey: ['langu'],
  representativeKey: 'guid',
  writeActivePersistence: 'ZDM_PSC_T',
  writeDraftPersistence: 'ZDM_PSC_TD'

}

@VDM.viewType: #TRANSACTIONAL
@Metadata.allowExtensions: true

define view ZDM_P_SAP_COMP_T

  as select from ZB_DM_P_SAP_COMP_T as ComponentText
// ITEM TABLE
  association [1..1] to ZDM_P_SAP_COMP as _Component on $projection.sap_component_guid = _Component.guid
// HEAD TABLE
  association [1..1] to ZDM_PRODUCT    as _Product   on $projection.product_guid = _Product.guid


{

  key ComponentText.guid,
      _Component.product_guid,
      ComponentText.sap_component_guid,
      ComponentText.langu,
      ComponentText.text,

      @ObjectModel.association.type: [#TO_COMPOSITION_PARENT]
      _Component,

      @ObjectModel.association.type: [#TO_COMPOSITION_ROOT]
      _Product
} 
 

Now I would like to create an association from subitem table to head table to set the association type #TO_COMPOSITION_ROOT. To build the join condition I need the product_guid, which I could get from the dependent item table. If I used the approach as in coding, I can't activate the BO. Then I get the error that product_guid is not a DB field.

Can someone help me here?

Thank you in advance!

1 REPLY 1

maheshpalavalli
Active Contributor
0 Kudos

Hi Niklas Weißenfels,

Please check your other quesiton answer and let me know if it works out/

BR,

Mahesh