Earlier, we discussed examples of before and after event handlers. Now let's look at a use case for on handlers.
An on handler actually fulfills requests, e.g. by reading or writing data from or to databases. In our example, we want to use an on handler to implement a domain-specific custom operation.
Watch the video to see how CAP supports the implementation of domain-specific custom operations.
Note
SAP recommends preferring unbound actions/functions, as these are much more straightforward to implement and invoke.As an example, we want to implement an unbound action called submitOrder for the CatalogService. It is used to place orders (in a very simplified way). We declare this action within the service definition as shown in the following figure.

The submitOrder action has two inbound parameters. The first parameter called book is used to identify the book to be ordered. The parameter is typed using the data type of the ID element from the Books entity defined in the imported domain model.
The second parameter quantity is of type Integer and specifies the number of items to be ordered.
An object with a property called stock is defined as the response type. This property is typed using the data type of the stock element from the Books domain model entity. The value of the property should be the new stock for the book after the order has been executed.
Note
Further examples for defining unbound and bound actions and functions in CDS models can be found in the CAP documentation.Next, let's take a look at how to implement the declared submitOrder action.