Based on the Sales Order BO view, we are now going to implement the data model for consumption with the help of the consumption view.
The ObjectModel annotations that are used in the consumption view provide transactional related aspects of the business data model.
The annotations (required) for each root entity are:
Annotation and Values |
Effect |
---|---|
@ObjectModel.transactionalProcessingDelegated: true |
Indicates that transactional access to the consumption view is delegated to the transactional runtime of the underlying view (which is annotated with @ObjectModel.transactionalProcessingEnabled: true). |
In addition, the following annotations are required for all editable entities (including the root entity):
Annotation and Values |
Effect |
---|---|
@ObjectModel.createEnabled: true |
Allows the end user to create new business object instances |
@ObjectModel.deleteEnabled: true |
Allows the end user to delete business object instances |
@ObjectModel.updateEnabled: true |
Allows the end user to update existing business object instances |
More on this: ObjectModel Annotations
The DDL-based data definition, as the corresponding development object, is already created. In our case, the DDL data definition and the CDS view are named ZDEMO_C_SALESORDER_TX and ZDEMO_C_SalesOrder_TX respectively.
The business object CDS view that you implemented in the previous step serves as the data source for the consumption view.
The key in the data model in the consumption view corresponds to the primary key of the underlying database table.
In this implementation, the business object view is the data source of the consumption view ZDEMO_C_SalesOrder_TX. The @ObjectModel.transactionalProcessingDelegated: true annotation indicates that transaction requests to the consumption view are delegated to the underlying business object view.
To expose the data model and its metadata to the OData service, the consumption view is annotated with @OData.publish: true.
The SELECT list includes a set of fields that are relevant for consumption in a user interface (UI). The key is specified as a semantic key SalesOrder. This is implemented by the annotation @ObjectModel.semanticKey: 'SalesOrder'.
@AbapCatalog.sqlViewName: 'ZDEMO_C_SO' @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'Sales Order for transactional app' @ObjectModel.semanticKey: 'SalesOrder' @ObjectModel.transactionalProcessingDelegated: true @ObjectModel.createEnabled: true @ObjectModel.deleteEnabled: true @ObjectModel.updateEnabled: true @UI.headerInfo: { typeName: 'Sales Order', typeNamePlural: 'Sales Orders' } @OData.publish: true define view ZDEMO_C_SalesOrder_TX as select from ZDEMO_I_SalesOrder_TX as Document { @UI.lineItem.position: 10 @UI.identification.position: 10 key Document.SalesOrder, @UI.lineItem.position: 20 @UI.identification.position: 20 Document.BusinessPartner, Document.CurrencyCode, @UI.lineItem.position: 50 @UI.identification.position: 50 Document.GrossAmount, @UI.lineItem.position: 60 @UI.identification.position: 60 Document.NetAmount, @UI.lineItem.position: 30 @UI.selectionField.position: 30 @UI.identification.position: 30 Document.BillingStatus, @UI.lineItem.position: 40 @UI.selectionField.position: 40 @UI.identification.position: 40 Document.OverallStatus, /* Exposing value via associations */ @UI.lineItem: { value: '.CompanyName', position: 15 } Document._BusinessPartner, Document._Currency, Document._BillingStatus, Document._OverallStatus }
All generated service artifacts are automatically added to the same ABAP package (and also to the same transport request) as the underlying consumption CDS view.
To make your data model ready for consumption, you only have to activate the resulting OData service in the SAP Gateway hub.
More on this: Expose CDS View as an OData Service
More on this: Test the Activated OData Service