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: 

Building BOPF business object from CDS view

glenn_karlsson2
Participant
1,560

Hi,

I am trying to build a BOPF Business Object representing tables KNA1, KNVK and ADR2 in sweet harmony. The aim is to be able to hopefully change names, addresses and contact info for the customer contact persons in a Fiori Elements App.

My CDS's are as below

@AbapCatalog.sqlViewName: 'ZV_I_CUST'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Basic view for cust search for Sales contact app 1'

@ObjectModel.semanticKey: 'kunnr' 
@ObjectModel.modelCategory: #BUSINESS_OBJECT
@ObjectModel.compositionRoot: true
@ObjectModel.transactionalProcessingEnabled: true
@ObjectModel.writeActivePersistence: 'kna1'
@ObjectModel.representativeKey: 'kunnr'   
@ObjectModel.updateEnabled: true

define view ZCDS_CAPP1_I_CUST as select from kna1 as _customers
  association[1..*] to ZCDS_CAPP1_I_CONTPERS 
     as _contpers on $projection.kunnr = _contpers.kunnr
{
    key kunnr,
    name1,
    ort01,    
    
    -- exposing the association to contacts
    @ObjectModel.association.type:  [#TO_COMPOSITION_CHILD  ] 
   _contpers
 }
@AbapCatalog.sqlViewName: 'ZV_I_CONTPERS'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Basic view for contact persons for Sales contact app 1'


@ObjectModel.semanticKey:  [ 'kunnr', 'parnr' ] 
@ObjectModel.writeActivePersistence: 'knvk'
@ObjectModel.representativeKey: [ 'parnr', 'kunnr'] 
@ObjectModel.updateEnabled: true


define view ZCDS_CAPP1_I_CONTPERS as select from knvk as _contpers 
  association [1..1] to ZCDS_CAPP1_I_PHONE 
       as _phone on $projection.prsnr = _phone.persnumber
  association [1..1] to ZCDS_CAPP1_I_CUST 
       as _customers on $projection.kunnr = _customers.kunnr

  {
    key parnr,
    key kunnr,
    namev,
    name1,
    abtnr,
    _contpers.prsnr,
         
//  exposing the association to contacts
    @ObjectModel.association.type:  
        [#TO_COMPOSITION_PARENT, #TO_COMPOSITION_ROOT ] 
    _customers,
    @ObjectModel.association.type:  [#TO_COMPOSITION_CHILD]
    _phone
}
@AbapCatalog.sqlViewName: 'ZV_I_CONTPERS_P'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Basic view for contact person phone'

@ObjectModel.semanticKey: 'PERSNUMBER'
@ObjectModel.writeActivePersistence: 'adr2'
@ObjectModel.representativeKey: 'persnumber'   
@ObjectModel.updateEnabled: true

define view ZCDS_CAPP1_I_PHONE as select from adr2 as _phone 
  association [1..1] to ZCDS_CAPP1_I_CONTPERS 
     as _contpers on $projection.persnumber = _contpers.prsnr
  {
    key persnumber,
    telnr_long,
    
//  exposing the association to contacts
    @ObjectModel.association.type:  [#TO_COMPOSITION_PARENT ] 
    _contpers
    
//    @ObjectModel.association.type: [#TO_COMPOSITION_ROOT]
//    _contpers._customers
}

As far as I understand I must declare a navigation back to the root element even for my last CDS. I have tried a couple of different options, but none seems to work. Any advice?

Also, I get a error message in Eclipse when activating saying

[BO Sync] Cannot find source attribute PARNR in association _PHONE (view ZCDS_CAPP1_I_CONTPERS)

What does that mean, and more importantly, how to I resolve it?

kind regards,

Glenn

5 REPLIES 5

glenn_karlsson2
Participant
0 Kudos
230

Bumping this one. No one have any clue?

Former Member
0 Kudos
230

Hey Glenn,

have you found a solution for this problem?

nbys
Explorer
0 Kudos
230

glenn.karlsson2 timm12 hey guys, by any chance did you find a solution?

230

From my observations, all the child views are supposed have a relation to parent. so the child(2 or 3rd or 4th level..,) should have the root view key field and you need to use the annotation "@ObjectModel.association.type:[#TO_COMPOSITION_ROOT]"

Former Member
0 Kudos
230

Have you found a solution?