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: 

Add business logic to OData update of CDS-based OData service

former_member186608
Active Participant
0 Kudos

I have created a custom CDS view in my local package as follows:

@AbapCatalog.sqlViewName: 'ZMD_C_PUR_REQ3'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Consumption View Purchase Requisition'

@ObjectModel.semanticKey: 'banfn'

@ObjectModel.transactionalProcessingDelegated: true

@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.entityChangeStateId: 'last_change'

@OData.publish: true
define view ZMD_C_PUR_REQ_03 as select from ZMD_I_PURCHASE_REQUISTION {
    key banfn,
    status,
    @Semantics.systemDateTime.lastChangedAt: true
    last_change
}

After activating this CDS view and exposing the generated OData service in transaction /IWFND/MAINT_SERVICE, it does work as expected, even with optimistic locking for handling concurrent updates.

Moreover, my requirement is to add further business logic so that the payload of an update request is validated against a given rule set. That is, if the updated data violates the rules, the update request shall be rejected and the client should be notified (e.g., by an HTTP 500).

How can I accomplish this?

I could not find any generated classes like *DPC_EXT where I can enrich the business logic.

I also did create a validation on my BOPF business object that is registered for update. However, upon updating an entity via OData this validation gets not invoked.

  • SAP Managed Tags:
1 REPLY 1

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

DPC_EXT classes are only generated if you create an OData Service based on your CDS view using SEGW and the "Referenced Datasource Approach".

https://blogs.sap.com/2016/06/01/odata-service-development-with-sap-gateway-using-cds-via-referenced...

Validations are defined in BOPF as described here:

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/201809.000/en-US/309ceacdb8aa4127b1eace...

ceterum censeo RAP esse utendam
  • SAP Managed Tags: