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: 

How-to define CDS View/Entity to generate a BO with Header and Item

Attila
Active Participant
0 Kudos

Dear Members,

I've a really simple scenario (on NW7.5 sp3). I've two self-defined DDIC tables: document header and item. I want to define CDS on top of them, and let the framework to generate the BO from it with the header and item node. I could manage to generate the root node from the  header table, but the child item node was not generated. Do you have a CDS snippet with @ObjectModel annotations to realize this ? What are the requirements to do this ?

Thank you very much

Attila

1 ACCEPTED SOLUTION

ivo_vollrath
Active Participant
0 Kudos

Hi Attila,

you need the following annotations in the header of your CDS view which represents your ROOT node:

@ObjectModel.modelCategory: #BUSINESS_OBJECT

@ObjectModel.compositionRoot: true

@ObjectModel.transactionalProcessingEnabled: true

@ObjectModel.writeActivePersistence: '<DDIC name of DB table>'

You will probably want to add:

@ObjectModel.createEnabled: true

@ObjectModel.updateEnabled: true

@ObjectModel.deleteEnabled: true

For sub nodes, you should not specify the first three annotations (i.e. modelCategory, compositionRoot, and transactionalProcessingEnabled).

In order to include a sub node in your BO, you need CDS associations from ROOT to the ITEM and vice versa. For a sub sub node, you also need an association to ROOT. All these associations have to be annotated with @ObjectModel.association.type. The annotation must be directly before the name of the association within the field list of the view (not at the declaration of the association).

For example, the association from ROOT to ITEM would be annotated as:

@ObjectModel.association.type:  [ #TO_COMPOSITION_CHILD ]

Other possible values are: #TO_COMPOSITION_PARENT, #TO_COMPOSITION_ROOT

Kind Regards,

Ivo

2 REPLIES 2

ivo_vollrath
Active Participant
0 Kudos

Hi Attila,

you need the following annotations in the header of your CDS view which represents your ROOT node:

@ObjectModel.modelCategory: #BUSINESS_OBJECT

@ObjectModel.compositionRoot: true

@ObjectModel.transactionalProcessingEnabled: true

@ObjectModel.writeActivePersistence: '<DDIC name of DB table>'

You will probably want to add:

@ObjectModel.createEnabled: true

@ObjectModel.updateEnabled: true

@ObjectModel.deleteEnabled: true

For sub nodes, you should not specify the first three annotations (i.e. modelCategory, compositionRoot, and transactionalProcessingEnabled).

In order to include a sub node in your BO, you need CDS associations from ROOT to the ITEM and vice versa. For a sub sub node, you also need an association to ROOT. All these associations have to be annotated with @ObjectModel.association.type. The annotation must be directly before the name of the association within the field list of the view (not at the declaration of the association).

For example, the association from ROOT to ITEM would be annotated as:

@ObjectModel.association.type:  [ #TO_COMPOSITION_CHILD ]

Other possible values are: #TO_COMPOSITION_PARENT, #TO_COMPOSITION_ROOT

Kind Regards,

Ivo

Attila
Active Participant
0 Kudos

Hello,

I could successfully generate the BO based on your explanation.

Thank you very much Ivo.

Best regards

Attila